fluent-plugin-wire-protocol-compat 0.1.0

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: 9a48a636525c3ed60d88189bbd630a2cc3e0b17b
4
+ data.tar.gz: 3f95a2c5e718392dc86aa49d2d4fb56e43b4ba35
5
+ SHA512:
6
+ metadata.gz: 794d3431ce9fffab468bad0b1455c0c284246f2461732b1f44b6638e202e6e34a576175e10e202ff46fcfbdffad956d1115e64cbd932c8084517fce484bba71d
7
+ data.tar.gz: 00d181daed6424ba79e696dd03d1b39013f0986a3e49ec7922e2901cbb0da51846b9483b84618186c3f6f06bf232938a2e853d33a69d5c0c2cc9a775486a6763
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
11
+ *.swo
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-wire-protocol-compat.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Fluent::WireProtocolCompatInput
2
+
3
+ This plugin makes the wire protocol for [in\_udp](http://docs.fluentd.org/articles/in_udp) and [in\_tcp](http://docs.fluentd.org/articles/in_tcp) compatible with [in\_forward](http://docs.fluentd.org/articles/in_forward#protocol)'s.
4
+
5
+ Note: You need to install [fluent-plugin-msgpack-parser](https://rubygems.org/gems/fluent-plugin-msgpack-parser) to add [msgpack](http://msgpack.org/) support for `in_udp` and `in_tcp`.
6
+
7
+ ## Installation
8
+
9
+ Please check Fluentd's [plugin management docs](http://docs.fluentd.org/articles/plugin-management)
10
+
11
+ ## Usage
12
+ ### Example configuration
13
+ ```
14
+ <source>
15
+ type wire_protocol_compat
16
+ <input>
17
+ type udp
18
+ port 12201
19
+ bind 127.0.0.1
20
+ format json
21
+ tag some_tag
22
+ </input>
23
+ </source>
24
+ ```
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( https://github.com/bitex-la/fluent-plugin-wire-protocol-compat/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create a new Pull Request
33
+
34
+ ## TODO
35
+ * Additional formats specs
36
+ * Extract rspec-fluentd gem
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,26 @@
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-wire-protocol-compat"
7
+ spec.version = File.read("VERSION").strip
8
+ spec.authors = ["Tomás Rojas"]
9
+ spec.email = ["tmsrjs@gmail.com"]
10
+
11
+ spec.summary = %q{Adds in_forward wire protocol support to in_udp and in_tcp}
12
+ spec.homepage = "https://github.com/bitex-la/fluent-plugin-wire-protocol-compat"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "fluentd", ">= 0.10.51"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.9"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "test-unit"
24
+ spec.add_development_dependency "byebug"
25
+ spec.add_development_dependency "timecop"
26
+ end
@@ -0,0 +1,109 @@
1
+ require 'fluent/input'
2
+ require 'fluent/plugin'
3
+
4
+ module Fluent
5
+ class WireProtocolCompatInput < Input
6
+ Plugin.register_input('wire_protocol_compat', self)
7
+ def configure(conf)
8
+ super
9
+
10
+ @inputs = [ ]
11
+ config.each_element('input') do |input_config|
12
+ type = input_config.delete('type')
13
+ next unless [ 'udp', 'tcp' ].include? type
14
+ base_input = Plugin.new_input(type).class
15
+ input_klass = Class.new(base_input) do
16
+ include WireProtocolCompatInput::SocketUtilBaseInputMethods
17
+ end
18
+ input = input_klass.new
19
+ input.configure(input_config)
20
+ if input.format == 'json'
21
+ parser_klass = Class.new(Fluent::TextParser::JSONParser) do
22
+ include WireProtocolCompatInput::JSONParserMethods
23
+ end
24
+ input.instance_eval do
25
+ @parser = parser_klass.new
26
+ @parser.configure(@config)
27
+ end
28
+ end
29
+ @inputs << input
30
+ end
31
+ end
32
+
33
+ def start
34
+ super
35
+ @inputs.each(&:start)
36
+ end
37
+
38
+ def shutdown
39
+ super
40
+ @inputs.each(&:shutdown)
41
+ end
42
+
43
+ module JSONParserMethods
44
+ def normalize_hash(record)
45
+ value = @keep_time_key ? record[@time_key] : record.delete(@time_key)
46
+ if value
47
+ if @time_format
48
+ time = @mutex.synchronize { @time_parser.parse(value) }
49
+ else
50
+ begin
51
+ time = value.to_i
52
+ rescue => e
53
+ raise ParserError, "invalid time value: value = #{value}, error_class = #{e.class.name}, error = #{e.message}"
54
+ end
55
+ end
56
+ else
57
+ if @estimate_current_event
58
+ time = Engine.now
59
+ else
60
+ time = nil
61
+ end
62
+ end
63
+ [ time, record ]
64
+ end
65
+
66
+ def parse(text)
67
+ parsed = @load_proc.call(text)
68
+ case parsed
69
+ when Hash
70
+ normalized = normalize_hash(parsed)
71
+ when Array
72
+ normalized = parsed
73
+ end
74
+ yield *normalized
75
+ end
76
+ end
77
+
78
+ module SocketUtilBaseInputMethods
79
+ def on_message(msg, addr)
80
+ @parser.parse(msg) do |*parsed|
81
+ case parsed[0]
82
+ when String
83
+ tag, time, record = parsed
84
+ records = time.is_a?(Array) ? time : [ [ time, record ] ]
85
+ when Integer
86
+ tag = @tag
87
+ records = [ parsed ]
88
+ end
89
+
90
+ time, record = records.first
91
+ unless time && record
92
+ log.warn "pattern not match: #{msg.inspect}"
93
+ return
94
+ end
95
+
96
+ es = MultiEventStream.new
97
+ records.each do |time, record|
98
+ record[@source_host_key] = addr[3] if @source_host_key
99
+ es.add(time, record)
100
+ end
101
+ router.emit_stream(tag, es)
102
+ end
103
+ rescue => e
104
+ log.error msg.dump, :error => e, :error_class => e.class, :host => addr[3]
105
+ log.error_backtrace
106
+ end
107
+ end
108
+ end
109
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-wire-protocol-compat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomás Rojas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-13 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.10.51
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.51
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.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
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: rspec
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: test-unit
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: byebug
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: timecop
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
+ description:
112
+ email:
113
+ - tmsrjs@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".ruby-version"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - VERSION
125
+ - fluent-plugin-wire-protocol-compat.gemspec
126
+ - lib/fluent/plugin/in_wire_protocol_compat.rb
127
+ homepage: https://github.com/bitex-la/fluent-plugin-wire-protocol-compat
128
+ licenses: []
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.4.5
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Adds in_forward wire protocol support to in_udp and in_tcp
150
+ test_files: []