fluent-plugin-cloudwatch-logs 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/example/fluentd.conf +4 -4
- data/lib/fluent/plugin/cloudwatch/logs/version.rb +1 -1
- data/lib/fluent/plugin/out_cloudwatch_logs.rb +69 -5
- data/test/plugin/test_in_cloudwatch_logs.rb +4 -4
- data/test/plugin/test_out_cloudwatch_logs.rb +196 -13
- data/test/test_helper.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f8fe8ec7ee187171451b47e824e14f3c475663bad90624b20c575b9ba7fa9eb
|
4
|
+
data.tar.gz: 9adc8de66f127eb20aa14830d88bd6cbc08a684ce8e4bec14543317dd26028df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ea28c6a7ba48d50891185c767ef5a3317d64964f89d809c643f191826cd092a77d99a12f80d3aafb3031941af1e25e12ea79a0fee374195d9882f3e3fe6bea7
|
7
|
+
data.tar.gz: c11a426c35c25ab35ddd066141c4c18e7df7b0f88482d4efd9544877376554001a1b1440e2068c8794bdbe12c7232bb4e07e7d7956e6b047986a68da33dcca1d
|
data/README.md
CHANGED
@@ -65,7 +65,7 @@ Fetch sample log from CloudWatch Logs:
|
|
65
65
|
|
66
66
|
```
|
67
67
|
<match tag>
|
68
|
-
type cloudwatch_logs
|
68
|
+
@type cloudwatch_logs
|
69
69
|
log_group_name log-group-name
|
70
70
|
log_stream_name log-stream-name
|
71
71
|
auto_create_stream true
|
@@ -107,7 +107,7 @@ Fetch sample log from CloudWatch Logs:
|
|
107
107
|
|
108
108
|
```
|
109
109
|
<source>
|
110
|
-
type cloudwatch_logs
|
110
|
+
@type cloudwatch_logs
|
111
111
|
tag cloudwatch.in
|
112
112
|
log_group_name group
|
113
113
|
log_stream_name stream
|
@@ -235,7 +235,7 @@ In this case IAM can be used to allow the fluentd instance in one account ("A")
|
|
235
235
|
### Configuring the plugin for STS authentication
|
236
236
|
```
|
237
237
|
<source>
|
238
|
-
type cloudwatch_logs
|
238
|
+
@type cloudwatch_logs
|
239
239
|
region us-east-1 # You must supply a region
|
240
240
|
aws_use_sts true
|
241
241
|
aws_sts_role_arn arn:aws:iam::ACCOUNT-B:role/fluentd
|
data/example/fluentd.conf
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
<source>
|
2
|
-
type forward
|
2
|
+
@type forward
|
3
3
|
</source>
|
4
4
|
|
5
5
|
<source>
|
6
|
-
type cloudwatch_logs
|
6
|
+
@type cloudwatch_logs
|
7
7
|
tag test.cloudwatch_logs.in
|
8
8
|
log_group_name fluent-plugin-cloudwatch-example
|
9
9
|
log_stream_name fluent-plugin-cloudwatch-example
|
@@ -11,13 +11,13 @@
|
|
11
11
|
</source>
|
12
12
|
|
13
13
|
<match test.cloudwatch_logs.out>
|
14
|
-
type cloudwatch_logs
|
14
|
+
@type cloudwatch_logs
|
15
15
|
log_group_name fluent-plugin-cloudwatch-example
|
16
16
|
log_stream_name fluent-plugin-cloudwatch-example
|
17
17
|
auto_create_stream true
|
18
18
|
</match>
|
19
19
|
|
20
20
|
<match test.cloudwatch_logs.in>
|
21
|
-
type stdout
|
21
|
+
@type stdout
|
22
22
|
</match>
|
23
23
|
|
@@ -12,6 +12,9 @@ module Fluent
|
|
12
12
|
|
13
13
|
config_param :aws_key_id, :string, :default => nil, :secret => true
|
14
14
|
config_param :aws_sec_key, :string, :default => nil, :secret => true
|
15
|
+
config_param :aws_use_sts, :bool, default: false
|
16
|
+
config_param :aws_sts_role_arn, :string, default: nil
|
17
|
+
config_param :aws_sts_session_name, :string, default: 'fluentd'
|
15
18
|
config_param :region, :string, :default => nil
|
16
19
|
config_param :log_group_name, :string, :default => nil
|
17
20
|
config_param :log_stream_name, :string, :default => nil
|
@@ -30,6 +33,12 @@ module Fluent
|
|
30
33
|
config_param :put_log_events_retry_limit, :integer, default: 17
|
31
34
|
config_param :put_log_events_disable_retry_limit, :bool, default: false
|
32
35
|
config_param :concurrency, :integer, default: 1
|
36
|
+
config_param :log_group_aws_tags, :hash, default: nil
|
37
|
+
config_param :log_group_aws_tags_key, :string, default: nil
|
38
|
+
config_param :remove_log_group_aws_tags_key, :bool, default: false
|
39
|
+
config_param :retention_in_days, :integer, default: nil
|
40
|
+
config_param :retention_in_days_key, :string, default: nil
|
41
|
+
config_param :remove_retention_in_days, :bool, default: false
|
33
42
|
|
34
43
|
MAX_EVENTS_SIZE = 1_048_576
|
35
44
|
MAX_EVENT_SIZE = 256 * 1024
|
@@ -59,14 +68,31 @@ module Fluent
|
|
59
68
|
unless [conf['log_stream_name'], conf['use_tag_as_stream'], conf['log_stream_name_key']].compact.size == 1
|
60
69
|
raise ConfigError, "Set only one of log_stream_name, use_tag_as_stream and log_stream_name_key"
|
61
70
|
end
|
71
|
+
|
72
|
+
if [conf['log_group_aws_tags'], conf['log_group_aws_tags_key']].compact.size > 1
|
73
|
+
raise ConfigError, "Set only one of log_group_aws_tags, log_group_aws_tags_key"
|
74
|
+
end
|
75
|
+
|
76
|
+
if [conf['retention_in_days'], conf['retention_in_days_key']].compact.size > 1
|
77
|
+
raise ConfigError, "Set only one of retention_in_days, retention_in_days_key"
|
78
|
+
end
|
62
79
|
end
|
63
80
|
|
64
81
|
def start
|
65
82
|
super
|
66
83
|
|
67
84
|
options = {}
|
68
|
-
options[:credentials] = Aws::Credentials.new(@aws_key_id, @aws_sec_key) if @aws_key_id && @aws_sec_key
|
69
85
|
options[:region] = @region if @region
|
86
|
+
|
87
|
+
if @aws_use_sts
|
88
|
+
Aws.config[:region] = options[:region]
|
89
|
+
options[:credentials] = Aws::AssumeRoleCredentials.new(
|
90
|
+
role_arn: @aws_sts_role_arn,
|
91
|
+
role_session_name: @aws_sts_session_name
|
92
|
+
)
|
93
|
+
else
|
94
|
+
options[:credentials] = Aws::Credentials.new(@aws_key_id, @aws_sec_key) if @aws_key_id && @aws_sec_key
|
95
|
+
end
|
70
96
|
options[:http_proxy] = @http_proxy if @http_proxy
|
71
97
|
@logs ||= Aws::CloudWatchLogs::Client.new(options)
|
72
98
|
@sequence_tokens = {}
|
@@ -124,8 +150,31 @@ module Fluent
|
|
124
150
|
end
|
125
151
|
|
126
152
|
unless log_group_exists?(group_name)
|
153
|
+
#rs = [[name, timestamp, record],[name,timestamp,record]]
|
154
|
+
#get tags and retention from first record
|
155
|
+
#as we create log group only once, values from first record will persist
|
156
|
+
record = rs[0][2]
|
157
|
+
|
158
|
+
awstags = @log_group_aws_tags
|
159
|
+
unless @log_group_aws_tags_key.nil?
|
160
|
+
if @remove_log_group_aws_tags_key
|
161
|
+
awstags = record.delete(@log_group_aws_tags_key)
|
162
|
+
else
|
163
|
+
awstags = record[@log_group_aws_tags_key]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
retention_in_days = @retention_in_days
|
168
|
+
unless @retention_in_days_key.nil?
|
169
|
+
if @remove_retention_in_days_key
|
170
|
+
retention_in_days = record.delete(@retention_in_days_key)
|
171
|
+
else
|
172
|
+
retention_in_days = record[@retention_in_days_key]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
127
176
|
if @auto_create_stream
|
128
|
-
create_log_group(group_name)
|
177
|
+
create_log_group(group_name, awstags, retention_in_days)
|
129
178
|
else
|
130
179
|
log.warn "Log group '#{group_name}' does not exist"
|
131
180
|
next
|
@@ -200,7 +249,7 @@ module Fluent
|
|
200
249
|
end
|
201
250
|
|
202
251
|
def store_next_sequence_token(group_name, stream_name, token)
|
203
|
-
@store_next_sequence_token_mutex.synchronize do
|
252
|
+
@store_next_sequence_token_mutex.synchronize do
|
204
253
|
@sequence_tokens[group_name][stream_name] = token
|
205
254
|
end
|
206
255
|
end
|
@@ -255,6 +304,7 @@ module Fluent
|
|
255
304
|
begin
|
256
305
|
t = Time.now
|
257
306
|
response = @logs.put_log_events(args)
|
307
|
+
log.warn response.rejected_log_events_info if response.rejected_log_events_info != nil
|
258
308
|
log.debug "Called PutLogEvents API", {
|
259
309
|
"group" => group_name,
|
260
310
|
"stream" => stream_name,
|
@@ -314,15 +364,29 @@ module Fluent
|
|
314
364
|
store_next_sequence_token(group_name, stream_name, response.next_sequence_token)
|
315
365
|
end
|
316
366
|
|
317
|
-
def create_log_group(group_name)
|
367
|
+
def create_log_group(group_name, log_group_aws_tags = nil, retention_in_days = nil)
|
318
368
|
begin
|
319
|
-
@logs.create_log_group(log_group_name: group_name)
|
369
|
+
@logs.create_log_group(log_group_name: group_name, tags: log_group_aws_tags)
|
370
|
+
unless retention_in_days.nil?
|
371
|
+
put_retention_policy(group_name, retention_in_days)
|
372
|
+
end
|
320
373
|
@sequence_tokens[group_name] = {}
|
321
374
|
rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException
|
322
375
|
log.debug "Log group '#{group_name}' already exists"
|
323
376
|
end
|
324
377
|
end
|
325
378
|
|
379
|
+
def put_retention_policy(group_name, retention_in_days)
|
380
|
+
begin
|
381
|
+
@logs.put_retention_policy({
|
382
|
+
log_group_name: group_name,
|
383
|
+
retention_in_days: retention_in_days
|
384
|
+
})
|
385
|
+
rescue Aws::CloudWatchLogs::Errors::InvalidParameterException => error
|
386
|
+
log.warn "failed to set retention policy for Log group '#{group_name}' with error #{error.backtrace}"
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
326
390
|
def create_log_stream(group_name, stream_name)
|
327
391
|
begin
|
328
392
|
@logs.create_log_stream(log_group_name: group_name, log_stream_name: stream_name)
|
@@ -15,7 +15,7 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
def test_configure
|
17
17
|
d = create_driver(<<-EOC)
|
18
|
-
type cloudwatch_logs
|
18
|
+
@type cloudwatch_logs
|
19
19
|
aws_key_id test_id
|
20
20
|
aws_sec_key test_key
|
21
21
|
region us-east-1
|
@@ -71,7 +71,7 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
71
71
|
|
72
72
|
d = create_driver(<<-EOC)
|
73
73
|
tag test
|
74
|
-
type cloudwatch_logs
|
74
|
+
@type cloudwatch_logs
|
75
75
|
log_group_name #{log_group_name}
|
76
76
|
log_stream_name #{log_stream_name}
|
77
77
|
state_file /tmp/state
|
@@ -116,7 +116,7 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
116
116
|
|
117
117
|
d = create_driver(<<-EOC)
|
118
118
|
tag test
|
119
|
-
type cloudwatch_logs
|
119
|
+
@type cloudwatch_logs
|
120
120
|
log_group_name #{log_group_name}
|
121
121
|
log_stream_name testprefix
|
122
122
|
use_log_stream_name_prefix true
|
@@ -141,7 +141,7 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
141
141
|
def default_config
|
142
142
|
<<-EOC
|
143
143
|
tag test
|
144
|
-
type cloudwatch_logs
|
144
|
+
@type cloudwatch_logs
|
145
145
|
log_group_name #{log_group_name}
|
146
146
|
log_stream_name #{log_stream_name}
|
147
147
|
state_file /tmp/state
|
@@ -17,13 +17,15 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
17
17
|
|
18
18
|
def test_configure
|
19
19
|
d = create_driver(<<-EOC)
|
20
|
-
type cloudwatch_logs
|
20
|
+
@type cloudwatch_logs
|
21
21
|
aws_key_id test_id
|
22
22
|
aws_sec_key test_key
|
23
23
|
region us-east-1
|
24
24
|
log_group_name test_group
|
25
25
|
log_stream_name test_stream
|
26
26
|
auto_create_stream false
|
27
|
+
log_group_aws_tags { "tagkey": "tagvalue", "tagkey_2": "tagvalue_2"}
|
28
|
+
retention_in_days 5
|
27
29
|
EOC
|
28
30
|
|
29
31
|
assert_equal('test_id', d.instance.aws_key_id)
|
@@ -32,6 +34,9 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
32
34
|
assert_equal('test_group', d.instance.log_group_name)
|
33
35
|
assert_equal('test_stream', d.instance.log_stream_name)
|
34
36
|
assert_equal(false, d.instance.auto_create_stream)
|
37
|
+
assert_equal("tagvalue", d.instance.log_group_aws_tags.fetch("tagkey"))
|
38
|
+
assert_equal("tagvalue_2", d.instance.log_group_aws_tags.fetch("tagkey_2"))
|
39
|
+
assert_equal(5, d.instance.retention_in_days)
|
35
40
|
end
|
36
41
|
|
37
42
|
def test_write
|
@@ -52,7 +57,7 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
52
57
|
assert_equal((time.to_i + 1) * 1000, events[1].timestamp)
|
53
58
|
assert_equal('{"cloudwatch":"logs2"}', events[1].message)
|
54
59
|
|
55
|
-
assert_match(/
|
60
|
+
assert_match(/Called PutLogEvents API/, d.instance.log.logs[0])
|
56
61
|
end
|
57
62
|
|
58
63
|
def test_write_utf8
|
@@ -270,7 +275,7 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
270
275
|
d.run
|
271
276
|
|
272
277
|
# Call API once for each stream
|
273
|
-
assert_equal(2, d.instance.log.logs.select {|l| l =~ /
|
278
|
+
assert_equal(2, d.instance.log.logs.select {|l| l =~ /Called PutLogEvents API/ }.size)
|
274
279
|
|
275
280
|
sleep 10
|
276
281
|
|
@@ -310,6 +315,188 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
310
315
|
assert_equal({'cloudwatch' => 'logs1', 'message' => 'message1'}, JSON.parse(events[0].message))
|
311
316
|
end
|
312
317
|
|
318
|
+
def test_log_group_aws_tags
|
319
|
+
clear_log_group
|
320
|
+
|
321
|
+
d = create_driver(<<-EOC)
|
322
|
+
#{default_config}
|
323
|
+
auto_create_stream true
|
324
|
+
use_tag_as_stream true
|
325
|
+
log_group_name_key group_name_key
|
326
|
+
log_group_aws_tags {"tag1": "value1", "tag2": "value2"}
|
327
|
+
EOC
|
328
|
+
|
329
|
+
records = [
|
330
|
+
{'cloudwatch' => 'logs1', 'message' => 'message1', 'group_name_key' => log_group_name},
|
331
|
+
{'cloudwatch' => 'logs2', 'message' => 'message1', 'group_name_key' => log_group_name},
|
332
|
+
{'cloudwatch' => 'logs3', 'message' => 'message1', 'group_name_key' => log_group_name},
|
333
|
+
]
|
334
|
+
|
335
|
+
time = Time.now
|
336
|
+
records.each_with_index do |record, i|
|
337
|
+
d.emit(record, time.to_i + i)
|
338
|
+
end
|
339
|
+
d.run
|
340
|
+
|
341
|
+
awstags = get_log_group_tags
|
342
|
+
assert_equal("value1", awstags.fetch("tag1"))
|
343
|
+
assert_equal("value2", awstags.fetch("tag2"))
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_retention_in_days
|
347
|
+
clear_log_group
|
348
|
+
|
349
|
+
d = create_driver(<<-EOC)
|
350
|
+
#{default_config}
|
351
|
+
auto_create_stream true
|
352
|
+
use_tag_as_stream true
|
353
|
+
log_group_name_key group_name_key
|
354
|
+
retention_in_days 7
|
355
|
+
EOC
|
356
|
+
|
357
|
+
records = [
|
358
|
+
{'cloudwatch' => 'logs1', 'message' => 'message1', 'group_name_key' => log_group_name},
|
359
|
+
{'cloudwatch' => 'logs2', 'message' => 'message1', 'group_name_key' => log_group_name},
|
360
|
+
{'cloudwatch' => 'logs3', 'message' => 'message1', 'group_name_key' => log_group_name},
|
361
|
+
]
|
362
|
+
|
363
|
+
time = Time.now
|
364
|
+
records.each_with_index do |record, i|
|
365
|
+
d.emit(record, time.to_i + i)
|
366
|
+
end
|
367
|
+
d.run
|
368
|
+
|
369
|
+
retention = get_log_group_retention_days
|
370
|
+
assert_equal(d.instance.retention_in_days, retention)
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_invalid_retention_in_days
|
374
|
+
clear_log_group
|
375
|
+
|
376
|
+
d = create_driver(<<-EOC)
|
377
|
+
#{default_config}
|
378
|
+
auto_create_stream true
|
379
|
+
use_tag_as_stream true
|
380
|
+
log_group_name_key group_name_key
|
381
|
+
retention_in_days 4
|
382
|
+
EOC
|
383
|
+
|
384
|
+
records = [
|
385
|
+
{'cloudwatch' => 'logs1', 'message' => 'message1', 'group_name_key' => log_group_name},
|
386
|
+
{'cloudwatch' => 'logs2', 'message' => 'message1', 'group_name_key' => log_group_name},
|
387
|
+
{'cloudwatch' => 'logs3', 'message' => 'message1', 'group_name_key' => log_group_name},
|
388
|
+
]
|
389
|
+
|
390
|
+
time = Time.now
|
391
|
+
records.each_with_index do |record, i|
|
392
|
+
d.emit(record, time.to_i + i)
|
393
|
+
end
|
394
|
+
d.run
|
395
|
+
|
396
|
+
assert_match(/failed to set retention policy for Log group/, d.instance.log.logs[0])
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_log_group_aws_tags_key
|
400
|
+
clear_log_group
|
401
|
+
|
402
|
+
d = create_driver(<<-EOC)
|
403
|
+
#{default_config}
|
404
|
+
auto_create_stream true
|
405
|
+
use_tag_as_stream true
|
406
|
+
log_group_name_key group_name_key
|
407
|
+
log_group_aws_tags_key aws_tags
|
408
|
+
EOC
|
409
|
+
|
410
|
+
records = [
|
411
|
+
{'cloudwatch' => 'logs1', 'message' => 'message1', 'group_name_key' => log_group_name, 'aws_tags' => {"tag1" => "value1", "tag2" => "value2"}},
|
412
|
+
{'cloudwatch' => 'logs2', 'message' => 'message1', 'group_name_key' => log_group_name, 'aws_tags' => {"tag1" => "value1", "tag2" => "value2"}},
|
413
|
+
{'cloudwatch' => 'logs3', 'message' => 'message1', 'group_name_key' => log_group_name, 'aws_tags' => {"tag1" => "value1", "tag2" => "value2"}}
|
414
|
+
]
|
415
|
+
|
416
|
+
time = Time.now
|
417
|
+
records.each_with_index do |record, i|
|
418
|
+
d.emit(record, time.to_i + i)
|
419
|
+
end
|
420
|
+
d.run
|
421
|
+
|
422
|
+
awstags = get_log_group_tags
|
423
|
+
assert_equal("value1", awstags.fetch("tag1"))
|
424
|
+
assert_equal("value2", awstags.fetch("tag2"))
|
425
|
+
end
|
426
|
+
|
427
|
+
def test_log_group_aws_tags_key_same_group_diff_tags
|
428
|
+
clear_log_group
|
429
|
+
|
430
|
+
d = create_driver(<<-EOC)
|
431
|
+
#{default_config}
|
432
|
+
auto_create_stream true
|
433
|
+
use_tag_as_stream true
|
434
|
+
log_group_name_key group_name_key
|
435
|
+
log_group_aws_tags_key aws_tags
|
436
|
+
EOC
|
437
|
+
|
438
|
+
records = [
|
439
|
+
{'cloudwatch' => 'logs1', 'message' => 'message1', 'group_name_key' => log_group_name, 'aws_tags' => {"tag1" => "value1", "tag2" => "value2"}},
|
440
|
+
{'cloudwatch' => 'logs3', 'message' => 'message1', 'group_name_key' => log_group_name, 'aws_tags' => {"tag3" => "value3", "tag4" => "value4"}}
|
441
|
+
]
|
442
|
+
|
443
|
+
time = Time.now
|
444
|
+
records.each_with_index do |record, i|
|
445
|
+
d.emit(record, time.to_i + i)
|
446
|
+
end
|
447
|
+
d.run
|
448
|
+
|
449
|
+
awstags = get_log_group_tags
|
450
|
+
assert_equal("value1", awstags.fetch("tag1"))
|
451
|
+
assert_equal("value2", awstags.fetch("tag2"))
|
452
|
+
assert_raise KeyError do
|
453
|
+
awstags.fetch("tag3")
|
454
|
+
end
|
455
|
+
assert_raise KeyError do
|
456
|
+
awstags.fetch("tag4")
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_log_group_aws_tags_key_no_tags
|
461
|
+
clear_log_group
|
462
|
+
|
463
|
+
d = create_driver(<<-EOC)
|
464
|
+
#{default_config}
|
465
|
+
auto_create_stream true
|
466
|
+
log_group_name_key group_name_key
|
467
|
+
log_stream_name_key stream_name_key
|
468
|
+
remove_log_group_name_key true
|
469
|
+
remove_log_stream_name_key true
|
470
|
+
log_group_aws_tags_key aws_tags
|
471
|
+
EOC
|
472
|
+
|
473
|
+
stream = log_stream_name
|
474
|
+
records = [
|
475
|
+
{'cloudwatch' => 'logs1', 'message' => 'message1', 'group_name_key' => log_group_name, 'stream_name_key' => stream},
|
476
|
+
{'cloudwatch' => 'logs2', 'message' => 'message2', 'group_name_key' => log_group_name, 'stream_name_key' => stream}
|
477
|
+
]
|
478
|
+
|
479
|
+
time = Time.now
|
480
|
+
records.each_with_index do |record, i|
|
481
|
+
d.emit(record, time.to_i + i)
|
482
|
+
end
|
483
|
+
d.run
|
484
|
+
|
485
|
+
sleep 10
|
486
|
+
|
487
|
+
awstags = get_log_group_tags
|
488
|
+
|
489
|
+
assert_raise KeyError do
|
490
|
+
awstags.fetch("tag1")
|
491
|
+
end
|
492
|
+
|
493
|
+
events = get_log_events(log_group_name, stream)
|
494
|
+
assert_equal(2, events.size)
|
495
|
+
assert_equal(time.to_i * 1000, events[0].timestamp)
|
496
|
+
assert_equal({'cloudwatch' => 'logs1', 'message' => 'message1'}, JSON.parse(events[0].message))
|
497
|
+
assert_equal({'cloudwatch' => 'logs2', 'message' => 'message2'}, JSON.parse(events[1].message))
|
498
|
+
end
|
499
|
+
|
313
500
|
def test_retrying_on_throttling_exception
|
314
501
|
resp = mock()
|
315
502
|
resp.expects(:next_sequence_token)
|
@@ -323,10 +510,9 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
323
510
|
d.emit({'message' => 'message1'}, time.to_i)
|
324
511
|
d.run
|
325
512
|
|
326
|
-
assert_match(/
|
327
|
-
assert_match(/
|
328
|
-
assert_match(/
|
329
|
-
assert_match(/retry succeeded/, d.instance.log.logs[3])
|
513
|
+
assert_match(/failed to PutLogEvents/, d.instance.log.logs[0])
|
514
|
+
assert_match(/Called PutLogEvents/, d.instance.log.logs[1])
|
515
|
+
assert_match(/retry succeeded/, d.instance.log.logs[2])
|
330
516
|
end
|
331
517
|
|
332
518
|
def test_retrying_on_throttling_exception_and_throw_away
|
@@ -345,12 +531,9 @@ put_log_events_retry_limit 1
|
|
345
531
|
d.emit({'message' => 'message1'}, time.to_i)
|
346
532
|
d.run
|
347
533
|
|
348
|
-
assert_match(/
|
534
|
+
assert_match(/failed to PutLogEvents/, d.instance.log.logs[0])
|
349
535
|
assert_match(/failed to PutLogEvents/, d.instance.log.logs[1])
|
350
|
-
assert_match(/
|
351
|
-
assert_match(/failed to PutLogEvents/, d.instance.log.logs[3])
|
352
|
-
assert_match(/Calling PutLogEvents/, d.instance.log.logs[4])
|
353
|
-
assert_match(/failed to PutLogEvents and throwing away/, d.instance.log.logs[5])
|
536
|
+
assert_match(/failed to PutLogEvents and discard logs/, d.instance.log.logs[2])
|
354
537
|
end
|
355
538
|
|
356
539
|
def test_too_large_event
|
@@ -388,7 +571,7 @@ log_stream_name #{log_stream_name}
|
|
388
571
|
private
|
389
572
|
def default_config
|
390
573
|
<<-EOC
|
391
|
-
type cloudwatch_logs
|
574
|
+
@type cloudwatch_logs
|
392
575
|
auto_create_stream true
|
393
576
|
#{aws_key_id}
|
394
577
|
#{aws_sec_key}
|
data/test/test_helper.rb
CHANGED
@@ -43,6 +43,16 @@ module CloudwatchLogsTestHelper
|
|
43
43
|
@log_stream_name = log_stream_name_prefix ? log_stream_name_prefix + uuid : uuid
|
44
44
|
end
|
45
45
|
|
46
|
+
def get_log_group_tags(name = nil)
|
47
|
+
name ||= log_group_name
|
48
|
+
logs.list_tags_log_group(log_group_name: name).tags
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_log_group_retention_days(name = nil)
|
52
|
+
name ||= log_group_name
|
53
|
+
logs.describe_log_groups(log_group_name_prefix: name, limit: 1).log_groups.first.retention_in_days
|
54
|
+
end
|
55
|
+
|
46
56
|
def clear_log_group
|
47
57
|
[log_group_name, fluentd_tag].each do |name|
|
48
58
|
begin
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-cloudwatch-logs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|