fluent-plugin-grpc 0.0.2

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: 3947aab1ca9cec4a5489d5b1f07921a80ff046ad
4
+ data.tar.gz: 662a6a85c98f3a486ff41b5fed6a47dcbcd794da
5
+ SHA512:
6
+ metadata.gz: 1fb58c4851579e45ba74333ac8f356665ccf1574c59e1880ec60424acc698b86ca71d182477c50c711d59087476ade30b5550901cadc554eac9d089f0ba20416
7
+ data.tar.gz: 28f7a4bc43a8ba1d5d8411c39ee7979351dd9fc5cefdc80063656bd965eb86dd29c54c8b048fb1c98cbc5cd3874d5abdee56caab3b20a4bad918e939cc54665b
@@ -0,0 +1,2 @@
1
+ /Gemfile.lock
2
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2018-2018 Myungjae Won
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,54 @@
1
+ # fluent-plugin-grpc, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ A fluentd plugin to both send and receive fluentd events via [grpc](https://grpc.io)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-grpc'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it by yourself:
16
+
17
+ $ gem install fluent-plugin-grpc
18
+
19
+ ## Requirements
20
+
21
+ - Ruby 2.3 or later
22
+
23
+ ## Usage
24
+
25
+ ### Input plugin (@type 'grpc')
26
+
27
+ Receive events via grpc.
28
+
29
+ <source>
30
+ @type grpc
31
+ bind 0.0.0.0
32
+ port 50051
33
+ </source>
34
+
35
+ <match **>
36
+ @type stdout
37
+ </match>
38
+
39
+ ### Output plugin (@type 'grpc')
40
+
41
+ Send events via grpc.
42
+
43
+ <source>
44
+ @type dummy
45
+ tag test
46
+ </source>
47
+
48
+ <match **>
49
+ @type grpc
50
+ path localhost:50051
51
+ <buffer>
52
+ flush_mode immediate
53
+ </buffer>
54
+ </match>
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/**/test_*.rb']
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => [:build]
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.authors = ["Myungjae Won"]
3
+ spec.email = ["breadmj@gmail.com"]
4
+ spec.description = %q{Fluentd plugins for gRPC}
5
+ spec.summary = %q{Fluentd input/output plugins that communicate over gRPC}
6
+ spec.homepage = "https://github.com/breadmj/fluent-plugin-grpc"
7
+ spec.license = "MIT"
8
+
9
+ spec.files = `git ls-files`.split($\)
10
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
12
+ spec.name = "fluent-plugin-grpc"
13
+ spec.require_paths = ["lib"]
14
+ spec.version = '0.0.2'
15
+ spec.required_ruby_version = ">= 2.3.0"
16
+
17
+ spec.add_dependency "fluentd", [">= 0.12.39", "< 2"]
18
+ spec.add_dependency "grpc", "~> 1.14"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.14"
21
+ spec.add_development_dependency "rake", "~> 12.0"
22
+ spec.add_development_dependency "test-unit", "~> 3.0"
23
+ spec.add_development_dependency "grpc-tools", "~> 1.14"
24
+ end
@@ -0,0 +1,18 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: event.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "event.Log" do
8
+ optional :name, :string, 1
9
+ end
10
+ add_message "event.Ack" do
11
+ optional :type, :string, 1
12
+ end
13
+ end
14
+
15
+ module Event
16
+ Log = Google::Protobuf::DescriptorPool.generated_pool.lookup("event.Log").msgclass
17
+ Ack = Google::Protobuf::DescriptorPool.generated_pool.lookup("event.Ack").msgclass
18
+ end
@@ -0,0 +1,22 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: event.proto for package 'event'
3
+
4
+ require 'grpc'
5
+ require 'event_pb'
6
+
7
+ module Event
8
+ module Forwarder
9
+ class Service
10
+
11
+ include GRPC::GenericService
12
+
13
+ self.marshal_class_method = :encode
14
+ self.unmarshal_class_method = :decode
15
+ self.service_name = 'event.Forwarder'
16
+
17
+ rpc :Forward, Log, Ack
18
+ end
19
+
20
+ Stub = Service.rpc_stub_class
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ require 'fluent/plugin/input'
2
+ require 'grpc'
3
+ require 'event_services_pb'
4
+
5
+ module Fluent::Plugin
6
+ class GrpcInput < Input
7
+ Fluent::Plugin.register_input('grpc', self)
8
+
9
+ helpers :thread
10
+
11
+ desc 'The address to bind to.'
12
+ config_param :bind, :string, default: '0.0.0.0'
13
+ desc 'The port to listen to.'
14
+ config_param :port, :integer, default: 50051
15
+
16
+ class ForwarderServer < Event::Forwarder::Service
17
+ def forward(event, _unused_call)
18
+ $stdout.puts event.name
19
+ Event::Ack.new(type: "received")
20
+ end
21
+ end
22
+
23
+ public
24
+ def configure(conf)
25
+ super
26
+
27
+ if @port < 1024
28
+ raise Fluent::ConfigError, "well known ports cannot be used for this purpose."
29
+ end
30
+ end
31
+
32
+ public
33
+ def start
34
+ super
35
+
36
+ @s = GRPC::RpcServer.new
37
+ @s.add_http2_port("#{@bind}:#{@port}", :this_port_is_insecure)
38
+ @s.handle(ForwarderServer)
39
+ thread_create :in_grpc_server do
40
+ @s.run
41
+ end
42
+ end
43
+
44
+ public
45
+ def shutdown
46
+ @s.stop
47
+
48
+ super
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,25 @@
1
+ require 'fluent/plugin/output'
2
+ require 'event_services_pb'
3
+
4
+ module Fluent::Plugin
5
+ class GrpcOutput < Output
6
+
7
+ Fluent::Plugin.register_output('grpc', self)
8
+
9
+ desc 'The endpoint of gRPC server.'
10
+ config_param :path, :string
11
+
12
+ def start
13
+ super
14
+ @stub = Event::Forwarder::Stub.new(@path, :this_channel_is_insecure)
15
+ end
16
+
17
+ def write(chunk)
18
+ chunk.each do |time, record|
19
+ ack = @stub.forward(Event::Log.new(name: record['message']))
20
+ $stdout.puts ack.type
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ syntax = "proto3";
2
+
3
+ package event;
4
+
5
+ service Forwarder {
6
+ rpc Forward(Log) returns (Ack) {}
7
+ }
8
+
9
+ message Log {
10
+ string name = 1;
11
+ }
12
+
13
+ message Ack {
14
+ string type = 1;
15
+ }
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require "test-unit"
4
+ require "fluent/test"
5
+ require "fluent/test/driver/input"
6
+ require "fluent/test/driver/output"
7
+ require "fluent/test/helpers"
8
+
9
+ Test::Unit::TestCase.include(Fluent::Test::Helpers)
10
+ Test::Unit::TestCase.extend(Fluent::Test::Helpers)
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+ require 'fluent/plugin/in_grpc'
3
+
4
+ class GrpcInputTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ BASE_CONFIG = %[
10
+ @type grpc
11
+ ]
12
+
13
+ CONFIG = BASE_CONFIG + %[
14
+ # nothing yet
15
+ ]
16
+
17
+ def create_driver(conf=CONFIG)
18
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::GrpcInput).configure(conf)
19
+ end
20
+
21
+ def test_configure
22
+ assert_nothing_raised(Fluent::ConfigError) {
23
+ create_driver(BASE_CONFIG)
24
+ }
25
+
26
+ assert_nothing_raised(Fluent::ConfigError) {
27
+ create_driver(CONFIG)
28
+ }
29
+ end
30
+
31
+ end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+ require 'fluent/plugin/out_grpc'
3
+
4
+ class GrpcOutputTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ CONFIG = %[
10
+ path localhost:50051
11
+ ]
12
+
13
+ def create_driver(conf=CONFIG)
14
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::GrpcOutput).configure(conf)
15
+ end
16
+
17
+ sub_test_case 'configured with invalid configurations' do
18
+ test 'empty config' do
19
+ assert_raise Fluent::ConfigError do
20
+ create_driver(%[])
21
+ end
22
+ end
23
+
24
+ test 'path is set correctly' do
25
+ d = create_driver
26
+ assert_equal "localhost:50051", d.instance.path
27
+ end
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-grpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Myungjae Won
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-06 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.39
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.12.39
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: grpc
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.14'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.14'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.14'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.14'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '12.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '12.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: grpc-tools
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.14'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.14'
103
+ description: Fluentd plugins for gRPC
104
+ email:
105
+ - breadmj@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - Gemfile
112
+ - LICENSE
113
+ - README.md
114
+ - Rakefile
115
+ - fluent-plugin-grpc.gemspec
116
+ - lib/event_pb.rb
117
+ - lib/event_services_pb.rb
118
+ - lib/fluent/plugin/in_grpc.rb
119
+ - lib/fluent/plugin/out_grpc.rb
120
+ - protos/event.proto
121
+ - test/helper.rb
122
+ - test/plugin/test_in_grpc.rb
123
+ - test/plugin/test_out_grpc.rb
124
+ homepage: https://github.com/breadmj/fluent-plugin-grpc
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 2.3.0
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.5.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Fluentd input/output plugins that communicate over gRPC
148
+ test_files:
149
+ - test/helper.rb
150
+ - test/plugin/test_in_grpc.rb
151
+ - test/plugin/test_out_grpc.rb