logstash-output-awslogs 0.1.5 → 0.1.10

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: ca546d819e0b7380e5c3e223f734b73b539b7ec7
4
- data.tar.gz: 33415c58330218021b79dfb305a265d034e5e20f
3
+ metadata.gz: 19a24fc8ec53b6f1aa7c2a42d2a1caa9e283960b
4
+ data.tar.gz: 972c27ef7ca2dfd7f7d6f84c710a9fdd6fd20a75
5
5
  SHA512:
6
- metadata.gz: fc483aea49fee409283373d3db6a8bb7af82269324eee605a9bf8d14c17947aeec4c9b653305ca724a8238912576a8337ce7c8c9e76fb0c28eb664b4c823b9a6
7
- data.tar.gz: e47bf343fa1eae53da1316475e5f8e85299b8360a6932a1d5db019e26509e67df471783af7a089959842ba093c839e07901a95ef6abcd7335ef61b407366bc15
6
+ metadata.gz: 44676bc3a7ae7491843cc0440ea52c72d9f97a8d1689a99b4410dec7adc99188e27eddb021290c3411af34394a60ebb545cdefe16455cb522757ef590a4f58bf
7
+ data.tar.gz: b79b2661c24cf73751aa3cae1034002f3a1f6815b2f9cd20a10c2f85ed4c767ada1c03199b126553dd16e173c5e3406846d5418885f9e7020c1742b7dc1a0ddf
@@ -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)
@@ -39,6 +40,43 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
39
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 => event_log_group_name)
59
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
60
+ @logger.info("Log group #{event_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 => event_log_group_name, :log_stream_name => event_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.5'
3
+ s.version = '0.1.10'
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.5
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Klyba