Skip to content

Commit 84a424c

Browse files
authored
Allow setting timestamp_key to nil or null to supress timestamp (#63)
Fixes: #59 Signed-off-by: Jesse Szwedko <jesse.szwedko@datadoghq.com>
1 parent eff6c9c commit 84a424c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/fluent/plugin/out_datadog.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
require_relative "version"
1313

14+
def nilish?(s)
15+
s.empty? || s == "nil" || s == "false" || s == "null"
16+
end
17+
1418
class Fluent::DatadogOutput < Fluent::Plugin::Output
1519
class RetryableError < StandardError;
1620
end
@@ -80,6 +84,8 @@ def configure(conf)
8084
# Set dd_hostname if not already set (can be set when using fluentd as aggregator)
8185
@dd_hostname = %x[hostname -f 2> /dev/null].strip
8286
@dd_hostname = Socket.gethostname if @dd_hostname.empty?
87+
88+
@timestamp_key = nil if nilish?(@timestamp_key)
8389
end
8490

8591
def multi_workers_ready?

test/plugin/test_out_datadog.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ def create_valid_subject
120120
assert_equal "1970-01-01T03:25:45.000Z", result["foo"]
121121
end
122122

123+
test "should not set timestamp tag if timestamp_key is nil" do
124+
plugin = create_driver(%[
125+
api_key foo
126+
timestamp_key nil
127+
]).instance
128+
time = 12345
129+
record = {"message" => "bar"}
130+
result = plugin.enrich_record(nil, time, record)
131+
# only hostname and message fields are set, no timestamp field
132+
assert_equal ["hostname", "message"], result.keys.sort
133+
end
134+
123135
test "should add specific datadog attributes" do
124136
plugin = create_driver(%[
125137
api_key foo

0 commit comments

Comments
 (0)