-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configurable sub-second precision with no time key
For input plugins that do not provide a time key as part of the record but do provide a `time` to the router, allow the degree of sub-second time precision to be configurable. Some sources (such as AWS CloudWatch) may provide an accurate time source but do not include a time portion for an otherwise free-form record: there is nothing to parse. In this case the casting of a `DateTime` to a `String` loses any sub-second precision.
- Loading branch information
Sam Pointer
committed
Mar 28, 2017
1 parent
83f978f
commit 64c7d7b
Showing
3 changed files
with
42 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,8 +120,8 @@ def test_template_create | |
to_return(:status => 200, :body => "", :headers => {}) | ||
|
||
driver('test', config) | ||
end | ||
end | ||
|
||
|
||
def test_template_create_invalid_filename | ||
config = %{ | ||
|
@@ -177,14 +177,14 @@ def test_templates_create | |
to_return(:status => 200, :body => "", :headers => {}) | ||
stub_request(:put, "https://john:[email protected]:777/es//_template/logstash3"). | ||
to_return(:status => 200, :body => "", :headers => {}) | ||
|
||
driver('test', config) | ||
|
||
assert_requested( :put, "https://john:[email protected]:777/es//_template/logstash1", times: 1) | ||
assert_requested( :put, "https://john:[email protected]:777/es//_template/logstash2", times: 1) | ||
assert_not_requested(:put, "https://john:[email protected]:777/es//_template/logstash3") #exists | ||
end | ||
|
||
def test_templates_not_used | ||
cwd = File.dirname(__FILE__) | ||
template_file = File.join(cwd, 'test_template.json') | ||
|
@@ -199,7 +199,7 @@ def test_templates_not_used | |
template_name logstash | ||
template_file #{template_file} | ||
templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}" } | ||
} | ||
} | ||
# connection start | ||
stub_request(:head, "https://john:[email protected]:777/es//"). | ||
to_return(:status => 200, :body => "", :headers => {}) | ||
|
@@ -254,7 +254,7 @@ def test_templates_can_be_partially_created_if_error_occurs | |
assert_raise(RuntimeError) { | ||
driver('test', config) | ||
} | ||
|
||
assert_requested(:put, "https://john:[email protected]:777/es//_template/logstash1", times: 1) | ||
assert_not_requested(:put, "https://john:[email protected]:777/es//_template/logstash2") | ||
end | ||
|
@@ -770,6 +770,29 @@ def test_uses_custom_time_key_format_obscure_format | |
assert_equal(index_cmds[1]['@timestamp'], ts) | ||
end | ||
|
||
def test_uses_no_subsecond_precision_by_default | ||
driver.configure("logstash_format true\n") | ||
stub_elastic_ping | ||
stub_elastic | ||
time = Fluent::EventTime.new(Time.now.to_i, 000000000) | ||
driver.emit(sample_record, time) | ||
driver.run | ||
assert(index_cmds[1].has_key? '@timestamp') | ||
assert_equal(index_cmds[1]['@timestamp'], Time.at(time).iso8601) | ||
end | ||
|
||
def test_uses_subsecond_precision_when_configured | ||
driver.configure("logstash_format true | ||
time_precision 3\n") | ||
stub_elastic_ping | ||
stub_elastic | ||
time = Fluent::EventTime.new(Time.now.to_i, 000000000) | ||
driver.emit(sample_record, time) | ||
driver.run | ||
assert(index_cmds[1].has_key? '@timestamp') | ||
assert_equal(index_cmds[1]['@timestamp'], Time.at(time).iso8601(3)) | ||
end | ||
|
||
def test_doesnt_add_tag_key_by_default | ||
stub_elastic_ping | ||
stub_elastic | ||
|
@@ -931,7 +954,7 @@ def test_reconnect_on_error_enabled | |
stub_request(:post, "http://localhost:9200/_bulk").with do |req| | ||
raise ZeroDivisionError, "any not host_unreachable_exceptions exception" | ||
end | ||
|
||
driver.configure("reconnect_on_error true\n") | ||
driver.emit(sample_record) | ||
|
||
|
@@ -955,7 +978,7 @@ def test_reconnect_on_error_disabled | |
stub_request(:post, "http://localhost:9200/_bulk").with do |req| | ||
raise ZeroDivisionError, "any not host_unreachable_exceptions exception" | ||
end | ||
|
||
driver.configure("reconnect_on_error false\n") | ||
driver.emit(sample_record) | ||
|
||
|