fluent-plugin-concat 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +52 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +10 -0
- data/fluent-plugin-concat.gemspec +23 -0
- data/lib/fluent/plugin/filter_concat.rb +88 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 27d3958d3254219e7ca4fe4e063ba5d9fcccadd9
|
4
|
+
data.tar.gz: bf836cffc244561d46bd47837aa3ce0018c36c93
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44fa6336681c18243a889ac5e0124f91d41654c8df7f4c8af65d9796bc5498805431035b841e2013a430131f7e4e63188e5caa10ea71b7150ff4fbeb357fb77b
|
7
|
+
data.tar.gz: 298996442014f001cd197a051231278d59f5877402c1993e627e88840e25d0af158dda3da2294b3405d78ed9d3d7d36037cc74c61b6c8fa493c784c0f4e0f598
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,52 @@
|
|
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
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 okkez
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# fluent-plugin-concat
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/okkez/fluent-plugin-concat.svg?branch=master)](https://travis-ci.org/okkez/fluent-plugin-concat)
|
4
|
+
|
5
|
+
Fluentd Filter plugin to concatenate multiline log separated in multiple events.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fluent-plugin-concat'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fluent-plugin-concat
|
22
|
+
|
23
|
+
## Configuration
|
24
|
+
|
25
|
+
**key** (required)
|
26
|
+
|
27
|
+
The key for part of multiline log.
|
28
|
+
|
29
|
+
**separator**
|
30
|
+
|
31
|
+
The separator of lines.
|
32
|
+
|
33
|
+
**n\_lines**
|
34
|
+
|
35
|
+
The number of lines.
|
36
|
+
This is exclusive with `multiline_start_regex`.
|
37
|
+
|
38
|
+
**multiline\_start\_regexp**
|
39
|
+
|
40
|
+
The regexp to match beginning of multiline.
|
41
|
+
This is exclusive with `n_lines.`
|
42
|
+
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
Every 10 events will be concatenated into one event.
|
47
|
+
|
48
|
+
```aconf
|
49
|
+
<filter docker.log>
|
50
|
+
@type concat
|
51
|
+
key message
|
52
|
+
n_lines 10
|
53
|
+
</filter>
|
54
|
+
```
|
55
|
+
|
56
|
+
Specify first line of multiline by regular expression.
|
57
|
+
|
58
|
+
```aconf
|
59
|
+
<filter docker.log>
|
60
|
+
@type concat
|
61
|
+
key message
|
62
|
+
multiline_start_regexp /^Start/
|
63
|
+
</filter>
|
64
|
+
```
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fluent-plugin-concat"
|
7
|
+
spec.version = "0.1.0"
|
8
|
+
spec.authors = ["Kenji Okimoto"]
|
9
|
+
spec.email = ["okimoto@clear-code.com"]
|
10
|
+
|
11
|
+
spec.summary = "Fluentd Filter plugin to concat multiple event messages"
|
12
|
+
spec.description = "Fluentd Filter plugin to concat multiple event messages"
|
13
|
+
spec.homepage = "https://github.com/okkez/fluent-plugin-concat"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "fluentd", "~> 0.12.21"
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "test-unit", ">= 3.1.0"
|
23
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Fluent
|
2
|
+
class ConcatFilter < Filter
|
3
|
+
Plugin.register_filter("concat", self)
|
4
|
+
|
5
|
+
desc "The key for part of multiline log"
|
6
|
+
config_param :key, :string, required: true
|
7
|
+
desc "The separator of lines"
|
8
|
+
config_param :separator, :string, default: "\n"
|
9
|
+
desc "The number of lines"
|
10
|
+
config_param :n_lines, :integer, default: nil
|
11
|
+
desc "The regexp to match beginning of multiline"
|
12
|
+
config_param :multiline_start_regexp, :string, default: nil
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
|
17
|
+
@buffer = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure(conf)
|
21
|
+
super
|
22
|
+
|
23
|
+
if @n_lines && @multiline_start_regexp
|
24
|
+
raise ConfigError, "n_lines and multiline_start_regexp are exclusive"
|
25
|
+
end
|
26
|
+
if @n_lines.nil? && @multiline_start_regexp.nil?
|
27
|
+
raise ConfigError, "Either n_lines or multiline_start_regexp is required"
|
28
|
+
end
|
29
|
+
|
30
|
+
@mode = nil
|
31
|
+
case
|
32
|
+
when @n_lines
|
33
|
+
@mode = :line
|
34
|
+
when @multiline_start_regexp
|
35
|
+
@multiline_start_regexp = Regexp.compile(@multiline_start_regexp[1..-2])
|
36
|
+
@mode = :regexp
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def filter_stream(tag, es)
|
41
|
+
new_es = MultiEventStream.new
|
42
|
+
es.each do |time, record|
|
43
|
+
begin
|
44
|
+
new_record = process(record)
|
45
|
+
new_es.add(time, record.merge(new_record)) if new_record
|
46
|
+
rescue => e
|
47
|
+
router.emit_error_event(tag, time, record, e)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
new_es
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def process(record)
|
56
|
+
case @mode
|
57
|
+
when :line
|
58
|
+
@buffer << record[@key]
|
59
|
+
if @n_lines && @buffer.size >= @n_lines
|
60
|
+
return flush_buffer
|
61
|
+
end
|
62
|
+
when :regexp
|
63
|
+
if firstline?(record[@key])
|
64
|
+
if @buffer.empty?
|
65
|
+
@buffer << record[@key]
|
66
|
+
else
|
67
|
+
return flush_buffer(record[@key])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
@buffer << record[@key]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def firstline?(text)
|
77
|
+
!!@multiline_start_regexp.match(text)
|
78
|
+
end
|
79
|
+
|
80
|
+
def flush_buffer(new_message = nil)
|
81
|
+
new_record = {}
|
82
|
+
new_record[@key] = @buffer.join(@separator)
|
83
|
+
@buffer = []
|
84
|
+
@buffer << new_message if new_message
|
85
|
+
new_record
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-concat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kenji Okimoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-07 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.12.21
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.12.21
|
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: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.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.0
|
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.0
|
69
|
+
description: Fluentd Filter plugin to concat multiple event messages
|
70
|
+
email:
|
71
|
+
- okimoto@clear-code.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- fluent-plugin-concat.gemspec
|
84
|
+
- lib/fluent/plugin/filter_concat.rb
|
85
|
+
homepage: https://github.com/okkez/fluent-plugin-concat
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.5.1
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Fluentd Filter plugin to concat multiple event messages
|
109
|
+
test_files: []
|