fluent-plugin-datadog-log 0.1.0.rc18 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +10 -14
- data/README.rdoc +0 -8
- data/fluent-plugin-datadog-log.gemspec +4 -6
- data/lib/fluent/plugin/out_datadog_log.rb +100 -84
- data/pkg/fluent-plugin-datadog-0.1.0.gem +0 -0
- data/pkg/fluent-plugin-datadog-log-0.1.0.gem +0 -0
- data/test/plugin/test_out_datadog_log.rb +2 -85
- metadata +23 -48
- data/fluent-plugin-datadog-log.gemspec~ +0 -33
- data/lib/datadog/log.rb~ +0 -125
- data/lib/fluent/plugin/datadog_log.rb +0 -166
- data/lib/fluent/plugin/datadog_log.rb~ +0 -131
- data/lib/fluent/plugin/out_datadog_log.rb~ +0 -584
- data/pkg/fluent-plugin-datadog-log-0.1.0.rc13.gem +0 -0
- data/pkg/fluent-plugin-datadog-log-0.1.0.rc14.gem +0 -0
- data/pkg/fluent-plugin-datadog-log-0.1.0.rc15.gem +0 -0
- data/pkg/fluent-plugin-datadog-log-0.1.0.rc16.gem +0 -0
- data/pkg/fluent-plugin-datadog-log-0.1.0.rc17.gem +0 -0
- data/pkg/fluent-plugin-datadog-log-0.1.0.rc18.gem +0 -0
- data/test/plugin/test_out_datadog_log.rb~ +0 -278
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ba2d248887e5b2de08cb5fdb40dd54daf9628fb
|
4
|
+
data.tar.gz: c2dd337e77d4b81cca604116943a22acd60ab0fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2d416a45ca1e3fa96319f75b14d7fc5ef21b18c049483acc754650776c4b50eccc70bb18c2f5ec54bdc74f7cabaaf9c7c9427d04d79429dfa152da0aba406d4
|
7
|
+
data.tar.gz: 50b49c31982537c5aaa6c75cebd2456dc3dfb6d2c92861ea664df55443016010c6274307c76f1a973cd3ffc601c3ec00fce17d071d5fb90e06627a8a7d3d416d
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fluent-plugin-datadog-log (0.1.0
|
5
|
-
fluentd (~>
|
4
|
+
fluent-plugin-datadog-log (0.1.0)
|
5
|
+
fluentd (~> 0.14)
|
6
6
|
json (~> 1.8)
|
7
|
-
net_tcp_client (~> 2.0.1)
|
8
|
-
prometheus-client (~> 0.7.1)
|
9
|
-
semantic_logger (~> 4.2.0)
|
10
7
|
|
11
8
|
GEM
|
12
9
|
remote: https://rubygems.org/
|
@@ -16,11 +13,10 @@ GEM
|
|
16
13
|
ast (2.3.0)
|
17
14
|
astrolabe (1.3.1)
|
18
15
|
parser (~> 2.2)
|
19
|
-
|
20
|
-
cool.io (1.5.3)
|
16
|
+
cool.io (1.5.1)
|
21
17
|
crack (0.4.3)
|
22
18
|
safe_yaml (~> 1.0.0)
|
23
|
-
fluentd (
|
19
|
+
fluentd (0.14.22)
|
24
20
|
cool.io (>= 1.4.5, < 2.0.0)
|
25
21
|
http_parser.rb (>= 0.5.1, < 0.7.0)
|
26
22
|
msgpack (>= 0.7.0, < 2.0.0)
|
@@ -37,15 +33,15 @@ GEM
|
|
37
33
|
metaclass (0.0.4)
|
38
34
|
mocha (1.3.0)
|
39
35
|
metaclass (~> 0.0.1)
|
40
|
-
msgpack (1.
|
36
|
+
msgpack (1.1.0)
|
41
37
|
net_tcp_client (2.0.1)
|
42
|
-
parser (2.4.0.
|
43
|
-
ast (~> 2.
|
38
|
+
parser (2.4.0.0)
|
39
|
+
ast (~> 2.2)
|
44
40
|
power_assert (1.1.1)
|
45
41
|
powerpack (0.1.1)
|
46
42
|
prometheus-client (0.7.1)
|
47
43
|
quantile (~> 0.2.0)
|
48
|
-
public_suffix (3.0.
|
44
|
+
public_suffix (3.0.0)
|
49
45
|
quantile (0.2.0)
|
50
46
|
rainbow (2.2.2)
|
51
47
|
rake
|
@@ -60,8 +56,6 @@ GEM
|
|
60
56
|
ruby-progressbar (1.9.0)
|
61
57
|
ruby_dig (0.0.2)
|
62
58
|
safe_yaml (1.0.4)
|
63
|
-
semantic_logger (4.2.0)
|
64
|
-
concurrent-ruby (~> 1.0)
|
65
59
|
serverengine (2.0.5)
|
66
60
|
sigdump (~> 0.2.2)
|
67
61
|
sigdump (0.2.4)
|
@@ -86,6 +80,8 @@ PLATFORMS
|
|
86
80
|
DEPENDENCIES
|
87
81
|
fluent-plugin-datadog-log!
|
88
82
|
mocha (~> 1.1)
|
83
|
+
net_tcp_client (~> 2.0.1)
|
84
|
+
prometheus-client (~> 0.7.1)
|
89
85
|
rake (~> 10.3)
|
90
86
|
rubocop (~> 0.35.0)
|
91
87
|
test-unit (~> 3.0)
|
data/README.rdoc
CHANGED
@@ -37,14 +37,6 @@ of your fluentd configuration file, for example:
|
|
37
37
|
|
38
38
|
Add `log_level debug` to enable debug logging which dumps every payload sent to Datadog.
|
39
39
|
|
40
|
-
== Testing Datadog Connectivity within irb
|
41
|
-
|
42
|
-
cd path/to/fluent-plugin-datadog-log
|
43
|
-
|
44
|
-
bundle exec irb -r datadog/lib
|
45
|
-
|
46
|
-
c = Datadog::Log::Client.new(api_key:ENV['DD_LOG_API_KEY'],hostname:'myhost'); pl = c.send_payload(msg: 'foobar', source: 'myapp', source_category: 'stdout', service: 'irb', tags: %w|foo=bar|); puts pl
|
47
|
-
|
48
40
|
== Copyright
|
49
41
|
|
50
42
|
Copyright:: Copyright 2017 Yusuke KUOKA All rights reserved.
|
@@ -8,7 +8,7 @@ eos
|
|
8
8
|
gem.homepage = \
|
9
9
|
'https://github.com/mumoshu/fluent-plugin-datadog-log'
|
10
10
|
gem.license = 'Apache-2.0'
|
11
|
-
gem.version = '0.1.0
|
11
|
+
gem.version = '0.1.0'
|
12
12
|
gem.authors = ['Yusuke KUOKA']
|
13
13
|
gem.email = ['ykuoka@gmail.com']
|
14
14
|
gem.required_ruby_version = Gem::Requirement.new('>= 2.0')
|
@@ -17,17 +17,15 @@ eos
|
|
17
17
|
gem.test_files = gem.files.grep(/^(test)/)
|
18
18
|
gem.require_paths = ['lib']
|
19
19
|
|
20
|
-
gem.add_runtime_dependency 'fluentd', '~>
|
20
|
+
gem.add_runtime_dependency 'fluentd', '~> 0.14'
|
21
21
|
# gem.add_runtime_dependency 'datadog-log-api-client', '~> 0.1'
|
22
22
|
gem.add_runtime_dependency 'json', '~> 1.8'
|
23
23
|
|
24
|
-
gem.
|
25
|
-
gem.add_dependency 'prometheus-client', '~> 0.7.1'
|
26
|
-
gem.add_dependency 'semantic_logger', '~> 4.2.0'
|
27
|
-
|
24
|
+
gem.add_development_dependency 'net_tcp_client', '~> 2.0.1'
|
28
25
|
gem.add_development_dependency 'mocha', '~> 1.1'
|
29
26
|
gem.add_development_dependency 'rake', '~> 10.3'
|
30
27
|
gem.add_development_dependency 'rubocop', '~> 0.35.0'
|
31
28
|
gem.add_development_dependency 'webmock', '~> 2.3.1'
|
32
29
|
gem.add_development_dependency 'test-unit', '~> 3.0'
|
30
|
+
gem.add_development_dependency 'prometheus-client', '~> 0.7.1'
|
33
31
|
end
|
@@ -17,20 +17,18 @@ require 'open-uri'
|
|
17
17
|
require 'socket'
|
18
18
|
require 'time'
|
19
19
|
require 'yaml'
|
20
|
+
require 'net/tcp_client'
|
20
21
|
require 'fluent/plugin/output'
|
21
22
|
|
22
|
-
require_relative 'datadog_log'
|
23
23
|
require_relative 'monitoring'
|
24
24
|
|
25
25
|
module Fluent::Plugin
|
26
26
|
# fluentd output plugin for the Datadog Log Intake API
|
27
27
|
class DatadogOutput < ::Fluent::Plugin::Output
|
28
|
-
Fluent::Plugin.register_output('
|
28
|
+
Fluent::Plugin.register_output('datadog', self)
|
29
29
|
|
30
30
|
helpers :compat_parameters, :inject
|
31
31
|
|
32
|
-
include ::Datadog::Log
|
33
|
-
|
34
32
|
DEFAULT_BUFFER_TYPE = 'memory'
|
35
33
|
|
36
34
|
PLUGIN_NAME = 'Fluentd Datadog plugin'
|
@@ -42,6 +40,16 @@ module Fluent::Plugin
|
|
42
40
|
# Disable this warning to conform to fluentd config_param conventions.
|
43
41
|
# rubocop:disable Style/HashSyntax
|
44
42
|
|
43
|
+
TRUNCATED_MSG = '...TRUNCATED...'
|
44
|
+
|
45
|
+
TRUNCATED_LEN = TRUNCATED_MSG.size
|
46
|
+
|
47
|
+
# MaxMessageLen is the maximum length for any message we send to the intake
|
48
|
+
# see https://github.com/DataDog/datadog-log-agent/blob/2394da8c79a6cadbcd1e98d6c89c437becec2732/pkg/config/constants.go#L9-L10
|
49
|
+
DD_MAX_MESSAGE_LEN = 1 * 1000 * 1000
|
50
|
+
|
51
|
+
MAX_MESSAGE_LEN = DD_MAX_MESSAGE_LEN - TRUNCATED_LEN
|
52
|
+
|
45
53
|
# see https://github.com/DataDog/datadog-log-agent/blob/db13b53dfdd036d43acfb15089a43eb31548f09f/pkg/logagent/logsagent.go#L26-L30
|
46
54
|
# see https://github.com/DataDog/datadog-log-agent/blob/db13b53dfdd036d43acfb15089a43eb31548f09f/pkg/config/config.go#L52-L56
|
47
55
|
config_param :log_dd_url, :string, default: 'intake.logs.datadoghq.com'
|
@@ -123,14 +131,63 @@ module Fluent::Plugin
|
|
123
131
|
@log = $log # rubocop:disable Style/GlobalVars
|
124
132
|
end
|
125
133
|
|
134
|
+
def truncate_message(msg)
|
135
|
+
if msg.size > DD_MAX_MESSAGE_LEN
|
136
|
+
msg.slice(0, MAX_MESSAGE_LEN) + TRUNCATED_MSG
|
137
|
+
else
|
138
|
+
msg
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Given a list of tags, build_tags_payload generates the bytes array
|
143
|
+
# that will be inserted into messages
|
144
|
+
# @see https://github.com/DataDog/datadog-log-agent/blob/2394da8c79a6cadbcd1e98d6c89c437becec2732/pkg/config/integration_config.go#L180
|
145
|
+
def build_tags_payload(config_tags:, source:, source_category:)
|
146
|
+
payload = ''
|
147
|
+
|
148
|
+
payload = "[dd ddsource=\"#{source}\"]" if !source.nil? && source != ''
|
149
|
+
|
150
|
+
if !source_category.nil? && source_category != ''
|
151
|
+
payload = "#{payload}[dd ddsourcecategory=\"#{source_category}\"]"
|
152
|
+
end
|
153
|
+
|
154
|
+
if !config_tags.nil? && config_tags != ''
|
155
|
+
config_tags = config_tags.join(',') if config_tags.is_a? ::Array
|
156
|
+
payload = "#{payload}[dd ddtags=\"#{config_tags}\"]"
|
157
|
+
end
|
158
|
+
|
159
|
+
payload
|
160
|
+
end
|
161
|
+
|
162
|
+
# https://github.com/DataDog/datadog-log-agent/blob/db13b53dfdd036d43acfb15089a43eb31548f09f/pkg/processor/processor.go#L65
|
163
|
+
def build_extra_content(timestamp:, hostname:, service:, tags_payload:)
|
164
|
+
"<46>0 #{timestamp} #{hostname} #{service} - - #{tags_payload}"
|
165
|
+
end
|
166
|
+
|
167
|
+
def build_api_key_str(api_key:, logset:)
|
168
|
+
if !logset.nil? && logset != ''
|
169
|
+
"#{api_key}/#{logset}"
|
170
|
+
else
|
171
|
+
api_key
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# build_payload returns a processed payload from a raw message
|
176
|
+
# @param [String] api_key_str
|
177
|
+
# @param [String] extra_content
|
178
|
+
# @param [String] msg
|
179
|
+
def build_payload(api_key_str:, msg:, extra_content:)
|
180
|
+
"#{api_key_str} #{extra_content} #{msg}\\n"
|
181
|
+
end
|
182
|
+
|
126
183
|
def configure(conf)
|
127
184
|
compat_parameters_convert(conf, :buffer, :inject)
|
128
185
|
super
|
129
186
|
|
130
187
|
if @api_key.size == 0
|
131
|
-
@api_key = ENV['
|
188
|
+
@api_key = ENV['DD_LOG_API_KEY']
|
132
189
|
if @api_key == '' || @api_key.nil?
|
133
|
-
error_message = 'Unable to obtain api_key from
|
190
|
+
error_message = 'Unable to obtain api_key from DD_LOG_API_KEY'
|
134
191
|
fail Fluent::ConfigError, error_message
|
135
192
|
end
|
136
193
|
end
|
@@ -183,7 +240,7 @@ module Fluent::Plugin
|
|
183
240
|
|
184
241
|
def shutdown
|
185
242
|
super
|
186
|
-
@conn.
|
243
|
+
@conn.close unless @conn.nil?
|
187
244
|
end
|
188
245
|
|
189
246
|
def format(tag, time, record)
|
@@ -232,10 +289,7 @@ module Fluent::Plugin
|
|
232
289
|
begin
|
233
290
|
msg = nil
|
234
291
|
%w(log message msg).each do |field|
|
235
|
-
if record.key?(field)
|
236
|
-
msg = record[field]
|
237
|
-
break
|
238
|
-
end
|
292
|
+
msg = record[field] if record.key?(field)
|
239
293
|
end
|
240
294
|
|
241
295
|
tags = []
|
@@ -249,31 +303,13 @@ module Fluent::Plugin
|
|
249
303
|
}
|
250
304
|
|
251
305
|
mappings.each do |json_key, tag_key|
|
252
|
-
tags << "#{tag_key}
|
306
|
+
tags << "#{tag_key}=#{kube[json_key]}" if kube.key? json_key
|
253
307
|
end
|
254
308
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
k2.gsub!(/[\,\.]/, '_')
|
260
|
-
k2.gsub!(%r{/}, '-')
|
261
|
-
tags << "kube_#{k2}:#{v}"
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
@log.debug 'Dumping kubernetes metadata', metadata: kube
|
266
|
-
|
267
|
-
annotations = kube['annotations']
|
268
|
-
unless annotations.nil?
|
269
|
-
created_by_str = annotations['kubernetes_io/created-by']
|
270
|
-
unless created_by_str.nil?
|
271
|
-
created_by = JSON.parse(created_by_str)
|
272
|
-
ref = created_by['reference'] unless created_by.nil?
|
273
|
-
kind = ref['kind'] unless ref.nil?
|
274
|
-
name = ref['name'] unless ref.nil?
|
275
|
-
kind = kind.downcase unless kind.nil?
|
276
|
-
tags << "kube_#{kind}:#{name}" if !kind.nil? && !name.nil?
|
309
|
+
if kube.key? 'labels'
|
310
|
+
labels = kube['labels']
|
311
|
+
labels.each do |k, v|
|
312
|
+
tags << "kube_#{k}=#{v}"
|
277
313
|
end
|
278
314
|
end
|
279
315
|
|
@@ -285,31 +321,26 @@ module Fluent::Plugin
|
|
285
321
|
|
286
322
|
tags.concat(@default_tags)
|
287
323
|
|
288
|
-
unless kube_labels.nil?
|
289
|
-
service = kube_labels['app'] ||
|
290
|
-
kube_labels['k8s-app']
|
291
|
-
end
|
292
|
-
source = kube['pod_name']
|
293
|
-
source_category = kube['container_name']
|
294
|
-
|
295
|
-
service = @service if service.nil?
|
296
|
-
source = @source if source.nil?
|
297
|
-
source_category = @source_category if source_category.nil?
|
298
|
-
|
299
324
|
datetime = Time.at(Fluent::EventTime.new(time).to_r).utc.to_datetime
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
325
|
+
timestamp_str = datetime.rfc3339(6)
|
326
|
+
|
327
|
+
payload = build_payload(
|
328
|
+
api_key_str: build_api_key_str(api_key: @api_key, logset: @logset),
|
329
|
+
msg: truncate_message(msg),
|
330
|
+
extra_content: build_extra_content(
|
331
|
+
timestamp: timestamp_str,
|
332
|
+
hostname: @vm_id,
|
333
|
+
service: @service,
|
334
|
+
tags_payload: build_tags_payload(
|
335
|
+
config_tags: tags,
|
336
|
+
source: @source,
|
337
|
+
source_category: @source_category
|
338
|
+
)
|
310
339
|
)
|
340
|
+
)
|
311
341
|
|
312
342
|
entries_count = 1
|
343
|
+
@conn.write(payload)
|
313
344
|
@log.debug 'Sent payload to Datadog.', payload: payload
|
314
345
|
increment_successful_requests_count
|
315
346
|
increment_ingested_entries_count(entries_count)
|
@@ -323,33 +354,17 @@ module Fluent::Plugin
|
|
323
354
|
|
324
355
|
rescue => error
|
325
356
|
increment_failed_requests_count
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
increment_retried_entries_count(entries_count)
|
332
|
-
# RPC cancelled, so retry via re-raising the error.
|
333
|
-
@log.debug "Retrying #{entries_count} log message(s) later.",
|
334
|
-
error: error.to_s
|
335
|
-
raise error
|
336
|
-
end
|
357
|
+
increment_retried_entries_count(entries_count)
|
358
|
+
# RPC cancelled, so retry via re-raising the error.
|
359
|
+
@log.debug "Retrying #{entries_count} log message(s) later.",
|
360
|
+
error: error.to_s
|
361
|
+
raise error
|
337
362
|
end
|
338
363
|
end
|
339
364
|
end
|
340
365
|
|
341
366
|
private
|
342
367
|
|
343
|
-
def init_api_client
|
344
|
-
@conn = ::Datadog::Log::Client.new(
|
345
|
-
log_dd_url: @log_dd_url,
|
346
|
-
log_dd_port: @log_dd_port,
|
347
|
-
api_key: @api_key,
|
348
|
-
hostname: @vm_id,
|
349
|
-
skip_ssl_validation: @skip_ssl_validation
|
350
|
-
)
|
351
|
-
end
|
352
|
-
|
353
368
|
def parse_json_or_nil(input)
|
354
369
|
# Only here to please rubocop...
|
355
370
|
return nil if input.nil?
|
@@ -479,24 +494,18 @@ module Fluent::Plugin
|
|
479
494
|
aws_account_id = ec2_metadata['accountId'] if
|
480
495
|
ec2_metadata.key?('accountId')
|
481
496
|
# #host:i-09fbfed2672d2c6bf
|
482
|
-
%W(host
|
497
|
+
%W(host=#{@vm_id} zone=#{@zone} aws_account_id=#{aws_account_id})
|
483
498
|
.concat @tags
|
484
499
|
end
|
485
500
|
|
486
501
|
# Filter out invalid non-Hash entries.
|
487
502
|
def each_valid_record(chunk)
|
488
503
|
chunk.msgpack_each do |event|
|
489
|
-
unless event.respond_to? :last
|
490
|
-
@log.warn 'Dropping a malformed event: ' \
|
491
|
-
"'#{event.inspect}'. " \
|
492
|
-
'An event should be an array.'
|
493
|
-
next
|
494
|
-
end
|
495
504
|
record = event.last
|
496
505
|
unless record.is_a?(Hash)
|
497
506
|
@log.warn 'Dropping log entries with malformed record: ' \
|
498
507
|
"'#{record.inspect}'. " \
|
499
|
-
|
508
|
+
'A log record should be in JSON format.'
|
500
509
|
next
|
501
510
|
end
|
502
511
|
tag = record.first
|
@@ -524,6 +533,13 @@ module Fluent::Plugin
|
|
524
533
|
tag
|
525
534
|
end
|
526
535
|
|
536
|
+
def init_api_client
|
537
|
+
ssl = true
|
538
|
+
ssl = { verify_mode: OpenSSL::SSL::VERIFY_NONE } if @skip_ssl_validation
|
539
|
+
server = "#{@log_dd_url}:#{@log_dd_port}"
|
540
|
+
@conn = Net::TCPClient.new(server: server, ssl: ssl)
|
541
|
+
end
|
542
|
+
|
527
543
|
# Encode as UTF-8. If 'coerce_to_utf8' is set to true in the config, any
|
528
544
|
# non-UTF-8 character would be replaced by the string specified by
|
529
545
|
# 'non_utf8_replacement_string'. If 'coerce_to_utf8' is set to false, any
|
Binary file
|
Binary file
|
@@ -35,31 +35,6 @@ class DatadogLogOutputTest < Test::Unit::TestCase
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def test_configure_with_env
|
39
|
-
new_stub_context do
|
40
|
-
setup_ec2_metadata_stubs
|
41
|
-
|
42
|
-
ENV.stubs(:[])
|
43
|
-
.with('DD_API_KEY')
|
44
|
-
.returns('myapikey_from_env')
|
45
|
-
|
46
|
-
ENV.stubs(:[])
|
47
|
-
.with(Not equals 'DD_API_KEY')
|
48
|
-
.returns('')
|
49
|
-
.times(3)
|
50
|
-
|
51
|
-
d = create_driver(<<-EOC)
|
52
|
-
type datadog_log
|
53
|
-
service myservice
|
54
|
-
source mysource
|
55
|
-
EOC
|
56
|
-
|
57
|
-
assert_equal 'myapikey_from_env', d.instance.api_key
|
58
|
-
assert_equal 'myservice', d.instance.service
|
59
|
-
assert_equal 'mysource', d.instance.source
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
38
|
def test_write
|
64
39
|
new_stub_context do
|
65
40
|
setup_ec2_metadata_stubs
|
@@ -78,66 +53,16 @@ class DatadogLogOutputTest < Test::Unit::TestCase
|
|
78
53
|
EOC
|
79
54
|
conn = StubConn.new
|
80
55
|
fluentd_tag = 'mytag'
|
81
|
-
Net::TCPClient.stubs(:new)
|
82
|
-
.with(server: 'intake.logs.datadoghq.com:10516', ssl: true)
|
83
|
-
.returns(conn)
|
84
|
-
d.run(default_tag: fluentd_tag) do
|
85
|
-
record = {
|
86
|
-
'log' => 'mymsg'
|
87
|
-
}
|
88
|
-
d.feed(time, record)
|
89
|
-
end
|
90
|
-
|
91
|
-
# fail d.logs.inspect
|
92
|
-
assert_equal(1, d.logs.count { |l| l =~ /Sent payload to Datadog/ })
|
93
|
-
assert_equal(1, conn.sent.size)
|
94
|
-
# rubocop:disable LineLength
|
95
|
-
payload = %(myapikey/mylogset <46>0 2006-01-02T15:04:05.000000+00:00 i-81c16767 myservice - - [dd ddsource="mysource"][dd ddsourcecategory="mysourcecategory"][dd ddtags="host:i-81c16767,zone:aws:us-west-2b,aws_account_id:123456789012"] mymsg\n)
|
96
|
-
# rubocop:enable LineLength
|
97
|
-
assert_equal(payload, conn.sent.first)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_write_kube
|
102
|
-
new_stub_context do
|
103
|
-
setup_ec2_metadata_stubs
|
104
|
-
|
105
|
-
timestamp_str = '2006-01-02T15:04:05.000000+00:00'
|
106
|
-
t = DateTime.rfc3339(timestamp_str).to_time
|
107
|
-
time = Fluent::EventTime.from_time(t)
|
108
|
-
d = create_driver(<<-EOC)
|
109
|
-
type datadog_log
|
110
|
-
api_key myapikey
|
111
|
-
service myservice
|
112
|
-
source mysource
|
113
|
-
source_category mysourcecategory
|
114
|
-
logset mylogset
|
115
|
-
log_level debug
|
116
|
-
tags ["kube_cluster:MyCluster", "mykey:myval"]
|
117
|
-
EOC
|
118
|
-
conn = StubConn.new
|
119
|
-
fluentd_tag = 'mytag'
|
120
|
-
Net::TCPClient.stubs(:new)
|
121
|
-
.with(server: 'intake.logs.datadoghq.com:10516', ssl: true)
|
122
|
-
.returns(conn)
|
123
56
|
d.run(default_tag: fluentd_tag) do
|
57
|
+
d.instance.instance_variable_set :@conn, conn
|
124
58
|
record = {
|
125
59
|
'log' => 'mymsg',
|
126
|
-
'docker' => {
|
127
|
-
'container_id' => 'myfullcontainerid'
|
128
|
-
},
|
129
60
|
'kubernetes' => {
|
130
61
|
'namespace' => 'myns',
|
131
62
|
'pod_name' => 'mypod',
|
132
63
|
'container_name' => 'mycontainer',
|
133
64
|
'labels' => {
|
134
65
|
'k8s-app' => 'myapp'
|
135
|
-
},
|
136
|
-
'annotations' => {
|
137
|
-
# rubocop:disable LineLength
|
138
|
-
# kubernetes.io is translated to kubernetes_io by kubernetes metadata filter
|
139
|
-
'kubernetes_io/created-by' => '{"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"Deployment","namespace":"default","name":"myapp","uid":"d67e8857-c2dc-11e7-aed9-066d23381f8c","apiVersion":"extensions","resourceVersion":"289"}}'
|
140
|
-
# rubocop:enable LineLength
|
141
66
|
}
|
142
67
|
}
|
143
68
|
}
|
@@ -148,7 +73,7 @@ class DatadogLogOutputTest < Test::Unit::TestCase
|
|
148
73
|
assert_equal(1, d.logs.count { |l| l =~ /Sent payload to Datadog/ })
|
149
74
|
assert_equal(1, conn.sent.size)
|
150
75
|
# rubocop:disable LineLength
|
151
|
-
payload =
|
76
|
+
payload = 'myapikey/mylogset <46>0 2006-01-02T15:04:05.000000+00:00 i-81c16767 myservice - - [dd ddsource="mysource"][dd ddsourcecategory="mysourcecategory"][dd ddtags="pod_name=mypod,container_name=mycontainer,kube_k8s-app=myapp,host=i-81c16767,zone=aws:us-west-2b,aws_account_id=123456789012"] mymsg\n'
|
152
77
|
# rubocop:enable LineLength
|
153
78
|
assert_equal(payload, conn.sent.first)
|
154
79
|
end
|
@@ -178,10 +103,6 @@ class DatadogLogOutputTest < Test::Unit::TestCase
|
|
178
103
|
log_level debug
|
179
104
|
enable_monitoring true
|
180
105
|
EOC
|
181
|
-
conn = StubConn.new
|
182
|
-
Net::TCPClient.stubs(:new)
|
183
|
-
.with(server: 'intake.logs.datadoghq.com:10516', ssl: true)
|
184
|
-
.returns(conn)
|
185
106
|
d.run(default_tag: 'mytag') do
|
186
107
|
(1..entry_count).each do |i|
|
187
108
|
d.feed time, 'message' => log_entry(i.to_s)
|
@@ -221,10 +142,6 @@ class DatadogLogOutputTest < Test::Unit::TestCase
|
|
221
142
|
@sent = []
|
222
143
|
end
|
223
144
|
|
224
|
-
def retry_on_connection_failure
|
225
|
-
yield
|
226
|
-
end
|
227
|
-
|
228
145
|
def write(payload)
|
229
146
|
@sent << payload
|
230
147
|
end
|