logstash-output-awslogs 0.1.2 → 0.1.7

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: b51111e0c86640d2277aa954226775fed704db91
4
- data.tar.gz: a24601a758c08e51c1916ffcc6154a878a856916
3
+ metadata.gz: ca3b7070b91420f6888420798778b06f9e5b2c48
4
+ data.tar.gz: 426f9a963a1436da065a0559b774c66a19441ce9
5
5
  SHA512:
6
- metadata.gz: 0cd0ccdb05a9db744383faa4b9985b353f1b20e7cd0f0813bcc12229bd54e8685f58306797bdae3e1f9ec79e450ae66d76a5f47f62a3ced88a55211e88cb3f77
7
- data.tar.gz: 5d7eca9d558c504f482e36dff72ca688e8460c38d68e101b9a776afd6be8eddeb62fff27634e3af0862ed9ead45fd089723f87830a55bdf866e0868567e1ffd8
6
+ metadata.gz: 04e400162e510b16b01b6699052569304bbf496f4fdc7f9c7cca1d7a5fabd3051e59c34e032e130a4db2d454818fff923aa26d9c0176a68aaeedfbd2e91fe5b2
7
+ data.tar.gz: 75bb11ef3a4cf7651dedddc5d76b1b35bf245fdf7d846c5bc4510ab3a5dedd45b63b54f56662dd0281a51ecd6ac5752e7afd35a0eb2d1bda3b41dc193114b643
@@ -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,45 @@ 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: encoded,
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
+ begin
49
+ @client.describe_log_streams({log_group_name: event_log_group_name}).each do |response|
50
+ response.log_streams.each do |log_stream_data|
51
+ sequence_tokens[event_log_group_name].push({ "#{log_stream_data.log_stream_name}": "#{log_stream_data.upload_sequence_token}"})
52
+ end
53
+ end
54
+ rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
55
+ @logger.info("Will create log group/stream and retry")
56
+ begin
57
+ @client.create_log_group(:log_group_name => send_opts[:log_group_name])
58
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
59
+ @logger.info("Log group #{send_opts[:log_group_name]} already exists")
60
+ rescue Exception => e
61
+ @logger.error(e)
62
+ end
63
+ begin
64
+ @client.create_log_stream(:log_group_name => send_opts[:log_group_name], :log_stream_name => send_opts[:log_stream_name])
65
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
66
+ @logger.info("Log stream #{send_opts[:log_stream_name]} already exists")
67
+ rescue Exception => e
68
+ @logger.error(e)
69
+ end
70
+ retry
71
+ rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
72
+ @logger.info("Logs throttling, retry")
73
+ retry
74
+ end
75
+ end
76
+ end
77
+
78
+
42
79
  to_send.each do |event_log_names, log_events|
43
80
  event_log_group_name = event_log_names[0]
44
81
  event_log_stream_name = event_log_names[1]
@@ -54,22 +91,11 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
54
91
 
55
92
  if @next_sequence_tokens.keys.include? next_sequence_token_key
56
93
  send_opts[:sequence_token] = @next_sequence_tokens[next_sequence_token_key]
94
+ elsif sequence_tokens[event_log_group_name].keys.include? event_log_stream_name
95
+ send_opts[:sequence_token] = sequence_tokens[event_log_group_name][event_log_stream_name]
57
96
  else
58
97
  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
98
  @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
99
  rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
74
100
  @logger.info("Will create log group/stream and retry")
75
101
  begin
@@ -87,6 +113,9 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
87
113
  @logger.error(e)
88
114
  end
89
115
  retry
116
+ rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
117
+ @logger.info("Logs throttling, retry")
118
+ retry
90
119
  end
91
120
  end
92
121
  begin
@@ -109,7 +138,10 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
109
138
  end
110
139
  retry
111
140
  # TODO: handle rejected events with debug message
112
- @next_sequence_tokens.store(next_sequence_token_key, resp.next_sequence_token)
141
+ @next_sequence_tokens.store(next_sequence_token_key, resp.next_sequence_token)
142
+ rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
143
+ @logger.info("Logs throttling, retry")
144
+ retry
113
145
  end
114
146
  end
115
147
  end # def multi_receive_encoded
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-awslogs'
3
- s.version = '0.1.2'
3
+ s.version = '0.1.7'
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.2
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Klyba