cloud_watch_logs_poller 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc88f8d5963c66a36bc794f6f7a101d080342aba5d7a2577d956b39417a93e76
4
- data.tar.gz: 9d4f3209935a3b0ceab85ab8e5842681c3804e7c8d0d99f528e5f1064c30331e
3
+ metadata.gz: 4641f0ec6db0d868154a40d3ac82a525c00d57ad3b51297a2078341397455a85
4
+ data.tar.gz: 486c7f3b586fbca8b079231df5f8bf979c5112aab5d04110a1ad983adee87570
5
5
  SHA512:
6
- metadata.gz: ae1401221a8a7e900ae59fbc14b744a06184e2f58a03300d8114850c7f8d2dfcdac67b0256ef82acca352302d0fc647f28b488a0956903791a78fcd9a1b30497
7
- data.tar.gz: e50f5a485af34912b8225f57177efa6cb5507337f81477a2be6d5ad937ba70f5597adf56b845a974daff8a72068884bc7444ede716bdb6e69dd953e4d49cca7c
6
+ metadata.gz: 35d9d853b1ee7192cca26901b1f4ae8a72a21652c3935b090f7a98dc757f5abcd7903a65bdf480c5654c5c7596db7520331289383a2a2c92a7bab0840193a989
7
+ data.tar.gz: f146bb5eb28ce03faf8198ceed4df78db65ea57e8d716d0096dc19b09b3c325c1405482fa91c5eaad5a8d319dfb209acc18e6fff787b5d88b93ba67c0b8e7332
@@ -4,7 +4,7 @@ module CloudWatchLogsPoller
4
4
  @client = Aws::CloudWatchLogs::Client.new
5
5
  @interval = interval
6
6
  @debug = debug
7
- @event_ids = []
7
+ @event_ids_by_timestamp = {}
8
8
  end
9
9
 
10
10
  def execute(log_group_name:, log_stream_name_prefix: nil, filter_pattern: nil, start_time: Time.now, &block)
@@ -16,24 +16,37 @@ module CloudWatchLogsPoller
16
16
  interleaved: true
17
17
  }
18
18
 
19
+ debug_log("start_time = #{params[:start_time]}")
20
+
19
21
  loop do
20
22
  loop do
21
23
  result = @client.filter_log_events(params)
22
24
  result.events.each do |event|
23
- next if @event_ids.include?(event.event_id)
25
+ timestamp = event.timestamp&.to_i
26
+ event_id = event.event_id
27
+
28
+ debug_log("timestamp = #{timestamp}")
24
29
 
25
- @event_ids << event.event_id
30
+ @event_ids_by_timestamp[timestamp] ||= Set.new
31
+ next if @event_ids_by_timestamp[timestamp].include?(event_id)
32
+
33
+ @event_ids_by_timestamp[timestamp] << event_id
26
34
  block.call(Event.convert_from_filtered_log_event(event))
27
35
  end
28
36
 
29
37
  debug_log(params)
30
- debug_log(result)
31
38
 
39
+ @event_ids_by_timestamp = get_latest_events_and_timestamp
32
40
  break unless result.next_token
33
41
 
34
42
  params[:next_token] = result.next_token
35
43
  end
36
44
 
45
+ newest_timestamp = @event_ids_by_timestamp.keys.max
46
+ params[:start_time] = newest_timestamp unless newest_timestamp.nil?
47
+ params[:next_token] = nil
48
+ @event_ids_by_timestamp = {}
49
+
37
50
  sleep(@interval)
38
51
  end
39
52
  rescue Interrupt
@@ -42,6 +55,13 @@ module CloudWatchLogsPoller
42
55
 
43
56
  private
44
57
 
58
+ def get_latest_events_and_timestamp
59
+ newest_timestamp = @event_ids_by_timestamp.keys.max
60
+ return {} if newest_timestamp.nil?
61
+
62
+ {newest_timestamp => @event_ids_by_timestamp[newest_timestamp]}
63
+ end
64
+
45
65
  def debug_log(message)
46
66
  return unless @debug
47
67
 
@@ -1,3 +1,3 @@
1
1
  module CloudWatchLogsPoller
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud_watch_logs_poller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Ooishi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-23 00:00:00.000000000 Z
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-cloudwatchlogs
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 3.0.3
107
+ rubygems_version: 3.1.2
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Polling Cloud Watch Logs