fluent-plugin-docker-journald-concat 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7698d8dc7b9b2976c8963c23d5ff7ee1f9793554
4
+ data.tar.gz: f18bf9669f0f5988157bced5b64ec191dd125cd3
5
+ SHA512:
6
+ metadata.gz: 49b5f3dd8bf8edc1b246f7059e3509118bead0956401e18a0108032825289e5fc36d5e6510f85b1cec0f4500cdf27c6f064abe8145775c5d50c26a07c38a5c9b
7
+ data.tar.gz: 35c410ae81440d38777aedb814afc7713748356b82c763bf49f5dfff78c7fb639df3d570349dacd0017ec7fe7c2b98faa281b0abd9d6656a8d8f9242d89bb6ba
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rubocop.yml ADDED
@@ -0,0 +1,55 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ DisplayCopNames: true
4
+ Exclude:
5
+ - "vendor/**/*"
6
+
7
+ Lint/UnderscorePrefixedVariableName:
8
+ Enabled: false
9
+ Lint/UnusedMethodArgument:
10
+ Enabled: false
11
+
12
+ Metrics/LineLength:
13
+ Enabled: false
14
+ Metrics/ClassLength:
15
+ Exclude:
16
+ - "test/**/*.rb"
17
+ Metrics/ParameterLists:
18
+ Max: 7
19
+ Metrics/MethodLength:
20
+ Max: 30
21
+
22
+ Style/AsciiComments:
23
+ Enabled: false
24
+ Style/HashSyntax:
25
+ Exclude:
26
+ - "**/*.rake"
27
+ - "Rakefile"
28
+ Style/FrozenStringLiteralComment:
29
+ Enabled: false
30
+ Style/StringLiterals:
31
+ EnforcedStyle: double_quotes
32
+ Style/TrailingCommaInLiteral:
33
+ Enabled: false
34
+ Style/TrailingCommaInArguments:
35
+ Enabled: false
36
+ Style/FileName:
37
+ Enabled: false
38
+ Style/Documentation:
39
+ Enabled: false
40
+ Style/WordArray:
41
+ Enabled: false
42
+ Style/BarePercentLiterals:
43
+ EnforcedStyle: percent_q
44
+ Style/SpaceInsideBlockBraces:
45
+ EnforcedStyle: space
46
+ SpaceBeforeBlockParameters: false
47
+ Style/BracesAroundHashParameters:
48
+ Enabled: false
49
+ Style/MultilineMethodCallIndentation:
50
+ EnforcedStyle: indented
51
+ Style/DoubleNegation:
52
+ Enabled: false
53
+ Style/EmptyCaseCondition:
54
+ Enabled: false
55
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-concat.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-docker-journald-concat (0.1.0)
5
+ fluentd (~> 0.14)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ cool.io (1.5.1)
11
+ fluentd (0.14.21)
12
+ cool.io (>= 1.4.5, < 2.0.0)
13
+ http_parser.rb (>= 0.5.1, < 0.7.0)
14
+ msgpack (>= 0.7.0, < 2.0.0)
15
+ ruby_dig (~> 0.0.2)
16
+ serverengine (>= 2.0.4, < 3.0.0)
17
+ sigdump (~> 0.2.2)
18
+ strptime (~> 0.1.7)
19
+ tzinfo (~> 1.0)
20
+ tzinfo-data (~> 1.0)
21
+ yajl-ruby (~> 1.0)
22
+ http_parser.rb (0.6.0)
23
+ msgpack (1.1.0)
24
+ power_assert (1.1.0)
25
+ rake (12.1.0)
26
+ rr (1.2.1)
27
+ ruby_dig (0.0.2)
28
+ serverengine (2.0.5)
29
+ sigdump (~> 0.2.2)
30
+ sigdump (0.2.4)
31
+ strptime (0.1.9)
32
+ test-unit (3.2.6)
33
+ power_assert
34
+ test-unit-rr (1.0.5)
35
+ rr (>= 1.1.1)
36
+ test-unit (>= 2.5.2)
37
+ thread_safe (0.3.6)
38
+ tzinfo (1.2.3)
39
+ thread_safe (~> 0.1)
40
+ tzinfo-data (1.2017.2)
41
+ tzinfo (>= 1.0.0)
42
+ yajl-ruby (1.3.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.11)
49
+ fluent-plugin-docker-journald-concat!
50
+ rake (~> 12.0)
51
+ test-unit (~> 3.1)
52
+ test-unit-rr (~> 1.0)
53
+
54
+ BUNDLED WITH
55
+ 1.14.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Oleksandr Kushchenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # fluent-plugin-docker-journald-concat
2
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-docker-journald-concat.svg)](https://badge.fury.io/rb/fluent-plugin-docker-journald-concat)
3
+
4
+ Fluentd Filter plugin to concatenate partial log messages generated by Docker daemon with Journald logging driver
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ task :default => :test
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.test_files = Dir["test/**/test_*.rb"].sort
8
+ t.verbose = false
9
+ t.warning = true
10
+ end
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "fluent-plugin-docker-journald-concat"
6
+ spec.version = "0.1.1"
7
+ spec.authors = ["Oleksandr Kushchenko"]
8
+ spec.email = ["gearok@gmail.com"]
9
+
10
+ spec.summary = "Fluentd Filter plugin to concatenate partial log messages generated by Docker daemon with Journald logging driver"
11
+ spec.description = "Fluentd Filter plugin to concatenate partial log messages generated by Docker daemon with Journald logging driver"
12
+ spec.homepage = "https://github.com/okushchenko/fluent-plugin-docker-journald-concat"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_runtime_dependency "fluentd", "~> 0.14"
19
+ spec.add_development_dependency "bundler", "~> 1.11"
20
+ spec.add_development_dependency "rake", "~> 12.0"
21
+ spec.add_development_dependency "test-unit", "~> 3.1"
22
+ spec.add_development_dependency "test-unit-rr", "~> 1.0"
23
+ end
@@ -0,0 +1,160 @@
1
+ require "fluent/plugin/filter"
2
+
3
+ module Fluent::Plugin
4
+ class DockerJournalConcatFilter < Filter
5
+ Fluent::Plugin.register_filter("docker_journal_concat", self)
6
+
7
+ helpers :timer, :event_emitter
8
+
9
+ desc "The key to merge records on"
10
+ config_param :key, :string, default: "message"
11
+ desc "The key to test if record is multipart against"
12
+ config_param :match_key, :string, default: "container_partial_message"
13
+ desc "The key to determine which stream an event belongs to"
14
+ config_param :stream_identity_key, :string, default: "container_id"
15
+ desc "The interval between data flushes, 0 means disable timeout"
16
+ config_param :flush_interval, :time, default: 60
17
+ desc "The label name to handle timeout"
18
+ config_param :timeout_label, :string, default: nil
19
+
20
+ class TimeoutError < StandardError
21
+ end
22
+
23
+ def initialize
24
+ super
25
+
26
+ @buffer = Hash.new {|h, k| h[k] = [] }
27
+ @timeout_map = Hash.new {|h, k| h[k] = Fluent::Engine.now }
28
+ end
29
+
30
+ def configure(conf)
31
+ super
32
+
33
+ @separator = ""
34
+ end
35
+
36
+ def start
37
+ super
38
+
39
+ @finished = false
40
+ timer_execute(:filter_concat_timer, 1, &method(:on_timer))
41
+ end
42
+
43
+ def shutdown
44
+ super
45
+
46
+ @finished = true
47
+ flush_shutdown_buffer
48
+ end
49
+
50
+ def filter_stream(tag, es)
51
+ new_es = Fluent::MultiEventStream.new
52
+ es.each do |time, record|
53
+ if /\Afluent\.(?:trace|debug|info|warn|error|fatal)\z/ =~ tag
54
+ new_es.add(time, record)
55
+ next
56
+ end
57
+ begin
58
+ flushed_es = process(tag, time, record)
59
+ unless flushed_es.empty?
60
+ flushed_es.each do |_time, new_record|
61
+ new_es.add(time, record.merge(new_record))
62
+ end
63
+ end
64
+ rescue => e
65
+ router.emit_error_event(tag, time, record, e)
66
+ end
67
+ end
68
+ new_es
69
+ end
70
+
71
+ private
72
+
73
+ def on_timer
74
+ return if @flush_interval <= 0
75
+ return if @finished
76
+ flush_timeout_buffer
77
+ end
78
+
79
+ def process(tag, time, record)
80
+ stream_identity = "#{tag}:#{record[@stream_identity_key]}"
81
+ @timeout_map[stream_identity] = Fluent::Engine.now
82
+ new_es = Fluent::MultiEventStream.new
83
+ if partial?(record[@match_key])
84
+ # partial record
85
+ @buffer[stream_identity] << [tag, time, record]
86
+ return new_es
87
+ elsif !@buffer[stream_identity].empty?
88
+ # last partial record
89
+ @buffer[stream_identity] << [tag, time, record]
90
+ _, new_record = flush_buffer(stream_identity)
91
+ new_es.add(time, new_record)
92
+ return new_es
93
+ end
94
+ # regular record
95
+ new_es.add(time, record)
96
+ new_es
97
+ end
98
+
99
+ def partial?(text)
100
+ /^true$/.match(text)
101
+ end
102
+
103
+ def sanitize_record(record)
104
+ record.delete(@match_key)
105
+ end
106
+
107
+ def flush_buffer(stream_identity)
108
+ lines = @buffer[stream_identity].map {|_tag, _time, record| record[@key] }
109
+ _tag, time, first_record = @buffer[stream_identity].first
110
+ new_record = {
111
+ @key => lines.join(@separator)
112
+ }
113
+ @buffer[stream_identity].clear
114
+ merged_record = first_record.merge(new_record)
115
+ sanitize_record(merged_record)
116
+ [time, merged_record]
117
+ end
118
+
119
+ def flush_timeout_buffer
120
+ # now = Fluent::Engine.now
121
+ now = Fluent::EventTime.now
122
+ timeout_stream_identities = []
123
+ @timeout_map.each do |stream_identity, previous_timestamp|
124
+ next if @flush_interval > (now - previous_timestamp)
125
+ next if @buffer[stream_identity].empty?
126
+ time, record = flush_buffer(stream_identity)
127
+ sanitize_record(record)
128
+ timeout_stream_identities << stream_identity
129
+ tag = stream_identity.split(":").first
130
+ message = "Timeout flush: #{stream_identity}"
131
+ handle_timeout_error(tag, time, record, message)
132
+ log.info(message)
133
+ end
134
+ @timeout_map.reject! do |stream_identity, _|
135
+ timeout_stream_identities.include?(stream_identity)
136
+ end
137
+ end
138
+
139
+ def flush_shutdown_buffer
140
+ @buffer.each do |stream_identity, elements|
141
+ next if elements.empty?
142
+ tag = stream_identity.split(":").first
143
+ time, record = flush_buffer(stream_identity)
144
+ router.emit(tag, time, record)
145
+ log.info("Shutdown flush: #{stream_identity}")
146
+ end
147
+ @buffer.clear
148
+ log.info("Filter docker_journal_concat shutdown finished")
149
+ end
150
+
151
+ def handle_timeout_error(tag, time, record, message)
152
+ if @timeout_label
153
+ event_router = event_emitter_router(@timeout_label)
154
+ event_router.emit(tag, time, record)
155
+ else
156
+ router.emit_error_event(tag, time, record, TimeoutError.new(message))
157
+ end
158
+ end
159
+ end
160
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-docker-journald-concat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Oleksandr Kushchenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit-rr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description: Fluentd Filter plugin to concatenate partial log messages generated by
84
+ Docker daemon with Journald logging driver
85
+ email:
86
+ - gearok@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rubocop.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - fluent-plugin-docker-journald-concat.gemspec
99
+ - lib/fluent/plugin/filter_docker_journal_concat.rb
100
+ homepage: https://github.com/okushchenko/fluent-plugin-docker-journald-concat
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.5.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Fluentd Filter plugin to concatenate partial log messages generated by Docker
124
+ daemon with Journald logging driver
125
+ test_files: []