logstash-output-awslogs 0.1.10 → 0.1.15

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: 19a24fc8ec53b6f1aa7c2a42d2a1caa9e283960b
4
- data.tar.gz: 972c27ef7ca2dfd7f7d6f84c710a9fdd6fd20a75
3
+ metadata.gz: 29735655683e0bf0d17d8726372472e951cbfc3c
4
+ data.tar.gz: 81fe5f0b3430e382cd049984cde731332f676252
5
5
  SHA512:
6
- metadata.gz: 44676bc3a7ae7491843cc0440ea52c72d9f97a8d1689a99b4410dec7adc99188e27eddb021290c3411af34394a60ebb545cdefe16455cb522757ef590a4f58bf
7
- data.tar.gz: b79b2661c24cf73751aa3cae1034002f3a1f6815b2f9cd20a10c2f85ed4c767ada1c03199b126553dd16e173c5e3406846d5418885f9e7020c1742b7dc1a0ddf
6
+ metadata.gz: 5f35c56827166827987c39716260dd1435f2ac0d7071208e674e6cf27d1a6102c9ae24e4cbac3fb67fce978499f5ce15e9e66eec61b07ca0c5b522c2e7c23068
7
+ data.tar.gz: 22eadde7bcff23206e3c99d87c5b0545de942e7f348260f8831a490565b206fc75f5b6d092db15a0091d7f512561d79698532e2da525d6da67412fabed580b81
@@ -1,8 +1,9 @@
1
- # encoding: utf-8
2
- require "logstash/outputs/base"
3
- require "logstash/namespace"
4
- require "logstash/plugin_mixins/aws_config"
5
- require "aws-sdk"
1
+ # frozen_string_literal: true
2
+
3
+ require 'logstash/outputs/base'
4
+ require 'logstash/namespace'
5
+ require 'logstash/plugin_mixins/aws_config'
6
+ require 'aws-sdk'
6
7
 
7
8
  Aws.eager_autoload!
8
9
 
@@ -10,73 +11,74 @@ Aws.eager_autoload!
10
11
  class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
11
12
  include LogStash::PluginMixins::AwsConfig::V2
12
13
 
13
- config_name "awslogs"
14
- default :codec, "line"
14
+ config_name 'awslogs'
15
+ default :codec, 'line'
15
16
 
16
- config :log_group_name, :validate => :string, :required => true
17
- config :log_stream_name, :validate => :string, :required => true
17
+ config :log_group_name, validate: :string, required: true
18
+ config :log_stream_name, validate: :string, required: true
18
19
 
19
20
  public
21
+
20
22
  def register
21
23
  @client = Aws::CloudWatchLogs::Client.new(aws_options_hash)
22
24
  @next_sequence_tokens = {}
23
25
  end # def register
24
26
 
25
27
  public
28
+
26
29
  def multi_receive_encoded(events_and_encoded)
27
30
  to_send = {}
28
31
  sequence_tokens = {}
29
32
 
30
- events_and_encoded.each do |event, encoded|
33
+ events_and_encoded.each do |event, _encoded|
31
34
  event_log_stream_name = event.sprintf(log_stream_name)
32
35
  event_log_group_name = event.sprintf(log_group_name)
33
36
 
34
37
  next_sequence_token_key = [event_log_group_name, event_log_stream_name]
35
- if ! to_send.keys.include? next_sequence_token_key
38
+ unless to_send.keys.include? next_sequence_token_key
36
39
  to_send.store(next_sequence_token_key, [])
37
40
  end
38
- to_send[next_sequence_token_key].push({
41
+ to_send[next_sequence_token_key].push(
39
42
  timestamp: (event.timestamp.time.to_f * 1000).to_int,
40
- message: event.get("message"),
41
- })
43
+ message: event.get('message')
44
+ )
42
45
  end
43
46
 
44
47
  to_send.each do |event_log_names, _events|
45
48
  event_log_group_name = event_log_names[0]
46
49
  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)
50
+ next if sequence_tokens.keys.include? event_log_group_name
51
+
52
+ sequence_tokens.store(event_log_group_name, {})
53
+ begin
54
+ @client.describe_log_streams(log_group_name: event_log_group_name).each do |response|
55
+ response.log_streams.each do |log_stream_data|
56
+ sequence_tokens[event_log_group_name][log_stream_data.log_stream_name.to_s] = log_stream_data.upload_sequence_token.to_s
70
57
  end
71
- retry
72
- rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
73
- @logger.info("Logs throttling, retry")
74
- retry
75
58
  end
59
+ rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
60
+ @logger.info('Will create log group/stream and retry')
61
+ begin
62
+ @client.create_log_group(log_group_name: event_log_group_name)
63
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
64
+ @logger.info("Log group #{event_log_group_name} already exists")
65
+ rescue Exception => e
66
+ @logger.error(e)
67
+ end
68
+ begin
69
+ @client.create_log_stream(log_group_name: event_log_group_name, log_stream_name: event_log_stream_name)
70
+ rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
71
+ @logger.info("Log stream #{event_log_stream_name} already exists")
72
+ rescue Exception => e
73
+ @logger.error(e)
74
+ end
75
+ retry
76
+ rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
77
+ @logger.info('Logs throttling, retry')
78
+ retry
76
79
  end
77
80
  end
78
81
 
79
-
80
82
  to_send.each do |event_log_names, log_events|
81
83
  event_log_group_name = event_log_names[0]
82
84
  event_log_stream_name = event_log_names[1]
@@ -84,11 +86,11 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
84
86
 
85
87
  ident_opts = {
86
88
  log_group_name: event_log_group_name,
87
- log_stream_name: event_log_stream_name,
89
+ log_stream_name: event_log_stream_name
88
90
  }
89
- send_opts = ident_opts.merge({
90
- log_events: log_events,
91
- })
91
+ send_opts = ident_opts.merge(
92
+ log_events: log_events
93
+ )
92
94
 
93
95
  if @next_sequence_tokens.keys.include? next_sequence_token_key
94
96
  send_opts[:sequence_token] = @next_sequence_tokens[next_sequence_token_key]
@@ -96,18 +98,26 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
96
98
  send_opts[:sequence_token] = sequence_tokens[event_log_group_name][event_log_stream_name]
97
99
  else
98
100
  begin
99
- @client.create_log_stream(ident_opts)
101
+ @client.create_log_stream(ident_opts)
102
+ until sequence_tokens[event_log_group_name].key?(event_log_stream_name) && !sequence_tokens[event_log_group_name][event_log_stream_name].to_s.empty?
103
+ @client.describe_log_streams(log_group_name: event_log_group_name).each do |response|
104
+ response.log_streams.each do |log_stream_data|
105
+ sequence_tokens[event_log_group_name][log_stream_data.log_stream_name.to_s] = log_stream_data.upload_sequence_token.to_s
106
+ end
107
+ end
108
+ end
109
+ send_opts[:sequence_token] = sequence_tokens[event_log_group_name][event_log_stream_name]
100
110
  rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
101
- @logger.info("Will create log group/stream and retry")
111
+ @logger.info('Will create log group/stream and retry')
102
112
  begin
103
- @client.create_log_group(:log_group_name => send_opts[:log_group_name])
113
+ @client.create_log_group(log_group_name: send_opts[:log_group_name])
104
114
  rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
105
115
  @logger.info("Log group #{send_opts[:log_group_name]} already exists")
106
116
  rescue Exception => e
107
117
  @logger.error(e)
108
118
  end
109
119
  begin
110
- @client.create_log_stream(:log_group_name => send_opts[:log_group_name], :log_stream_name => send_opts[:log_stream_name])
120
+ @client.create_log_stream(log_group_name: send_opts[:log_group_name], log_stream_name: send_opts[:log_stream_name])
111
121
  rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
112
122
  @logger.info("Log stream #{send_opts[:log_stream_name]} already exists")
113
123
  rescue Exception => e
@@ -115,23 +125,24 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
115
125
  end
116
126
  retry
117
127
  rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
118
- @logger.info("Logs throttling, retry")
128
+ @logger.info('Logs throttling, retry')
119
129
  retry
120
130
  end
121
131
  end
122
132
  begin
123
133
  resp = @client.put_log_events(send_opts)
134
+ @next_sequence_tokens.store(next_sequence_token_key, resp.next_sequence_token)
124
135
  rescue Aws::CloudWatchLogs::Errors::ResourceNotFoundException => e
125
- @logger.info("Will create log group/stream and retry")
136
+ @logger.info('Will create log group/stream and retry')
126
137
  begin
127
- @client.create_log_group(:log_group_name => send_opts[:log_group_name])
138
+ @client.create_log_group(log_group_name: send_opts[:log_group_name])
128
139
  rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
129
140
  @logger.info("Log group #{send_opts[:log_group_name]} already exists")
130
141
  rescue Exception => e
131
142
  @logger.error(e)
132
143
  end
133
144
  begin
134
- @client.create_log_stream(:log_group_name => send_opts[:log_group_name], :log_stream_name => send_opts[:log_stream_name])
145
+ @client.create_log_stream(log_group_name: send_opts[:log_group_name], log_stream_name: send_opts[:log_stream_name])
135
146
  rescue Aws::CloudWatchLogs::Errors::ResourceAlreadyExistsException => e
136
147
  @logger.info("Log stream #{send_opts[:log_stream_name]} already exists")
137
148
  rescue Exception => e
@@ -139,10 +150,11 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
139
150
  end
140
151
  retry
141
152
  # TODO: handle rejected events with debug message
142
- @next_sequence_tokens.store(next_sequence_token_key, resp.next_sequence_token)
143
153
  rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
144
- @logger.info("Logs throttling, retry")
154
+ @logger.info('Logs throttling, retry')
145
155
  retry
156
+ rescue Exception => e
157
+ @logger.error(e)
146
158
  end
147
159
  end
148
160
  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.10'
3
+ s.version = '0.1.15'
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-awslogs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Klyba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-16 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core-plugin-api