fluent-plugin-cloudwatch-logs 0.9.4 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b2918da30191dd56e19d14043de953c649cb6207226df51a4721b8dda6af464
4
- data.tar.gz: a6a6def2e408711e723f6cec2f5fb706981f23479dd8cb9a3a1a674d859c1cbf
3
+ metadata.gz: 13ef3e0d5f4fd4c12c49b16ccbd07db237b7cff26ea272e4ef6337b09b02e975
4
+ data.tar.gz: 8cefeed014b1842ccce9f15479ad8cc54aa51b976281abb5d3e1c8828239aaa3
5
5
  SHA512:
6
- metadata.gz: 3aa61613b097ff349ba56fd9a5b7e0ee4f87ed3fa23bfa816c35decc193d1161a1771b6985c745f751cc0d05e8e0be606326e145ec19a509f1d2ebd2698f7d71
7
- data.tar.gz: ffca6e46ee0c87dc22cd60c4cd724bdf22421daaff0338f245436edce33a8f0397f3f08daa4dd0f929cfabb6d73a2718feff15d304b5e79ca6762c0808aebd93
6
+ metadata.gz: 41ca6fa20d0c26955fcbab7f7a5a9fb8c032a5fd09f8676ccaaf5e4dd12694ea74c7c5320590f076405c691d436bc87b820e6bc9b75dc516062b2f3e09d8a377
7
+ data.tar.gz: 1f5bbd694c5962de73ee1e0ca622d8892437fb82d00b76ed87086feeba49f6d2c3a4904edad81bec88ba2d3ca47701c15cb56395470f19742c16b3168dd870e5
@@ -2,7 +2,7 @@ module Fluent
2
2
  module Plugin
3
3
  module Cloudwatch
4
4
  module Logs
5
- VERSION = "0.9.4"
5
+ VERSION = "0.9.5"
6
6
  end
7
7
  end
8
8
  end
@@ -170,49 +170,57 @@ module Fluent::Plugin
170
170
  end
171
171
 
172
172
  def get_events(log_stream_name)
173
- request = {
174
- log_group_name: @log_group_name,
175
- log_stream_name: log_stream_name
176
- }
177
- request.merge!(start_time: @start_time) if @start_time
178
- request.merge!(end_time: @end_time) if @end_time
179
- log_next_token = next_token(log_stream_name)
180
- request[:next_token] = log_next_token if !log_next_token.nil? && !log_next_token.empty?
181
- response = @logs.get_log_events(request)
182
- if valid_next_token(log_next_token, response.next_forward_token)
183
- store_next_token(response.next_forward_token, log_stream_name)
173
+ throttling_handler('get_log_events') do
174
+ request = {
175
+ log_group_name: @log_group_name,
176
+ log_stream_name: log_stream_name
177
+ }
178
+ request.merge!(start_time: @start_time) if @start_time
179
+ request.merge!(end_time: @end_time) if @end_time
180
+ log_next_token = next_token(log_stream_name)
181
+ request[:next_token] = log_next_token if !log_next_token.nil? && !log_next_token.empty?
182
+ response = @logs.get_log_events(request)
183
+ if valid_next_token(log_next_token, response.next_forward_token)
184
+ store_next_token(response.next_forward_token, log_stream_name)
185
+ end
186
+
187
+ response.events
184
188
  end
189
+ end
185
190
 
186
- response.events
191
+ def describe_log_streams(log_stream_name_prefix, log_streams = nil, next_token = nil)
192
+ throttling_handler('describe_log_streams') do
193
+ request = {
194
+ log_group_name: @log_group_name
195
+ }
196
+ request[:next_token] = next_token if next_token
197
+ request[:log_stream_name_prefix] = log_stream_name_prefix if log_stream_name_prefix
198
+ response = @logs.describe_log_streams(request)
199
+ if log_streams
200
+ log_streams.concat(response.log_streams)
201
+ else
202
+ log_streams = response.log_streams
203
+ end
204
+ if response.next_token
205
+ log_streams = describe_log_streams(log_stream_name_prefix, log_streams, response.next_token)
206
+ end
207
+ log_streams
208
+ end
209
+ end
210
+
211
+ def throttling_handler(method_name)
212
+ yield
187
213
  rescue Aws::CloudWatchLogs::Errors::ThrottlingException => err
188
214
  if throttling_retry_seconds
189
- log.warn "ThrottlingException in get_log_events (#{log_stream_name}). Waiting #{throttling_retry_seconds} seconds to retry."
215
+ log.warn "ThrottlingException #{method_name}. Waiting #{throttling_retry_seconds} seconds to retry."
190
216
  sleep throttling_retry_seconds
191
217
 
192
- get_events(log_stream_name)
218
+ throttling_handler(method_name) { yield }
193
219
  else
194
220
  raise err
195
221
  end
196
222
  end
197
223
 
198
- def describe_log_streams(log_stream_name_prefix, log_streams = nil, next_token = nil)
199
- request = {
200
- log_group_name: @log_group_name
201
- }
202
- request[:next_token] = next_token if next_token
203
- request[:log_stream_name_prefix] = log_stream_name_prefix if log_stream_name_prefix
204
- response = @logs.describe_log_streams(request)
205
- if log_streams
206
- log_streams.concat(response.log_streams)
207
- else
208
- log_streams = response.log_streams
209
- end
210
- if response.next_token
211
- log_streams = describe_log_streams(log_stream_name_prefix, log_streams, response.next_token)
212
- end
213
- log_streams
214
- end
215
-
216
224
  def valid_next_token(prev_token, next_token)
217
225
  next_token && prev_token != next_token.chomp
218
226
  end
@@ -611,7 +611,7 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
611
611
  assert_equal(["test", ((time_ms + 8000) / 1000), { "cloudwatch" => "logs8" }], events[7])
612
612
  end
613
613
 
614
- test "retry on Aws::CloudWatchLogs::Errors::ThrottlingException" do
614
+ test "retry on Aws::CloudWatchLogs::Errors::ThrottlingException in get_log_events" do
615
615
  config = <<-CONFIG
616
616
  tag test
617
617
  @type cloudwatch_logs
@@ -634,11 +634,34 @@ class CloudwatchLogsInputTest < Test::Unit::TestCase
634
634
  # so, it is expected to valid_next_token once
635
635
  mock(d.instance).valid_next_token(nil, nil).once
636
636
 
637
+ d.run
638
+ assert_equal(2, d.logs.select {|l| l =~ /ThrottlingException get_log_events. Waiting 0.2 seconds to retry/ }.size)
639
+ end
640
+
641
+ test "retry on Aws::CloudWatchLogs::Errors::ThrottlingException in describe_log_streams" do
642
+ config = <<-CONFIG
643
+ tag test
644
+ @type cloudwatch_logs
645
+ log_group_name #{log_group_name}
646
+ use_log_stream_name_prefix true
647
+ state_file /tmp/state
648
+ fetch_interval 0.1
649
+ throttling_retry_seconds 0.2
650
+ CONFIG
651
+
652
+ # it will raises the error 2 times
637
653
  log_stream = Aws::CloudWatchLogs::Types::LogStream.new(log_stream_name: "stream_name")
638
- @client.stub_responses(:describe_log_streams, { log_streams: [log_stream], next_token: nil })
654
+ counter = 0
655
+ times = 2
656
+ stub(@client).describe_log_streams(anything) {
657
+ counter += 1
658
+ counter <= times ? raise(Aws::CloudWatchLogs::Errors::ThrottlingException.new(nil, "error")) : OpenStruct.new(log_streams: [log_stream], next_token: nil)
659
+ }
660
+
661
+ d = create_driver(config)
639
662
 
640
663
  d.run
641
- assert_equal(2, d.logs.select {|l| l =~ /Waiting 0.2 seconds to retry/ }.size)
664
+ assert_equal(2, d.logs.select {|l| l =~ /ThrottlingException describe_log_streams. Waiting 0.2 seconds to retry/ }.size)
642
665
  end
643
666
  end
644
667
 
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.9.4
4
+ version: 0.9.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: 2020-04-22 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd