-
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.
Merge pull request #249 from sampointer/add_configurable_time_precisi…
…on_when_timestamp_missing configurable sub-second precision with no time key
- Loading branch information
Showing
3 changed files
with
50 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 | ||
|
@@ -780,6 +780,37 @@ 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 | ||
begin | ||
time = Fluent::EventTime.new(Time.now.to_i, 000000000) | ||
rescue | ||
time = Fluent::Engine.now | ||
end | ||
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 | ||
begin | ||
time = Fluent::EventTime.new(Time.now.to_i, 000000000) | ||
rescue | ||
time = Fluent::Engine.now | ||
end | ||
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 | ||
|
@@ -941,7 +972,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) | ||
|
||
|
@@ -965,7 +996,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) | ||
|
||
|