logstash-output-awslogs 0.1.6 → 0.1.7
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 +41 -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: ca3b7070b91420f6888420798778b06f9e5b2c48
|
4
|
+
data.tar.gz: 426f9a963a1436da065a0559b774c66a19441ce9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
@@ -39,6 +40,42 @@ 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
|
+
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
|
@@ -88,7 +114,7 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
|
|
88
114
|
end
|
89
115
|
retry
|
90
116
|
rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
|
91
|
-
@logger.info("Logs throttling,
|
117
|
+
@logger.info("Logs throttling, retry")
|
92
118
|
retry
|
93
119
|
end
|
94
120
|
end
|
@@ -114,7 +140,7 @@ class LogStash::Outputs::Awslogs < LogStash::Outputs::Base
|
|
114
140
|
# TODO: handle rejected events with debug message
|
115
141
|
@next_sequence_tokens.store(next_sequence_token_key, resp.next_sequence_token)
|
116
142
|
rescue Aws::CloudWatchLogs::Errors::ThrottlingException => e
|
117
|
-
@logger.info("Logs throttling,
|
143
|
+
@logger.info("Logs throttling, retry")
|
118
144
|
retry
|
119
145
|
end
|
120
146
|
end
|