logstash-output-awslogs 0.1.4 → 0.1.9

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
  SHA1:
3
- metadata.gz: 1280d4828fdd1cbfc0e407bfdfae5127572cb0c6
4
- data.tar.gz: c641eccec19bdc129e2c15a5c927ec7796945149
3
+ metadata.gz: 976089b21d8679e1a4a82a82e496257ad6085a26
4
+ data.tar.gz: e05ab955c846840ca2e91d89520db15dc9cff0d3
5
5
  SHA512:
6
- metadata.gz: cfd68ef3a9bb21a4c3ab9b6efee6168aaa000d95e19d60413ab4c5ea407410f98dd07b96b655646d574c4562a85853e9a09da6e8da2940472b46926c9f497b42
7
- data.tar.gz: 806074d660e435ad74fc4bcf766cfa1536680c9f53d84a9fd13c641e99ba0eee311409600dd13babb859a277e24879bb97f7ec62eacc525940449e4a7381ca2a
6
+ metadata.gz: 3fb50d9e90d952643b4002be3f252a3fa6aa1fd690384a160ece3f469223a0def2e34ead061f883df113bb882f7de10c2c0ad71cb33f35d64383c21359c4a1a7
7
+ data.tar.gz: '04870b92f6126ef8a297afa9a0bfef6f55b7ac630d5499d15fa67a9a06d62037dab5df10f32e4951690bba00190557ad6f7e45a545ca75eee3fbe0e212091964'
@@ -25,6 +25,7 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
25
25
  public
26
26
  def multi_receive_encoded(events_and_encoded)
27
27
  to_send = {}
28
+ sequence_tokens = {}
28
29
 
29
30
  events_and_encoded.each do |event, encoded|
30
31
  event_log_stream_name = event.sprintf(log_stream_name)
@@ -36,9 +37,46 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
36
37
  end
37
38
  to_send[next_sequence_token_key].push({
38
39
  timestamp: (event.timestamp.time.to_f * 1000).to_int,
39
- message: event.get(MESSAGE),
40
+ message: event.get("message"),
40
41
  })
41
42
  end
43
+
44
+ to_send.each do |event_log_names, _events|
45
+ event_log_group_name = event_log_names[0]
46
+ event_log_stream_name = event_log_names[1]
47
+ unless sequence_tokens.keys.include? event_log_group_name
48
+ sequence_tokens.store(event_log_group_name, {})
49
+ begin
50
+ @client.describe_log_streams({log_group_name: event_log_group_name}).each do |response|
51
+ response.log_streams.each do |log_stream_data|
52
+ sequence_tokens[event_log_group_name]["#{log_stream_data.log_stream_name}"] = "#{log_stream_data.upload_sequence_token}"
53
+ end
54
+ end
55
+ rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
56
+ @logger.info("Will create log group/stream and retry")
57
+ begin
58
+ @client.create_log_group(:log_group_name => send_opts[:log_group_name])
59
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
60
+ @logger.info("Log group #{send_opts[:log_group_name]} already exists")
61
+ rescue Exception => e
62
+ @logger.error(e)
63
+ end
64
+ begin
65
+ @client.create_log_stream(:log_group_name => send_opts[:log_group_name], :log_stream_name => send_opts[:log_stream_name])
66
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
67
+ @logger.info("Log stream #{send_opts[:log_stream_name]} already exists")
68
+ rescue Exception => e
69
+ @logger.error(e)
70
+ end
71
+ retry
72
+ rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
73
+ @logger.info("Logs throttling, retry")
74
+ retry
75
+ end
76
+ end
77
+ end
78
+
79
+
42
80
  to_send.each do |event_log_names, log_events|
43
81
  event_log_group_name = event_log_names[0]
44
82
  event_log_stream_name = event_log_names[1]
@@ -54,22 +92,11 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
54
92
 
55
93
  if @next_sequence_tokens.keys.include? next_sequence_token_key
56
94
  send_opts[:sequence_token] = @next_sequence_tokens[next_sequence_token_key]
95
+ elsif sequence_tokens[event_log_group_name].keys.include? event_log_stream_name
96
+ send_opts[:sequence_token] = sequence_tokens[event_log_group_name][event_log_stream_name]
57
97
  else
58
98
  begin
59
- resp = @client.describe_log_streams({
60
- log_group_name: event_log_group_name,
61
- log_stream_name_prefix: event_log_stream_name,
62
- })
63
- if resp.log_streams.length < 1
64
99
  @client.create_log_stream(ident_opts)
65
- else
66
- resp.log_streams.each do |log_stream_data|
67
- if log_stream_data.log_stream_name == event_log_stream_name
68
- send_opts[:sequence_token] = log_stream_data.upload_sequence_token
69
- break
70
- end
71
- end
72
- end
73
100
  rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
74
101
  @logger.info("Will create log group/stream and retry")
75
102
  begin
@@ -87,6 +114,9 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
87
114
  @logger.error(e)
88
115
  end
89
116
  retry
117
+ rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
118
+ @logger.info("Logs throttling, retry")
119
+ retry
90
120
  end
91
121
  end
92
122
  begin
@@ -111,7 +141,7 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
111
141
  # TODO: handle rejected events with debug message
112
142
  @next_sequence_tokens.store(next_sequence_token_key, resp.next_sequence_token)
113
143
  rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
114
- @logger.info("Logs throttling, wait 1 sec")
144
+ @logger.info("Logs throttling, retry")
115
145
  retry
116
146
  end
117
147
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-awslogs'
3
- s.version = '0.1.4'
3
+ s.version = '0.1.9'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'Writes events to AWS CloudWatch logs.'
6
6
  s.homepage = 'https://github.com/rickycook/logstash-output-awslogs'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-awslogs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Klyba