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 +4 -4
- data/lib/logstash/outputs/awslogs.rb +45 -15
- data/logstash-output-awslogs.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 976089b21d8679e1a4a82a82e496257ad6085a26
|
4
|
+
data.tar.gz: e05ab955c846840ca2e91d89520db15dc9cff0d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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,
|
144
|
+
@logger.info("Logs throttling, retry")
|
115
145
|
retry
|
116
146
|
end
|
117
147
|
end
|