fluent-plugin-json_expander 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dd0e91d385a1c563f4eeda19098692538e510d20
4
+ data.tar.gz: 1c35f48f84214ab5e9e1c3b872c7852b19631f80
5
+ SHA512:
6
+ metadata.gz: 3b6fdbddb5dd1aaed2317c129fd1f1fa66c6cc66cfac2f8cf407fdd49e8ef04ceba667270f261026a7d8bc3dae574e7113a63a7dfc20bf7f2f7de7244f12b634
7
+ data.tar.gz: dc05731acc6313db0faad2074543cd1036be1c56343dabfa60a14ec5c61ca484cd49a1d33deb7614eb5b8735f05d29cfea9e27504dccfaf564f445082f4018e4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1
6
+ - 2.2
7
+
8
+ before_install: gem install bundler -v 1.10.6
9
+
10
+ script: bundle exec rake test
11
+
12
+ notifications:
13
+ slack:
14
+ secure: S3CV6glzkzmVCEmXv0/mqizzBdGJk7btU2Y2pqP9V5JuQO/5ememCSxbmqcbMiO6CLRUIObFxhUxlWpvZspauQVX6xNMPZPgoTM9Ma5a+kxYkXc/7izbCqEhaqO8Qf2J78Ly5osqE4DtzYjQ6An85dDJ2mrhbuOrNINJkzL4x34jZgxLfNUIzcn1yC/MOstLqSWBPeSWUmh/cL8Jb74q+vLSYY5QdZvnGtxUvf8kWK/dfaT9xU9TUU+axdRJRT7VZqXEUtkuwhAEUElGNOFNuPUK95pxtGujVI+TI5s4+wq9rBRINGULpXQZh897pvHyAqGApxz/yxt/tsLGRT+B0Jn2EJ5J0eA0Aaew8Zwzp5Vpa3Q07jxr5EvGEWEHlNO1fTkg+SFE3EZO+I+0Mvlsqc1le8clGcssPyUCNl/ddvtbIR4QpcYf+JxE7YVgKCPGMdHQrmfTiqiuYfp6XhIiW5dcXa4WwT4/aCW0C/DtxMj74MZOfuMKGzyAOIQem/KZnxQj9zQG55ofCyUxjWUcdqHeLaHvVhOf5SX9O5CGyO1tpFW54Lj3nXO5EuJNj+pxIMVLPuP4oUkDN5xbMYF8IrNfYkXpOYJCvUpALmU7F9CfuNkJQwgDA3nQl4ptby8s/Ml8NzDPJnXxFVjF2hXocgHYy8Kqa344PleBpOG+da0=
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-json_expander.gemspec
4
+ gemspec
5
+
6
+ gem "pry"
7
+ gem "travis"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Uchio KONDO
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,71 @@
1
+ # fluent-plugin-json_expander
2
+
3
+ [![Build Status](https://travis-ci.org/udzura/fluent-plugin-json_expander.svg?branch=master)](https://travis-ci.org/udzura/fluent-plugin-json_expander)
4
+
5
+ ## Installation
6
+
7
+ Install it yourself as:
8
+
9
+ $ fluent-gem install fluent-plugin-json_expander
10
+
11
+ ## Usage
12
+
13
+ ```xml
14
+ <match access.summary>
15
+ type json_expander
16
+ subtype growthforecast
17
+ delete_used_key false # or true if you want to delete the key
18
+ # used in template construction
19
+
20
+ <template>
21
+ gfapi_url http://127.0.0.1:5125/api/
22
+ graph_path ${data[mothor_host]}/${data[vhost]}/${key_name}
23
+ name_keys count_2xx,count_3xx,count_4xx,count_5xx
24
+ </template>
25
+ </match>
26
+ ```
27
+
28
+ With data:
29
+
30
+ ```json
31
+ // tag = access.summary
32
+ {
33
+ "mother_host": "kvm001.udzura.jp",
34
+ "vhost": "front.udzura.com",
35
+ "count_2xx": 1234,
36
+ "count_3xx": 567,
37
+ "...": "..."
38
+ }
39
+ ```
40
+
41
+ Will extracted to below:
42
+
43
+ ```xml
44
+ <match>
45
+ type growthforecast
46
+ gfapi_url http://127.0.0.1:5125/api/
47
+ graph_path kvm001.udzura.jp/front.udzura.com/${key_name}
48
+ name_keys count_2xx,count_3xx,count_4xx,count_5xx
49
+ </match>
50
+ ```
51
+
52
+ ### Options
53
+
54
+ * `delete_used_key` - Deletes the key in the data when it is used to expand. Default: `false`
55
+ * `handle_empty_as_error` - Raise error that the value for the specified key is empty in template. Default: `false`
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
+
61
+ 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).
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/udzura/fluent-plugin-json_expander. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
66
+
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
71
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.description = "Run #{File.basename(Dir.pwd)}'s test suite"
6
+ # To run test for only one file (or file path pattern)
7
+ # $ bundle exec rake test TEST=test/test_specified_path.rb
8
+ t.libs.concat ["test"]
9
+ t.test_files = Dir["test/**/test_*.rb"]
10
+ t.verbose = true
11
+ t.ruby_opts = ["-r config"]
12
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/jsonbreak"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
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-json_expander"
7
+ spec.version = "0.0.1.pre"
8
+ spec.authors = ["Uchio KONDO"]
9
+ spec.email = ["udzura@udzura.jp"]
10
+
11
+ spec.summary = %q{Run the sub-matcher created from accepted json data}
12
+ spec.description = %q{Run the sub-matcher created from accepted json data}
13
+ spec.homepage = "https://github.com/udzura/fluent-plugin-json_expander"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "fluentd"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+
26
+ spec.add_development_dependency "test-unit", ">= 3"
27
+ spec.add_development_dependency "test-unit-rr"
28
+ spec.add_development_dependency "power_assert"
29
+ end
@@ -0,0 +1,126 @@
1
+ class Fluent::JsonExpanderOutput < Fluent::MultiOutput
2
+ Fluent::Plugin.register_output('json_expander', self)
3
+
4
+ config_param :subtype, :string
5
+ config_param :remove_prefix, :string, :default => nil
6
+ config_param :add_prefix, :string, :default => nil
7
+
8
+ config_param :delete_used_key, :bool, :default => false
9
+ config_param :handle_empty_as_error, :bool, :default => false
10
+
11
+ attr_reader :outputs
12
+
13
+ # Define `log` method for v0.10.42 or earlier
14
+ unless method_defined?(:log)
15
+ define_method("log") { $log }
16
+ end
17
+
18
+ def configure(conf)
19
+ super
20
+
21
+ if @remove_prefix
22
+ @removed_prefix_string = @remove_prefix + '.'
23
+ @removed_length = @removed_prefix_string.length
24
+ end
25
+ if @add_prefix
26
+ @added_prefix_string = @add_prefix + '.'
27
+ end
28
+
29
+ @outputs = []
30
+ @mutex = Mutex.new
31
+
32
+ templates = conf.elements.select{|e| e.name == 'template' }
33
+ if templates.size != 1
34
+ raise Fluent::ConfigError, "Just 1 template must be contained"
35
+ end
36
+
37
+ @template = templates.first
38
+ end
39
+
40
+ def emit(tag, es, chain)
41
+ if @remove_prefix and
42
+ ((tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix)
43
+ tag = tag[@removed_length..-1]
44
+ end
45
+ if @add_prefix
46
+ tag = tag.empty? ? (@added_prefix_string + tag) : @add_prefix
47
+ end
48
+
49
+ es.each {|time, record|
50
+ output = new_output(record)
51
+ if output
52
+ dup_es = Fluent::ArrayEventStream.new([[time, record]])
53
+ null_chain = Fluent::NullOutputChain.instance
54
+ output.emit(tag, dup_es, null_chain)
55
+ end
56
+ }
57
+ chain.next
58
+ end
59
+
60
+ private
61
+
62
+ def new_output(data)
63
+ o = nil
64
+ t = @template
65
+ begin
66
+ @mutex.synchronize do
67
+ if e = expand_elm(t, data)
68
+ o = Fluent::Plugin.new_output(@subtype)
69
+ o.configure(e)
70
+ o.start
71
+
72
+ @outputs.push(o)
73
+ end
74
+ end
75
+
76
+ log.info "[out_json_expand] Expanded new output: #{@subtype}"
77
+ rescue Fluent::ConfigError => e
78
+ log.error "failed to configure sub output #{@subtype}: #{e.message}"
79
+ log.error e.backtrace.join("\n")
80
+ log.error "Cannot output messages with data #{data.inspect}"
81
+ o = nil
82
+ rescue StandardError => e
83
+ log.error "failed to configure/start sub output #{@subtype}: #{e.message}"
84
+ log.error e.backtrace.join("\n")
85
+ log.error "Cannot output messages with data #{data.inspect}"
86
+ o = nil
87
+ end
88
+
89
+ return o
90
+ end
91
+
92
+ SCAN_DATA_RE = /\$\{data\[(?:[_a-zA-Z][_a-zA-Z0-9]*)\]\}/
93
+ SCAN_KEY_NAME_RE = /\[([_a-zA-Z][_a-zA-Z0-9]*)\]/
94
+
95
+ def expand_elm(template, data)
96
+ attr = {}
97
+ template.each do |k, v|
98
+ v = v.gsub(SCAN_DATA_RE) do |matched|
99
+ key_matched = matched.scan(SCAN_KEY_NAME_RE)[0]
100
+ if !key_matched or !key_matched[0]
101
+ raise(Fluent::ConfigError, "[BUG] data matched in template, but could not find key name")
102
+ end
103
+ if @handle_empty_as_error
104
+ k = key_matched[0]
105
+ data[k] || mark_errored(k, data)
106
+ else
107
+ data[key_matched[0]] || ""
108
+ end
109
+ end
110
+ attr[k] = v
111
+ end
112
+ # Expand recursively
113
+ sub_elms = template.elements.map {|e| expand_elm(data) }
114
+
115
+ if @mark_errored
116
+ nil
117
+ else
118
+ Fluent::Config::Element.new('instance', '', attr, sub_elms)
119
+ end
120
+ end
121
+
122
+ def mark_errored(k, data)
123
+ log.error "Could not find value for `#{k}' in data #{data.inspect}, Fluentd skips this"
124
+ @mark_errored = true
125
+ end
126
+ end
@@ -0,0 +1,22 @@
1
+ class Fluent::EchoPoolOutput < Fluent::Output
2
+ class << self
3
+ def echopool
4
+ @echopool ||= []
5
+ end
6
+ end
7
+
8
+ Fluent::Plugin.register_output('echopool', self)
9
+
10
+ config_param :message, :string
11
+
12
+ def emit(tag, es, chain)
13
+ es.each {|time, record|
14
+ self.class.echopool.push({
15
+ message: @message,
16
+ record: record,
17
+ tag: tag
18
+ })
19
+ }
20
+ chain.next
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-json_expander
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Uchio KONDO
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-29 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
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: '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: power_assert
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
+ description: Run the sub-matcher created from accepted json data
98
+ email:
99
+ - udzura@udzura.jp
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - fluent-plugin-json_expander.gemspec
114
+ - lib/fluent/plugin/out_json_expander.rb
115
+ - lib/fluent/plugin/testing/out_echopool.rb
116
+ homepage: https://github.com/udzura/fluent-plugin-json_expander
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">"
132
+ - !ruby/object:Gem::Version
133
+ version: 1.3.1
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.3
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Run the sub-matcher created from accepted json data
140
+ test_files: []