fluentspec 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2bad1ac690f90653a60a46a110d096dcd02e8137
4
+ data.tar.gz: 6284c36efcbe4b80884b4da3c35fa14524db9043
5
+ SHA512:
6
+ metadata.gz: 48d2093ae7850d409907277d57b667b3ede599c358a4c9e5356f9d45aa8ca6cb96aa682bfedf479f1baafcdb055a9ed7d157ffc51bf49314ac19d08ca8718b9a
7
+ data.tar.gz: b748de381eb596bafc20e700ab1c590293b6caf7a15b0eeef855fa922f63e5d656563eda06f79d6c9c4720e14e6ec174edecbfdec567a3e22a2ea793ad258a9e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+ DisplayCopNames: true
4
+ Exclude:
5
+ - 'gemgiles/*'
6
+
7
+ Metrics/LineLength:
8
+ Max: 116
9
+ Exclude:
10
+ - 'spec/**/*'
11
+ - 'example/spec/**/*'
12
+
13
+ Metrics/BlockLength:
14
+ Exclude:
15
+ - 'spec/**/*'
16
+ - 'example/spec/**/*'
17
+
18
+ Style/Documentation:
19
+ Enabled: false
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 2.3
3
+ - 2.4.1
4
+
5
+ gemfile:
6
+ - gemfiles/fluentd_v0.12.x.gemfile
7
+ - gemfiles/fluentd_v0.14.x.gemfile
8
+ script:
9
+ - bundle exec rake
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'fluentd v0.12.x' do
4
+ gem 'fluentd', '~> 0.12.0'
5
+ end
6
+
7
+ appraise 'fluentd v0.14.x' do
8
+ gem 'fluentd', '~> 0.14.0'
9
+ end
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hiroki_toi@dwango.co.jp. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 toihrk
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.
@@ -0,0 +1,36 @@
1
+ # fluentspec
2
+
3
+ [![Build Status](https://travis-ci.org/toihrk/fluentspec.svg?branch=master)](https://travis-ci.org/toihrk/fluentspec)
4
+
5
+ fluentspec is testing tool for your fluentd configuration file.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'fluentspec'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Usage
20
+
21
+ [see example](example)
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at [toihrk/fluentspec](https://github.com/toihrk/fluentspec). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rubocop/rake_task'
5
+ require 'rspec/core/rake_task'
6
+ require 'appraisal'
7
+
8
+ RuboCop::RakeTask.new
9
+ RSpec::Core::RakeTask.new(:spec) do |s|
10
+ s.rspec_opts = %w[--format documentation --color]
11
+ end
12
+
13
+ if !ENV['APPRAISAL_INITIALIZED'] && !ENV['TRAVIS']
14
+ task default: %i[rubocop appraisal]
15
+ else
16
+ task default: %i[spec]
17
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'fluentspec'
6
+
7
+ require 'pry'
8
+ Pry.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rspec'
6
+
7
+ gem 'fluentd'
8
+ gem 'fluentspec', path: '../'
9
+
10
+ gem 'fluent-plugin-concat'
11
+ gem 'fluent-plugin-kinesis'
12
+ gem 'fluent-plugin-kubernetes_metadata_filter'
13
+ gem 'fluent-plugin-rewrite-tag-filter'
14
+ gem 'fluent-plugin-slack'
15
+
16
+ gem 'pry'
@@ -0,0 +1,141 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ fluentspec (0.1.0)
5
+ fluentd (>= 0.12)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.1.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ addressable (2.5.1)
16
+ public_suffix (~> 2.0, >= 2.0.2)
17
+ aws-sdk (2.10.9)
18
+ aws-sdk-resources (= 2.10.9)
19
+ aws-sdk-core (2.10.9)
20
+ aws-sigv4 (~> 1.0)
21
+ jmespath (~> 1.0)
22
+ aws-sdk-resources (2.10.9)
23
+ aws-sdk-core (= 2.10.9)
24
+ aws-sigv4 (1.0.0)
25
+ coderay (1.1.1)
26
+ concurrent-ruby (1.0.5)
27
+ cool.io (1.5.0)
28
+ diff-lcs (1.3)
29
+ domain_name (0.5.20170404)
30
+ unf (>= 0.0.5, < 1.0.0)
31
+ fluent-plugin-concat (1.0.0)
32
+ fluentd (~> 0.12.21)
33
+ fluent-plugin-kinesis (1.1.3)
34
+ aws-sdk (~> 2)
35
+ concurrent-ruby (~> 1)
36
+ fluentd (>= 0.10.58, < 2)
37
+ os (>= 0.9.6)
38
+ protobuf (>= 3.5.5)
39
+ fluent-plugin-kubernetes_metadata_filter (0.27.0)
40
+ fluentd (>= 0.12.0)
41
+ kubeclient (~> 1.1.4)
42
+ lru_redux
43
+ fluent-plugin-rewrite-tag-filter (1.5.6)
44
+ fluentd (>= 0.10.0, < 0.14.0)
45
+ fluent-plugin-slack (0.6.7)
46
+ fluentd (>= 0.10.8)
47
+ fluentd (0.12.37)
48
+ cool.io (>= 1.2.2, < 2.0.0)
49
+ http_parser.rb (>= 0.5.1, < 0.7.0)
50
+ json (>= 1.4.3)
51
+ msgpack (>= 0.5.11, < 2)
52
+ sigdump (~> 0.2.2)
53
+ string-scrub (>= 0.0.3, <= 0.0.5)
54
+ tzinfo (>= 1.0.0)
55
+ tzinfo-data (>= 1.0.0)
56
+ yajl-ruby (~> 1.0)
57
+ http (0.9.8)
58
+ addressable (~> 2.3)
59
+ http-cookie (~> 1.0)
60
+ http-form_data (~> 1.0.1)
61
+ http_parser.rb (~> 0.6.0)
62
+ http-cookie (1.0.3)
63
+ domain_name (~> 0.5)
64
+ http-form_data (1.0.3)
65
+ http_parser.rb (0.6.0)
66
+ i18n (0.8.6)
67
+ jmespath (1.3.1)
68
+ json (2.1.0)
69
+ kubeclient (1.1.4)
70
+ activesupport
71
+ http (= 0.9.8)
72
+ recursive-open-struct (= 1.0.0)
73
+ rest-client
74
+ lru_redux (1.1.0)
75
+ method_source (0.8.2)
76
+ middleware (0.1.0)
77
+ mime-types (3.1)
78
+ mime-types-data (~> 3.2015)
79
+ mime-types-data (3.2016.0521)
80
+ minitest (5.10.2)
81
+ msgpack (1.1.0)
82
+ netrc (0.11.0)
83
+ os (1.0.0)
84
+ protobuf (3.7.5)
85
+ activesupport (>= 3.2)
86
+ middleware
87
+ thor
88
+ thread_safe
89
+ pry (0.10.4)
90
+ coderay (~> 1.1.0)
91
+ method_source (~> 0.8.1)
92
+ slop (~> 3.4)
93
+ public_suffix (2.0.5)
94
+ recursive-open-struct (1.0.0)
95
+ rest-client (2.0.2)
96
+ http-cookie (>= 1.0.2, < 2.0)
97
+ mime-types (>= 1.16, < 4.0)
98
+ netrc (~> 0.8)
99
+ rspec (3.6.0)
100
+ rspec-core (~> 3.6.0)
101
+ rspec-expectations (~> 3.6.0)
102
+ rspec-mocks (~> 3.6.0)
103
+ rspec-core (3.6.0)
104
+ rspec-support (~> 3.6.0)
105
+ rspec-expectations (3.6.0)
106
+ diff-lcs (>= 1.2.0, < 2.0)
107
+ rspec-support (~> 3.6.0)
108
+ rspec-mocks (3.6.0)
109
+ diff-lcs (>= 1.2.0, < 2.0)
110
+ rspec-support (~> 3.6.0)
111
+ rspec-support (3.6.0)
112
+ sigdump (0.2.4)
113
+ slop (3.6.0)
114
+ string-scrub (0.0.5)
115
+ thor (0.19.4)
116
+ thread_safe (0.3.6)
117
+ tzinfo (1.2.3)
118
+ thread_safe (~> 0.1)
119
+ tzinfo-data (1.2017.2)
120
+ tzinfo (>= 1.0.0)
121
+ unf (0.1.4)
122
+ unf_ext
123
+ unf_ext (0.0.7.4)
124
+ yajl-ruby (1.3.0)
125
+
126
+ PLATFORMS
127
+ ruby
128
+
129
+ DEPENDENCIES
130
+ fluent-plugin-concat
131
+ fluent-plugin-kinesis
132
+ fluent-plugin-kubernetes_metadata_filter
133
+ fluent-plugin-rewrite-tag-filter
134
+ fluent-plugin-slack
135
+ fluentd
136
+ fluentspec!
137
+ pry
138
+ rspec
139
+
140
+ BUNDLED WITH
141
+ 1.14.6
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec) do |s|
5
+ s.rspec_opts = %w[--format documentation --color]
6
+ end
7
+
8
+ task default: %i[spec]
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path '../Gemfile', __FILE__
4
+
5
+ require 'bundler'
6
+ Bundler.require
7
+
8
+ Fluentspec.setup File.expand_path '../fluent.conf', __FILE__
9
+
10
+ Pry.start
@@ -0,0 +1,83 @@
1
+ <source>
2
+ @type tail
3
+
4
+ path /var/log/containers/*.log
5
+ pos_file fluentd-docker.pos
6
+ time_format %Y-%m-%dT%H:%M:%S
7
+ tag kubernetes.*
8
+ format json
9
+ </source>
10
+
11
+ <filter kubernetes.var.log.containers.**.log>
12
+ @type kubernetes_metadata
13
+ </filter>
14
+
15
+ <filter kubernetes.var.log.containers.**.log>
16
+ @type record_transformer
17
+ enable_ruby true
18
+
19
+ <record>
20
+ role ${record["kubernetes"]["labels"]["app"]}
21
+ container_name ${record["kubernetes"]["container_name"]}
22
+ </record>
23
+ </filter>
24
+
25
+ <match kubernetes.var.log.containers.**.log>
26
+ @type rewrite_tag_filter
27
+ rewriterule1 role (.+) service.$1
28
+ </match>
29
+
30
+ <match service.**>
31
+ @type rewrite_tag_filter
32
+ rewriterule1 container_name web nginx.${tag}
33
+ </match>
34
+
35
+ <match nginx.**>
36
+ @type rewrite_tag_filter
37
+ rewriterule1 stream stdout access.${tag}
38
+ rewriterule2 stream stderr error.${tag}
39
+ </match>
40
+
41
+ <filter access.nginx.**>
42
+ @type parser
43
+ format ltsv
44
+ key_name log
45
+ reserve_data
46
+ </filter>
47
+
48
+ <filter error.nginx.**>
49
+ @type concat
50
+ key log
51
+ stream_identity_key container_id
52
+ multiline_start_regexp /^-e:2:in `\/'/
53
+ multiline_end_regexp /^-e:4:in/
54
+ </filter>
55
+
56
+ <filter error.nginx.**>
57
+ @type parser
58
+ format multiline
59
+ format_firstline /^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} \[\w+\] (?<pid>\d+).(?<tid>\d+): /
60
+ format1 /^(?<time>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) \[(?<log_level>\w+)\] (?<pid>\d+).(?<tid>\d+): (?<message>.*)/
61
+ multiline_flush_interval 3s
62
+ key_name log
63
+ reserve_data
64
+ </filter>
65
+
66
+ <match access.nginx.**>
67
+ @type kinesis_firehose
68
+ include_time_key true
69
+ region dummy-region
70
+ delivery_stream_name dummy-stream
71
+ num_threads 15
72
+ flush_interval 10
73
+ buffer_chunk_limit 1m
74
+ try_flush_interval 0.1
75
+ queued_chunk_flush_interval 0.01
76
+ </match>
77
+
78
+ <match error.nginx.**>
79
+ @type slack
80
+ slackbot_url https://dummy
81
+ channel nginx-error
82
+ flush_interval 60s
83
+ </match>
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'inputs' do
6
+ subject { Fluentspec.inputs }
7
+
8
+ it 'has a input' do
9
+ expect(subject.size).to eq(1)
10
+ end
11
+
12
+ it 'should be tail input' do
13
+ tail = subject[0]
14
+ expect(tail.path).to eq('/var/log/containers/*.log')
15
+ expect(tail.tag).to eq('kubernetes.*')
16
+ end
17
+ end
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'match' do
6
+ subject do
7
+ Fluentspec.event_router.match(tag)
8
+ end
9
+
10
+ context 'kubernetes.var.log.containers.**.log' do
11
+ let(:tag) { 'kubernetes.var.log.containers.example.log' }
12
+
13
+ it 'should have filters and output' do
14
+ expect(subject).to be_an_instance_of Fluent::EventRouter::Pipeline
15
+
16
+ filters = subject.filters
17
+ output = subject.output
18
+ expect(filters.size).to eq(2)
19
+ expect(output).not_to be nil
20
+ end
21
+
22
+ it 'has KubernetesMetadataFilter' do
23
+ filters = subject.filters
24
+ kubernetes_metadata_filter = filters.find do |f|
25
+ f.is_a? Fluent::KubernetesMetadataFilter
26
+ end
27
+
28
+ expect(kubernetes_metadata_filter).not_to be nil
29
+ expect(kubernetes_metadata_filter.kubernetes_url).to be nil
30
+ end
31
+
32
+ it 'has RecordTransformerFilter' do
33
+ filters = subject.filters
34
+ record_transformer_filter = filters.find do |f|
35
+ f.is_a? Fluent::RecordTransformerFilter
36
+ end
37
+ expect(record_transformer_filter).not_to be nil
38
+ expect(record_transformer_filter.enable_ruby).to be true
39
+
40
+ config = record_transformer_filter.config
41
+ record_config = config.elements.find { |e| e.name == 'record' }
42
+
43
+ expect(record_config['role']).to eq('${record["kubernetes"]["labels"]["app"]}')
44
+ expect(record_config.key?('container_name')).to be true
45
+ expect(record_config['container_name']).to eq('${record["kubernetes"]["container_name"]}')
46
+ end
47
+
48
+ it 'has RewriteTagFilterOutput' do
49
+ output = subject.output
50
+ expect(output).to be_an_instance_of Fluent::RewriteTagFilterOutput
51
+
52
+ rewrite_tag = output.rewrite_tag tag, 'role' => 'example'
53
+ expect(rewrite_tag).to eq('service.example')
54
+ end
55
+ end
56
+
57
+ context 'service.**' do
58
+ let(:tag) { 'service.example' }
59
+
60
+ it 'should match RewriteTagFilterOutput' do
61
+ expect(subject).to be_an_instance_of Fluent::RewriteTagFilterOutput
62
+
63
+ rewrite_tag = subject.rewrite_tag tag, 'container_name' => 'web'
64
+ expect(rewrite_tag).to eq('nginx.service.example')
65
+ end
66
+ end
67
+
68
+ context 'nginx.**' do
69
+ let(:tag) { 'nginx.service.example' }
70
+
71
+ it 'should match RewriteTagFilterOutput' do
72
+ expect(subject).to be_an_instance_of Fluent::RewriteTagFilterOutput
73
+ end
74
+
75
+ context 'stream => stdout' do
76
+ let(:record) { { 'stream' => 'stdout' } }
77
+ it 'should rewrite tag access.nginx.service.example' do
78
+ rewrite_tag = subject.rewrite_tag tag, record
79
+ expect(rewrite_tag).to eq('access.nginx.service.example')
80
+ end
81
+ end
82
+
83
+ context 'stream => stderr' do
84
+ let(:record) { { 'stream' => 'stderr' } }
85
+ it 'should rewrite tag error.nginx.service.example' do
86
+ rewrite_tag = subject.rewrite_tag tag, record
87
+ expect(rewrite_tag).to eq('error.nginx.service.example')
88
+ end
89
+ end
90
+ end
91
+
92
+ context 'access.nginx.**' do
93
+ let(:tag) { 'access.nginx.service.example' }
94
+
95
+ it 'should have filters and output' do
96
+ expect(subject).to be_an_instance_of Fluent::EventRouter::Pipeline
97
+
98
+ filters = subject.filters
99
+ output = subject.output
100
+ expect(filters.size).to eq(1)
101
+ expect(output).not_to be nil
102
+ end
103
+
104
+ it 'has ParserFilter' do
105
+ filters = subject.filters
106
+ parser_filter = filters.find do |f|
107
+ f.is_a? Fluent::ParserFilter
108
+ end
109
+
110
+ expect(parser_filter).not_to be nil
111
+ config = parser_filter.config
112
+ expect(config['format']).to eq('ltsv')
113
+ expect(config['key_name']).to eq('log')
114
+ expect(config.key?('reserve_data')).to be true
115
+ end
116
+
117
+ it 'has KinesisFirehoseOutput' do
118
+ output = subject.output
119
+ expect(output).to be_an_instance_of Fluent::KinesisFirehoseOutput
120
+ expect(output.include_time_key).to be true
121
+ expect(output.region).to eq('dummy-region')
122
+ expect(output.delivery_stream_name).to eq('dummy-stream')
123
+ end
124
+ end
125
+
126
+ context 'error.nginx.**' do
127
+ let(:tag) { 'error.nginx.service.example' }
128
+
129
+ it 'should have filters and output' do
130
+ expect(subject).to be_an_instance_of Fluent::EventRouter::Pipeline
131
+
132
+ filters = subject.filters
133
+ output = subject.output
134
+ expect(filters.size).to eq(2)
135
+ expect(output).not_to be nil
136
+ end
137
+
138
+ it 'has ConcatFilter' do
139
+ filters = subject.filters
140
+ concar_filter = filters.find do |f|
141
+ f.is_a? Fluent::ConcatFilter
142
+ end
143
+
144
+ expect(concar_filter).not_to be nil
145
+ end
146
+
147
+ it 'has ParserFilter' do
148
+ filters = subject.filters
149
+ parser_filter = filters.find do |f|
150
+ f.is_a? Fluent::ParserFilter
151
+ end
152
+
153
+ expect(parser_filter).not_to be nil
154
+ config = parser_filter.config
155
+ expect(config['format']).to eq('multiline')
156
+ end
157
+
158
+ it 'has SlackOutput' do
159
+ output = subject.output
160
+ expect(output).to be_an_instance_of Fluent::SlackOutput
161
+
162
+ expect(output.slackbot_url).to eq('https://dummy')
163
+ expect(output.channel).to eq('#nginx-error')
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path '../../Gemfile', __FILE__
4
+
5
+ require 'bundler'
6
+ Bundler.setup
7
+
8
+ require 'rspec'
9
+ require 'fluentspec'
10
+ Fluentspec.setup File.expand_path('../../fluent.conf', __FILE__)
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'fluentspec/version'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = 'fluentspec'
10
+ s.version = Fluentspec::VERSION
11
+ s.authors = ['toihrk']
12
+ s.email = ['toihrk@me.com']
13
+
14
+ s.summary = 'fluentspec is testing tool for your fluentd configuration file.'
15
+ s.description = s.summary
16
+
17
+ s.homepage = 'https://github.com/toihrk/fluentspec'
18
+ s.license = 'MIT'
19
+
20
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless s.respond_to?(:metadata)
21
+
22
+ s.files = `git ls-files -z`.split(?\x0).reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+
24
+ s.require_paths = ['lib']
25
+
26
+ s.add_dependency 'fluentd', '>= 0.12'
27
+
28
+ s.add_development_dependency 'bundler', '~> 1.14'
29
+ s.add_development_dependency 'rake', '~> 12'
30
+ s.add_development_dependency 'pry'
31
+ s.add_development_dependency 'pry-doc'
32
+ s.add_development_dependency 'rubocop'
33
+ s.add_development_dependency 'appraisal'
34
+ s.add_development_dependency 'rspec', '~> 3.6'
35
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "fluentd", "~> 0.12.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ fluentspec (0.1.0)
5
+ fluentd (>= 0.12)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ appraisal (2.2.0)
11
+ bundler
12
+ rake
13
+ thor (>= 0.14.0)
14
+ ast (2.3.0)
15
+ coderay (1.1.1)
16
+ cool.io (1.5.0)
17
+ diff-lcs (1.3)
18
+ fluentd (0.12.37)
19
+ cool.io (>= 1.2.2, < 2.0.0)
20
+ http_parser.rb (>= 0.5.1, < 0.7.0)
21
+ json (>= 1.4.3)
22
+ msgpack (>= 0.5.11, < 2)
23
+ sigdump (~> 0.2.2)
24
+ string-scrub (>= 0.0.3, <= 0.0.5)
25
+ tzinfo (>= 1.0.0)
26
+ tzinfo-data (>= 1.0.0)
27
+ yajl-ruby (~> 1.0)
28
+ http_parser.rb (0.6.0)
29
+ json (2.1.0)
30
+ method_source (0.8.2)
31
+ msgpack (1.1.0)
32
+ parallel (1.11.2)
33
+ parser (2.4.0.0)
34
+ ast (~> 2.2)
35
+ powerpack (0.1.1)
36
+ pry (0.10.4)
37
+ coderay (~> 1.1.0)
38
+ method_source (~> 0.8.1)
39
+ slop (~> 3.4)
40
+ pry-doc (0.10.0)
41
+ pry (~> 0.9)
42
+ yard (~> 0.9)
43
+ rainbow (2.2.2)
44
+ rake
45
+ rake (12.0.0)
46
+ rspec (3.6.0)
47
+ rspec-core (~> 3.6.0)
48
+ rspec-expectations (~> 3.6.0)
49
+ rspec-mocks (~> 3.6.0)
50
+ rspec-core (3.6.0)
51
+ rspec-support (~> 3.6.0)
52
+ rspec-expectations (3.6.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.6.0)
55
+ rspec-mocks (3.6.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.6.0)
58
+ rspec-support (3.6.0)
59
+ rubocop (0.49.1)
60
+ parallel (~> 1.10)
61
+ parser (>= 2.3.3.1, < 3.0)
62
+ powerpack (~> 0.1)
63
+ rainbow (>= 1.99.1, < 3.0)
64
+ ruby-progressbar (~> 1.7)
65
+ unicode-display_width (~> 1.0, >= 1.0.1)
66
+ ruby-progressbar (1.8.1)
67
+ sigdump (0.2.4)
68
+ slop (3.6.0)
69
+ string-scrub (0.0.5)
70
+ thor (0.19.4)
71
+ thread_safe (0.3.6)
72
+ tzinfo (1.2.3)
73
+ thread_safe (~> 0.1)
74
+ tzinfo-data (1.2017.2)
75
+ tzinfo (>= 1.0.0)
76
+ unicode-display_width (1.3.0)
77
+ yajl-ruby (1.3.0)
78
+ yard (0.9.9)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ appraisal
85
+ bundler (~> 1.14)
86
+ fluentd (~> 0.12.0)
87
+ fluentspec!
88
+ pry
89
+ pry-doc
90
+ rake (~> 12)
91
+ rspec (~> 3.6)
92
+ rubocop
93
+
94
+ BUNDLED WITH
95
+ 1.14.6
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "fluentd", "~> 0.14.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ fluentspec (0.1.0)
5
+ fluentd (>= 0.12)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ appraisal (2.2.0)
11
+ bundler
12
+ rake
13
+ thor (>= 0.14.0)
14
+ ast (2.3.0)
15
+ coderay (1.1.1)
16
+ cool.io (1.5.0)
17
+ diff-lcs (1.3)
18
+ fluentd (0.14.18)
19
+ cool.io (>= 1.4.5, < 2.0.0)
20
+ http_parser.rb (>= 0.5.1, < 0.7.0)
21
+ msgpack (>= 0.7.0, < 2.0.0)
22
+ serverengine (>= 2.0.4, < 3.0.0)
23
+ sigdump (~> 0.2.2)
24
+ strptime (~> 0.1.7)
25
+ tzinfo (~> 1.0)
26
+ tzinfo-data (~> 1.0)
27
+ yajl-ruby (~> 1.0)
28
+ http_parser.rb (0.6.0)
29
+ method_source (0.8.2)
30
+ msgpack (1.1.0)
31
+ parallel (1.11.2)
32
+ parser (2.4.0.0)
33
+ ast (~> 2.2)
34
+ powerpack (0.1.1)
35
+ pry (0.10.4)
36
+ coderay (~> 1.1.0)
37
+ method_source (~> 0.8.1)
38
+ slop (~> 3.4)
39
+ pry-doc (0.10.0)
40
+ pry (~> 0.9)
41
+ yard (~> 0.9)
42
+ rainbow (2.2.2)
43
+ rake
44
+ rake (12.0.0)
45
+ rspec (3.6.0)
46
+ rspec-core (~> 3.6.0)
47
+ rspec-expectations (~> 3.6.0)
48
+ rspec-mocks (~> 3.6.0)
49
+ rspec-core (3.6.0)
50
+ rspec-support (~> 3.6.0)
51
+ rspec-expectations (3.6.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.6.0)
54
+ rspec-mocks (3.6.0)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.6.0)
57
+ rspec-support (3.6.0)
58
+ rubocop (0.49.1)
59
+ parallel (~> 1.10)
60
+ parser (>= 2.3.3.1, < 3.0)
61
+ powerpack (~> 0.1)
62
+ rainbow (>= 1.99.1, < 3.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (~> 1.0, >= 1.0.1)
65
+ ruby-progressbar (1.8.1)
66
+ serverengine (2.0.5)
67
+ sigdump (~> 0.2.2)
68
+ sigdump (0.2.4)
69
+ slop (3.6.0)
70
+ strptime (0.1.9)
71
+ thor (0.19.4)
72
+ thread_safe (0.3.6)
73
+ tzinfo (1.2.3)
74
+ thread_safe (~> 0.1)
75
+ tzinfo-data (1.2017.2)
76
+ tzinfo (>= 1.0.0)
77
+ unicode-display_width (1.3.0)
78
+ yajl-ruby (1.3.0)
79
+ yard (0.9.9)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ appraisal
86
+ bundler (~> 1.14)
87
+ fluentd (~> 0.14.0)
88
+ fluentspec!
89
+ pry
90
+ pry-doc
91
+ rake (~> 12)
92
+ rspec (~> 3.6)
93
+ rubocop
94
+
95
+ BUNDLED WITH
96
+ 1.14.6
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fluentspec/version'
4
+ require 'fluentspec/supervisor'
5
+
6
+ module Fluentspec
7
+ @ready = false
8
+
9
+ module_function
10
+
11
+ def ready?
12
+ @ready ||= false
13
+ end
14
+
15
+ def setup(config_file_path)
16
+ @sv = Supervisor.new(config_file_path)
17
+ @ready = true
18
+ end
19
+
20
+ def engine
21
+ ::Fluent::Engine if Fluentspec.ready?
22
+ end
23
+
24
+ def root_agent
25
+ Fluentspec.engine.root_agent if Fluentspec.ready?
26
+ end
27
+
28
+ def inputs
29
+ Fluentspec.root_agent.inputs if Fluentspec.ready?
30
+ end
31
+
32
+ def filters
33
+ Fluentspec.root_agent.filters if Fluentspec.ready?
34
+ end
35
+
36
+ def outputs
37
+ Fluentspec.root_agent.outputs if Fluentspec.ready?
38
+ end
39
+
40
+ def event_router
41
+ Fluentspec.root_agent.event_router if Fluentspec.ready?
42
+ end
43
+
44
+ def cleanup
45
+ @sv.reset
46
+ @ready = false
47
+ end
48
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fluent/plugin'
4
+ require 'fluent/supervisor'
5
+
6
+ module Fluent
7
+ class Supervisor
8
+ def run_spec
9
+ read_config
10
+ set_system_config
11
+
12
+ change_privilege
13
+ init_engine
14
+ run_configure
15
+ end
16
+ end
17
+
18
+ class EventRouter
19
+ class Pipeline
20
+ def filters
21
+ @filters ||= []
22
+ end
23
+
24
+ def output
25
+ @output ||= nil
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ module Fluentspec
32
+ class Supervisor
33
+ def initialize(conf = nil)
34
+ raise ArgumentError if conf.nil?
35
+ @conf = conf
36
+ opts = Fluent::Supervisor.default_options
37
+ opts[:config_path] = @conf
38
+ @sv = Fluent::Supervisor.new(opts)
39
+ @sv.run_spec
40
+ end
41
+
42
+ # rubocop:disable Lint/HandleExceptions
43
+ def reset
44
+ opts = Fluent::Supervisor.default_options
45
+ @sv = Fluent::Supervisor.new(opts)
46
+ @sv.run_spec
47
+ rescue
48
+ end
49
+ end
50
+ # rubocop:enable Lint/HandleExceptions
51
+ end
52
+
53
+ # rubocop:disable all
54
+ def $log.method_missing(_method, *_args); end
55
+ # rubocop:enable all
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fluentspec
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluentspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - toihrk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-18 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'
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'
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.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
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'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: appraisal
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.6'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.6'
125
+ description: fluentspec is testing tool for your fluentd configuration file.
126
+ email:
127
+ - toihrk@me.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rubocop.yml"
134
+ - ".travis.yml"
135
+ - Appraisals
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - example/Gemfile
144
+ - example/Gemfile.lock
145
+ - example/Rakefile
146
+ - example/console.rb
147
+ - example/fluent.conf
148
+ - example/spec/inputs_spec.rb
149
+ - example/spec/match_spec.rb
150
+ - example/spec/spec_helper.rb
151
+ - fluentspec.gemspec
152
+ - gemfiles/fluentd_v0.12.x.gemfile
153
+ - gemfiles/fluentd_v0.12.x.gemfile.lock
154
+ - gemfiles/fluentd_v0.14.x.gemfile
155
+ - gemfiles/fluentd_v0.14.x.gemfile.lock
156
+ - lib/fluentspec.rb
157
+ - lib/fluentspec/supervisor.rb
158
+ - lib/fluentspec/version.rb
159
+ homepage: https://github.com/toihrk/fluentspec
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.6.11
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: fluentspec is testing tool for your fluentd configuration file.
183
+ test_files: []