fluent-plugin-cloudwatch-ingest 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd7841c1d572b29c7281cb013d50891e7f516220
|
4
|
+
data.tar.gz: 2f17af0ba832d06aa21adff0ac5ddd5f0a619d6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1075e7279388aaa254e9ad81f5be0bbe1c0461d07022b9b1d095d4dc7450e0e08ceeb8b5a46dd5c7aa02b3760efe733ac05860f9e80eb70969a1e8584ad4bb00
|
7
|
+
data.tar.gz: 5f01bd527a5942c662449ccc1f06ada526d7ffb72185c6d92bfb24c0a02da7b537eb381dd2425c0f622aedeff31507f26a792c578f2dbbad481acc224ecc905f
|
@@ -3,7 +3,7 @@ require 'fluent/plugin/parser'
|
|
3
3
|
require 'fluent/config/error'
|
4
4
|
require 'aws-sdk'
|
5
5
|
require 'pathname'
|
6
|
-
require '
|
6
|
+
require 'psych'
|
7
7
|
|
8
8
|
module Fluent::Plugin
|
9
9
|
class CloudwatchIngestInput < Fluent::Plugin::Input
|
@@ -191,32 +191,42 @@ module Fluent::Plugin
|
|
191
191
|
attr_accessor :statefile
|
192
192
|
|
193
193
|
def initialize(filepath, log)
|
194
|
+
@filepath = filepath
|
195
|
+
@log = log
|
196
|
+
|
194
197
|
if File.exist?(statefile)
|
195
|
-
self.statefile = Pathname.new(filepath).open('r+')
|
198
|
+
self.statefile = Pathname.new(@filepath).open('r+')
|
196
199
|
else
|
197
|
-
log.warn("No state file #{statefile} Creating a new one.")
|
200
|
+
@log.warn("No state file #{statefile} Creating a new one.")
|
198
201
|
begin
|
199
|
-
self.statefile = Pathname.new(filepath).open('w+')
|
202
|
+
self.statefile = Pathname.new(@filepath).open('w+')
|
200
203
|
save
|
201
204
|
rescue => boom
|
202
|
-
log.error("Unable to create new state file #{statefile}: #{boom}")
|
205
|
+
@log.error("Unable to create new state file #{statefile}: #{boom}")
|
203
206
|
end
|
204
207
|
end
|
205
208
|
|
206
209
|
# Attempt to obtain an exclusive flock on the file and raise and
|
207
210
|
# exception if we can't
|
208
|
-
log.info("Obtaining exclusive lock on state file #{statefile}")
|
211
|
+
@log.info("Obtaining exclusive lock on state file #{statefile}")
|
209
212
|
lockstatus = statefile.flock(File::LOCK_EX | File::LOCK_NB)
|
210
213
|
raise CloudwatchIngestInput::State::LockFailed if lockstatus == false
|
211
214
|
|
212
|
-
merge!(
|
213
|
-
log.info("Loaded state for #{keys.size} log groups from #{statefile}")
|
215
|
+
merge!(Psych.safe_load(statefile.read, [Fluent::Plugin::CloudwatchIngestInput::State])) # rubocop:disable all
|
216
|
+
@log.info("Loaded state for #{keys.size} log groups from #{statefile}")
|
217
|
+
end
|
218
|
+
|
219
|
+
# http://stackoverflow.com/questions/12821534/ruby-yaml-parser-by-passing-constructor
|
220
|
+
def init_with(coder)
|
221
|
+
@filepath = coder['filepath']
|
222
|
+
@log = coder['log']
|
214
223
|
end
|
215
224
|
|
216
225
|
def save
|
217
226
|
statefile.rewind
|
218
|
-
statefile.write(
|
219
|
-
log.info("Saved state to #{statefile}")
|
227
|
+
statefile.write(Psych.dump(self))
|
228
|
+
@log.info("Saved state to #{statefile}")
|
229
|
+
statefile.rewind
|
220
230
|
end
|
221
231
|
|
222
232
|
def close
|
@@ -226,7 +236,7 @@ module Fluent::Plugin
|
|
226
236
|
def prune(log_groups)
|
227
237
|
groups_before = keys.size
|
228
238
|
delete_if { |k, _v| true unless log_groups.key?(k) }
|
229
|
-
log.info("Pruned #{groups_before - keys.size} keys from state file")
|
239
|
+
@log.info("Pruned #{groups_before - keys.size} keys from state file")
|
230
240
|
|
231
241
|
# TODO: also prune streams as these are most likely to be transient
|
232
242
|
end
|