fluent-plugin-cloudwatch-logs 0.4.5 → 0.5.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/fluent-plugin-cloudwatch-logs.gemspec +1 -2
- data/lib/fluent/plugin/cloudwatch/logs/version.rb +1 -1
- data/lib/fluent/plugin/in_cloudwatch_logs.rb +17 -22
- data/lib/fluent/plugin/out_cloudwatch_logs.rb +22 -17
- data/test/plugin/test_in_cloudwatch_logs.rb +11 -13
- data/test/plugin/test_out_cloudwatch_logs.rb +100 -68
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0293939c5f3f3a26433414ba6f8f0e24e2919ffcdde9d0089c36ea812c74fa75'
|
4
|
+
data.tar.gz: d2f8ccb99658afd56dd08819f4849bcb9925f590b928cd009aac380cdf130163
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aaef277138417fc14f8b979c05a500b86c3cce4f887993ac1079078021b6c42ccc4e77c058b3b680f23dcfba80995742513620c164b9c89a0c5050cdb4e7bc4
|
7
|
+
data.tar.gz: 542aa4b296c089500eda35ea2af8f79f71a0a35f1573bbb06c1e5ae3d2ef578a1c0506142acfc6c992e51cf546ce70f17d623941d8ab283a0452808af5cf9e01
|
data/Gemfile
CHANGED
@@ -17,9 +17,8 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency 'fluentd'
|
20
|
+
spec.add_dependency 'fluentd', '>= 0.14.15'
|
21
21
|
spec.add_dependency 'aws-sdk-cloudwatchlogs', '~> 1.0'
|
22
|
-
spec.add_dependency 'fluent-mixin-config-placeholders', '>= 0.2.0'
|
23
22
|
|
24
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
25
24
|
spec.add_development_dependency "rake"
|
@@ -1,18 +1,11 @@
|
|
1
|
-
require 'fluent/input'
|
2
|
-
require 'fluent/parser'
|
3
|
-
|
4
|
-
module Fluent
|
5
|
-
require 'fluent/mixin/config_placeholders'
|
1
|
+
require 'fluent/plugin/input'
|
2
|
+
require 'fluent/plugin/parser'
|
6
3
|
|
4
|
+
module Fluent::Plugin
|
7
5
|
class CloudwatchLogsInput < Input
|
8
|
-
Plugin.register_input('cloudwatch_logs', self)
|
9
|
-
|
10
|
-
include Fluent::Mixin::ConfigPlaceholders
|
6
|
+
Fluent::Plugin.register_input('cloudwatch_logs', self)
|
11
7
|
|
12
|
-
|
13
|
-
unless method_defined?(:router)
|
14
|
-
define_method("router") { Engine }
|
15
|
-
end
|
8
|
+
helpers :parser, :thread, :compat_parameters
|
16
9
|
|
17
10
|
config_param :aws_key_id, :string, :default => nil, :secret => true
|
18
11
|
config_param :aws_sec_key, :string, :default => nil, :secret => true
|
@@ -28,22 +21,24 @@ module Fluent
|
|
28
21
|
config_param :fetch_interval, :time, default: 60
|
29
22
|
config_param :http_proxy, :string, default: nil
|
30
23
|
|
24
|
+
config_section :parse do
|
25
|
+
config_set_default :@type, 'none'
|
26
|
+
end
|
27
|
+
|
31
28
|
def initialize
|
32
29
|
super
|
33
30
|
|
34
31
|
require 'aws-sdk-cloudwatchlogs'
|
35
32
|
end
|
36
33
|
|
37
|
-
def placeholders
|
38
|
-
[:percent]
|
39
|
-
end
|
40
|
-
|
41
34
|
def configure(conf)
|
35
|
+
compat_parameters_convert(conf, :parser)
|
42
36
|
super
|
43
37
|
configure_parser(conf)
|
44
38
|
end
|
45
39
|
|
46
40
|
def start
|
41
|
+
super
|
47
42
|
options = {}
|
48
43
|
options[:region] = @region if @region
|
49
44
|
options[:http_proxy] = @http_proxy if @http_proxy
|
@@ -61,19 +56,18 @@ module Fluent
|
|
61
56
|
@logs = Aws::CloudWatchLogs::Client.new(options)
|
62
57
|
|
63
58
|
@finished = false
|
64
|
-
|
59
|
+
thread_create(:in_cloudwatch_logs_runner, &method(:run))
|
65
60
|
end
|
66
61
|
|
67
62
|
def shutdown
|
68
63
|
@finished = true
|
69
|
-
|
64
|
+
super
|
70
65
|
end
|
71
66
|
|
72
67
|
private
|
73
68
|
def configure_parser(conf)
|
74
69
|
if conf['format']
|
75
|
-
@parser =
|
76
|
-
@parser.configure(conf)
|
70
|
+
@parser = parser_create
|
77
71
|
end
|
78
72
|
end
|
79
73
|
|
@@ -122,8 +116,9 @@ module Fluent
|
|
122
116
|
|
123
117
|
def emit(stream, event)
|
124
118
|
if @parser
|
125
|
-
|
126
|
-
|
119
|
+
@parser.parse(event.message) {|time, record|
|
120
|
+
router.emit(@tag, time, record)
|
121
|
+
}
|
127
122
|
else
|
128
123
|
time = (event.timestamp / 1000).floor
|
129
124
|
record = JSON.parse(event.message)
|
@@ -1,14 +1,13 @@
|
|
1
|
-
require 'fluent/output'
|
1
|
+
require 'fluent/plugin/output'
|
2
2
|
require 'thread'
|
3
3
|
|
4
|
-
module Fluent
|
5
|
-
|
4
|
+
module Fluent::Plugin
|
5
|
+
class CloudwatchLogsOutput < Output
|
6
|
+
Fluent::Plugin.register_output('cloudwatch_logs', self)
|
6
7
|
|
7
|
-
|
8
|
-
Plugin.register_output('cloudwatch_logs', self)
|
8
|
+
helpers :compat_parameters, :inject
|
9
9
|
|
10
|
-
|
11
|
-
include Fluent::Mixin::ConfigPlaceholders
|
10
|
+
DEFAULT_BUFFER_TYPE = "memory"
|
12
11
|
|
13
12
|
config_param :aws_key_id, :string, :default => nil, :secret => true
|
14
13
|
config_param :aws_sec_key, :string, :default => nil, :secret => true
|
@@ -40,33 +39,30 @@ module Fluent
|
|
40
39
|
config_param :retention_in_days_key, :string, default: nil
|
41
40
|
config_param :remove_retention_in_days, :bool, default: false
|
42
41
|
|
42
|
+
config_section :buffer do
|
43
|
+
config_set_default :@type, DEFAULT_BUFFER_TYPE
|
44
|
+
end
|
45
|
+
|
43
46
|
MAX_EVENTS_SIZE = 1_048_576
|
44
47
|
MAX_EVENT_SIZE = 256 * 1024
|
45
48
|
EVENT_HEADER_SIZE = 26
|
46
49
|
|
47
|
-
unless method_defined?(:log)
|
48
|
-
define_method(:log) { $log }
|
49
|
-
end
|
50
|
-
|
51
50
|
def initialize
|
52
51
|
super
|
53
52
|
|
54
53
|
require 'aws-sdk-cloudwatchlogs'
|
55
54
|
end
|
56
55
|
|
57
|
-
def placeholders
|
58
|
-
[:percent]
|
59
|
-
end
|
60
|
-
|
61
56
|
def configure(conf)
|
57
|
+
compat_parameters_convert(conf, :buffer, :inject)
|
62
58
|
super
|
63
59
|
|
64
60
|
unless [conf['log_group_name'], conf['use_tag_as_group'], conf['log_group_name_key']].compact.size == 1
|
65
|
-
raise ConfigError, "Set only one of log_group_name, use_tag_as_group and log_group_name_key"
|
61
|
+
raise Fluent::ConfigError, "Set only one of log_group_name, use_tag_as_group and log_group_name_key"
|
66
62
|
end
|
67
63
|
|
68
64
|
unless [conf['log_stream_name'], conf['use_tag_as_stream'], conf['log_stream_name_key']].compact.size == 1
|
69
|
-
raise ConfigError, "Set only one of log_stream_name, use_tag_as_stream and log_stream_name_key"
|
65
|
+
raise Fluent::ConfigError, "Set only one of log_stream_name, use_tag_as_stream and log_stream_name_key"
|
70
66
|
end
|
71
67
|
|
72
68
|
if [conf['log_group_aws_tags'], conf['log_group_aws_tags_key']].compact.size > 1
|
@@ -100,9 +96,18 @@ module Fluent
|
|
100
96
|
end
|
101
97
|
|
102
98
|
def format(tag, time, record)
|
99
|
+
record = inject_values_to_record(tag, time, record)
|
103
100
|
[tag, time, record].to_msgpack
|
104
101
|
end
|
105
102
|
|
103
|
+
def formatted_to_msgpack_binary?
|
104
|
+
true
|
105
|
+
end
|
106
|
+
|
107
|
+
def multi_workers_ready?
|
108
|
+
true
|
109
|
+
end
|
110
|
+
|
106
111
|
def write(chunk)
|
107
112
|
queue = Thread::Queue.new
|
108
113
|
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'fluent/test/driver/input'
|
3
|
+
require 'fluent/test/helpers'
|
2
4
|
|
3
5
|
class CloudwatchLogsInputTest < Test::Unit::TestCase
|
4
6
|
include CloudwatchLogsTestHelper
|
7
|
+
include Fluent::Test::Helpers
|
5
8
|
|
6
9
|
def setup
|
7
10
|
Fluent::Test.setup
|
@@ -48,11 +51,9 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
48
51
|
sleep 5
|
49
52
|
|
50
53
|
d = create_driver
|
51
|
-
d.run
|
52
|
-
sleep 5
|
53
|
-
end
|
54
|
+
d.run(expect_emits: 2, timeout: 5)
|
54
55
|
|
55
|
-
emits = d.
|
56
|
+
emits = d.events
|
56
57
|
assert_equal(2, emits.size)
|
57
58
|
assert_equal(['test', (time_ms / 1000).floor, {'cloudwatch' => 'logs1'}], emits[0])
|
58
59
|
assert_equal(['test', (time_ms / 1000).floor, {'cloudwatch' => 'logs2'}], emits[1])
|
@@ -81,11 +82,9 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
81
82
|
#{region}
|
82
83
|
EOC
|
83
84
|
|
84
|
-
d.run
|
85
|
-
sleep 5
|
86
|
-
end
|
85
|
+
d.run(expect_emits: 2, timeout: 5)
|
87
86
|
|
88
|
-
emits = d.
|
87
|
+
emits = d.events
|
89
88
|
assert_equal(2, emits.size)
|
90
89
|
assert_equal('test', emits[0][0])
|
91
90
|
assert_in_delta((time_ms / 1000).floor, emits[0][1], 10)
|
@@ -125,11 +124,9 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
125
124
|
#{aws_sec_key}
|
126
125
|
#{region}
|
127
126
|
EOC
|
128
|
-
d.run
|
129
|
-
sleep 5
|
130
|
-
end
|
127
|
+
d.run(expect_emits: 4, timeout: 5)
|
131
128
|
|
132
|
-
emits = d.
|
129
|
+
emits = d.events
|
133
130
|
assert_equal(4, emits.size)
|
134
131
|
assert_equal(['test', (time_ms / 1000).floor, {'cloudwatch' => 'logs1'}], emits[0])
|
135
132
|
assert_equal(['test', (time_ms / 1000).floor, {'cloudwatch' => 'logs2'}], emits[1])
|
@@ -145,6 +142,7 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
145
142
|
log_group_name #{log_group_name}
|
146
143
|
log_stream_name #{log_stream_name}
|
147
144
|
state_file /tmp/state
|
145
|
+
fetch_interval 1
|
148
146
|
#{aws_key_id}
|
149
147
|
#{aws_sec_key}
|
150
148
|
#{region}
|
@@ -152,6 +150,6 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
|
|
152
150
|
end
|
153
151
|
|
154
152
|
def create_driver(conf = default_config)
|
155
|
-
Fluent::Test::
|
153
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::CloudwatchLogsInput).configure(conf)
|
156
154
|
end
|
157
155
|
end
|
@@ -1,13 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require 'test_helper'
|
2
3
|
require 'fileutils'
|
4
|
+
require 'fluent/test/driver/output'
|
5
|
+
require 'fluent/test/helpers'
|
3
6
|
|
4
7
|
class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
5
8
|
include CloudwatchLogsTestHelper
|
9
|
+
include Fluent::Test::Helpers
|
6
10
|
|
7
11
|
def setup
|
8
12
|
Fluent::Test.setup
|
9
13
|
require 'fluent/plugin/out_cloudwatch_logs'
|
10
|
-
|
11
14
|
end
|
12
15
|
|
13
16
|
def teardown
|
@@ -43,13 +46,15 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
43
46
|
new_log_stream
|
44
47
|
|
45
48
|
d = create_driver
|
46
|
-
time =
|
47
|
-
d.
|
48
|
-
|
49
|
-
|
49
|
+
time = event_time
|
50
|
+
d.run(default_tag: fluentd_tag, flush: true) do
|
51
|
+
d.feed(time, {'cloudwatch' => 'logs1'})
|
52
|
+
d.feed(time + 1, {'cloudwatch' => 'logs2'})
|
53
|
+
end
|
50
54
|
|
51
55
|
sleep 10
|
52
56
|
|
57
|
+
logs = d.logs
|
53
58
|
events = get_log_events
|
54
59
|
assert_equal(2, events.size)
|
55
60
|
assert_equal(time.to_i * 1000, events[0].timestamp)
|
@@ -57,16 +62,17 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
57
62
|
assert_equal((time.to_i + 1) * 1000, events[1].timestamp)
|
58
63
|
assert_equal('{"cloudwatch":"logs2"}', events[1].message)
|
59
64
|
|
60
|
-
|
65
|
+
assert(logs.any?{|log| log.include?("Calling PutLogEvents API") })
|
61
66
|
end
|
62
67
|
|
63
68
|
def test_write_utf8
|
64
69
|
new_log_stream
|
65
70
|
|
66
71
|
d = create_driver
|
67
|
-
time =
|
68
|
-
d.
|
69
|
-
|
72
|
+
time = event_time
|
73
|
+
d.run(default_tag: fluentd_tag) do
|
74
|
+
d.feed(time, { 'cloudwatch' => 'これは日本語です'.force_encoding('UTF-8')})
|
75
|
+
end
|
70
76
|
|
71
77
|
sleep 10
|
72
78
|
|
@@ -79,12 +85,18 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
79
85
|
def test_write_24h_apart
|
80
86
|
new_log_stream
|
81
87
|
|
82
|
-
d = create_driver
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
+
d = create_driver(<<-EOC)
|
89
|
+
#{default_config}
|
90
|
+
log_group_name #{log_group_name}
|
91
|
+
log_stream_name #{log_stream_name}
|
92
|
+
utc
|
93
|
+
EOC
|
94
|
+
time = event_time
|
95
|
+
d.run(default_tag: fluentd_tag) do
|
96
|
+
d.feed(time - 60 * 60 * 25, {'cloudwatch' => 'logs0'})
|
97
|
+
d.feed(time, {'cloudwatch' => 'logs1'})
|
98
|
+
d.feed(time + 1, {'cloudwatch' => 'logs2'})
|
99
|
+
end
|
88
100
|
|
89
101
|
sleep 10
|
90
102
|
|
@@ -108,10 +120,11 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
108
120
|
log_stream_name #{log_stream_name}
|
109
121
|
EOC
|
110
122
|
|
111
|
-
time =
|
112
|
-
d.
|
113
|
-
|
114
|
-
|
123
|
+
time = event_time
|
124
|
+
d.run(default_tag: fluentd_tag) do
|
125
|
+
d.feed(time, {'cloudwatch' => 'logs1', 'message' => 'message1'})
|
126
|
+
d.feed(time + 1, {'cloudwatch' => 'logs2', 'message' => 'message2'})
|
127
|
+
end
|
115
128
|
|
116
129
|
sleep 10
|
117
130
|
|
@@ -134,10 +147,11 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
134
147
|
log_stream_name #{log_stream_name}
|
135
148
|
EOC
|
136
149
|
|
137
|
-
time =
|
138
|
-
d.
|
139
|
-
|
140
|
-
|
150
|
+
time = event_time
|
151
|
+
d.run(default_tag: fluentd_tag) do
|
152
|
+
d.feed(time, {'cloudwatch' => 'logs1', 'message' => 'message1'})
|
153
|
+
d.feed(time + 1, {'cloudwatch' => 'logs2', 'message' => 'message2'})
|
154
|
+
end
|
141
155
|
|
142
156
|
sleep 10
|
143
157
|
|
@@ -159,10 +173,11 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
159
173
|
log_stream_name #{log_stream_name}
|
160
174
|
EOC
|
161
175
|
|
162
|
-
time =
|
163
|
-
d.
|
164
|
-
|
165
|
-
|
176
|
+
time = event_time
|
177
|
+
d.run(default_tag: fluentd_tag) do
|
178
|
+
d.feed(time, {'cloudwatch' => 'logs1', 'message' => 'message1'})
|
179
|
+
d.feed(time + 1, {'cloudwatch' => 'logs2', 'message' => 'message2'})
|
180
|
+
end
|
166
181
|
|
167
182
|
sleep 10
|
168
183
|
|
@@ -184,10 +199,11 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
184
199
|
log_group_name #{log_group_name}
|
185
200
|
EOC
|
186
201
|
|
187
|
-
time =
|
188
|
-
d.
|
189
|
-
|
190
|
-
|
202
|
+
time = event_time
|
203
|
+
d.run(default_tag: fluentd_tag) do
|
204
|
+
d.feed(time, {'cloudwatch' => 'logs1', 'message' => 'message1'})
|
205
|
+
d.feed(time + 1, {'cloudwatch' => 'logs2', 'message' => 'message2'})
|
206
|
+
end
|
191
207
|
|
192
208
|
sleep 10
|
193
209
|
|
@@ -207,21 +223,23 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
207
223
|
include_time_key true
|
208
224
|
log_group_name #{log_group_name}
|
209
225
|
log_stream_name #{log_stream_name}
|
226
|
+
utc
|
210
227
|
EOC
|
211
228
|
|
212
|
-
time =
|
213
|
-
d.
|
214
|
-
|
215
|
-
|
229
|
+
time = event_time
|
230
|
+
d.run(default_tag: fluentd_tag) do
|
231
|
+
d.feed(time, {'cloudwatch' => 'logs1'})
|
232
|
+
d.feed(time + 1, {'cloudwatch' => 'logs2'})
|
233
|
+
end
|
216
234
|
|
217
235
|
sleep 10
|
218
236
|
|
219
237
|
events = get_log_events
|
220
238
|
assert_equal(2, events.size)
|
221
239
|
assert_equal(time.to_i * 1000, events[0].timestamp)
|
222
|
-
assert_equal("{\"cloudwatch\":\"logs1\",\"time\":\"#{time.utc.strftime("%Y-%m-%dT%H:%M:%SZ")}\"}", events[0].message)
|
240
|
+
assert_equal("{\"cloudwatch\":\"logs1\",\"time\":\"#{Time.at(time.to_r).utc.strftime("%Y-%m-%dT%H:%M:%SZ")}\"}", events[0].message)
|
223
241
|
assert_equal((time.to_i + 1) * 1000, events[1].timestamp)
|
224
|
-
assert_equal("{\"cloudwatch\":\"logs2\",\"time\":\"#{(time+1).utc.strftime("%Y-%m-%dT%H:%M:%SZ")}\"}", events[1].message)
|
242
|
+
assert_equal("{\"cloudwatch\":\"logs2\",\"time\":\"#{Time.at((time+1).to_r).utc.strftime("%Y-%m-%dT%H:%M:%SZ")}\"}", events[1].message)
|
225
243
|
end
|
226
244
|
|
227
245
|
def test_include_time_key_localtime
|
@@ -235,19 +253,20 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
235
253
|
log_stream_name #{log_stream_name}
|
236
254
|
EOC
|
237
255
|
|
238
|
-
time =
|
239
|
-
d.
|
240
|
-
|
241
|
-
|
256
|
+
time = event_time
|
257
|
+
d.run(default_tag: fluentd_tag) do
|
258
|
+
d.feed(time, {'cloudwatch' => 'logs1'})
|
259
|
+
d.feed(time + 1, {'cloudwatch' => 'logs2'})
|
260
|
+
end
|
242
261
|
|
243
262
|
sleep 10
|
244
263
|
|
245
264
|
events = get_log_events
|
246
265
|
assert_equal(2, events.size)
|
247
266
|
assert_equal(time.to_i * 1000, events[0].timestamp)
|
248
|
-
assert_equal("{\"cloudwatch\":\"logs1\",\"time\":\"#{time.strftime("%Y-%m-%dT%H:%M:%S%:z")}\"}", events[0].message)
|
267
|
+
assert_equal("{\"cloudwatch\":\"logs1\",\"time\":\"#{Time.at(time.to_r).strftime("%Y-%m-%dT%H:%M:%S%:z")}\"}", events[0].message)
|
249
268
|
assert_equal((time.to_i + 1) * 1000, events[1].timestamp)
|
250
|
-
assert_equal("{\"cloudwatch\":\"logs2\",\"time\":\"#{(time+1).strftime("%Y-%m-%dT%H:%M:%S%:z")}\"}", events[1].message)
|
269
|
+
assert_equal("{\"cloudwatch\":\"logs2\",\"time\":\"#{Time.at((time+1).to_r).to_time.strftime("%Y-%m-%dT%H:%M:%S%:z")}\"}", events[1].message)
|
251
270
|
end
|
252
271
|
|
253
272
|
def test_log_group_name_key_and_log_stream_name_key
|
@@ -257,6 +276,7 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
257
276
|
#{default_config}
|
258
277
|
log_group_name_key group_name_key
|
259
278
|
log_stream_name_key stream_name_key
|
279
|
+
@log_level debug
|
260
280
|
EOC
|
261
281
|
|
262
282
|
stream1 = new_log_stream
|
@@ -268,14 +288,16 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
268
288
|
{'cloudwatch' => 'logs3', 'message' => 'message1', 'group_name_key' => log_group_name, 'stream_name_key' => stream1},
|
269
289
|
]
|
270
290
|
|
271
|
-
time =
|
272
|
-
|
273
|
-
|
291
|
+
time = event_time
|
292
|
+
d.run(default_tag: fluentd_tag) do
|
293
|
+
records.each_with_index do |record, i|
|
294
|
+
d.feed(time + i, record)
|
295
|
+
end
|
274
296
|
end
|
275
|
-
d.run
|
276
297
|
|
298
|
+
logs = d.logs
|
277
299
|
# Call API once for each stream
|
278
|
-
assert_equal(2,
|
300
|
+
assert_equal(2, logs.select {|l| l =~ /Calling PutLogEvents API/ }.size)
|
279
301
|
|
280
302
|
sleep 10
|
281
303
|
|
@@ -303,9 +325,10 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
303
325
|
remove_log_stream_name_key true
|
304
326
|
EOC
|
305
327
|
|
306
|
-
time =
|
307
|
-
d.
|
308
|
-
|
328
|
+
time = event_time
|
329
|
+
d.run(default_tag: fluentd_tag) do
|
330
|
+
d.feed(time, {'cloudwatch' => 'logs1', 'message' => 'message1', 'group_name_key' => log_group_name, 'stream_name_key' => log_stream_name})
|
331
|
+
end
|
309
332
|
|
310
333
|
sleep 10
|
311
334
|
|
@@ -504,15 +527,17 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
504
527
|
client.stubs(:put_log_events).
|
505
528
|
raises(Aws::CloudWatchLogs::Errors::ThrottlingException.new(nil, "error")).then.returns(resp)
|
506
529
|
|
507
|
-
time = Time.now
|
508
530
|
d = create_driver
|
531
|
+
time = event_time
|
509
532
|
d.instance.instance_variable_set(:@logs, client)
|
510
|
-
d.
|
511
|
-
|
533
|
+
d.run(default_tag: fluentd_tag) do
|
534
|
+
d.feed(time, {'message' => 'message1'})
|
535
|
+
end
|
512
536
|
|
513
|
-
|
514
|
-
|
515
|
-
|
537
|
+
logs = d.logs
|
538
|
+
assert_equal(2, logs.select {|l| l =~ /Calling PutLogEvents API/ }.size)
|
539
|
+
assert_equal(1, logs.select {|l| l =~ /failed to PutLogEvents/ }.size)
|
540
|
+
assert_equal(1, logs.select {|l| l =~ /retry succeeded/ }.size)
|
516
541
|
end
|
517
542
|
|
518
543
|
def test_retrying_on_throttling_exception_and_throw_away
|
@@ -520,33 +545,39 @@ class CloudwatchLogsOutputTest < Test::Unit::TestCase
|
|
520
545
|
client.stubs(:put_log_events).
|
521
546
|
raises(Aws::CloudWatchLogs::Errors::ThrottlingException.new(nil, "error"))
|
522
547
|
|
523
|
-
time =
|
548
|
+
time = Fluent::Engine.now
|
524
549
|
d = create_driver(<<-EOC)
|
525
550
|
#{default_config}
|
526
551
|
log_group_name #{log_group_name}
|
527
552
|
log_stream_name #{log_stream_name}
|
528
553
|
put_log_events_retry_limit 1
|
554
|
+
@log_level debug
|
529
555
|
EOC
|
530
556
|
d.instance.instance_variable_set(:@logs, client)
|
531
|
-
d.
|
532
|
-
|
557
|
+
d.run(default_tag: fluentd_tag) do
|
558
|
+
d.feed(time, {'message' => 'message1'})
|
559
|
+
end
|
533
560
|
|
534
|
-
|
535
|
-
|
536
|
-
|
561
|
+
logs = d.logs
|
562
|
+
assert_equal(3, logs.select {|l| l =~ /Calling PutLogEvents API/ }.size)
|
563
|
+
assert_equal(3, logs.select {|l| l =~ /failed to PutLogEvents/ }.size)
|
564
|
+
assert_equal(1, logs.select {|l| l =~ /failed to PutLogEvents and discard logs/ }.size)
|
537
565
|
end
|
538
566
|
|
539
567
|
def test_too_large_event
|
540
|
-
time =
|
568
|
+
time = Fluent::Engine.now
|
541
569
|
d = create_driver(<<-EOC)
|
542
570
|
#{default_config}
|
543
571
|
log_group_name #{log_group_name}
|
544
572
|
log_stream_name #{log_stream_name}
|
573
|
+
@log_level debug
|
545
574
|
EOC
|
546
|
-
d.
|
547
|
-
|
575
|
+
d.run(default_tag: fluentd_tag) do
|
576
|
+
d.feed(time, {'message' => '*' * 256 * 1024})
|
577
|
+
end
|
548
578
|
|
549
|
-
|
579
|
+
logs = d.logs
|
580
|
+
assert(logs.any?{|log| log.include?("Log event is discarded because it is too large: 262184 bytes exceeds limit of 262144")})
|
550
581
|
end
|
551
582
|
|
552
583
|
def test_scrub_record
|
@@ -585,8 +616,9 @@ auto_create_stream true
|
|
585
616
|
#{default_config}
|
586
617
|
log_group_name #{log_group_name}
|
587
618
|
log_stream_name #{log_stream_name}
|
619
|
+
@log_level debug
|
588
620
|
EOC
|
589
621
|
end
|
590
|
-
Fluent::Test::
|
622
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::CloudwatchLogsOutput).configure(conf)
|
591
623
|
end
|
592
624
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-cloudwatch-logs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.14.15
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.14.15
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: aws-sdk-cloudwatchlogs
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: fluent-mixin-config-placeholders
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.2.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.2.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,9 +130,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
130
|
version: '0'
|
145
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
132
|
requirements:
|
147
|
-
- - "
|
133
|
+
- - ">"
|
148
134
|
- !ruby/object:Gem::Version
|
149
|
-
version:
|
135
|
+
version: 1.3.1
|
150
136
|
requirements: []
|
151
137
|
rubyforge_project:
|
152
138
|
rubygems_version: 2.7.3
|