fluent-plugin-scribe 0.10.7 → 0.10.8
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.
- data/ChangeLog +5 -0
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/bin/fluent-scribe-remote +2 -1
- data/fluent-plugin-scribe.gemspec +11 -11
- data/lib/fluent/plugin/in_scribe.rb +39 -31
- data/test/plugin/in_scribe.rb +56 -0
- metadata +17 -7
data/ChangeLog
CHANGED
data/README.rdoc
CHANGED
@@ -54,6 +54,7 @@ These options are supported.
|
|
54
54
|
* server_type: server architecture either in 'simple', 'threaded', 'thread_pool', 'nonblocking' (default: nonblocking)
|
55
55
|
* is_framed: use framed protocol or not (default: true)
|
56
56
|
* add_prefix: prefix string, added to the tag (default: nil)
|
57
|
+
* msg_format: format of the messages either in 'text', 'json', 'url_param' (default: text)
|
57
58
|
|
58
59
|
=== Scribe Output
|
59
60
|
|
@@ -73,6 +74,7 @@ These options are supported.
|
|
73
74
|
* port: port number (default: 1463)
|
74
75
|
* field_ref: field name which sent as scribe log message (default: message)
|
75
76
|
* timeout: thrift protocol timeout (default: 30)
|
77
|
+
* body_format: parse a body message as a specified format (default: 'text', option: 'json')
|
76
78
|
* remove_prefix: prefix string, removed from the tag (default: nil)
|
77
79
|
|
78
80
|
== For Developers
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.10.
|
1
|
+
0.10.8
|
data/bin/fluent-scribe-remote
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'thrift'
|
3
|
+
require 'json'
|
3
4
|
$:.unshift File.join(File.dirname(__FILE__), '../lib/fluent/plugin/thrift')
|
4
5
|
require 'fb303_types'
|
5
6
|
require 'fb303_constants'
|
@@ -24,7 +25,7 @@ raw_sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
|
|
24
25
|
|
25
26
|
entry = LogEntry.new
|
26
27
|
entry.category = 'debug.hoge'
|
27
|
-
entry.message = '
|
28
|
+
entry.message = {'a' => 'b'}.to_json
|
28
29
|
p client.Log([entry])
|
29
30
|
|
30
31
|
transport.close
|
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.10.
|
7
|
+
s.name = "fluent-plugin-scribe"
|
8
|
+
s.version = "0.10.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date =
|
13
|
-
s.email =
|
14
|
-
s.executables = [
|
11
|
+
s.authors = ["Kazuki Ohta"]
|
12
|
+
s.date = "2012-04-27"
|
13
|
+
s.email = "kazuki.ohta@gmail.com"
|
14
|
+
s.executables = ["fluent-scribe-remote"]
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"ChangeLog",
|
17
17
|
"README.rdoc"
|
@@ -36,11 +36,11 @@ Gem::Specification.new do |s|
|
|
36
36
|
"test/plugin/in_scribe.rb",
|
37
37
|
"test/plugin/out_scribe.rb"
|
38
38
|
]
|
39
|
-
s.homepage =
|
40
|
-
s.require_paths = [
|
41
|
-
s.rubygems_version =
|
42
|
-
s.summary =
|
43
|
-
s.test_files = [
|
39
|
+
s.homepage = "https://github.com/fluent/fluent-plugin-scribe"
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = "1.8.21"
|
42
|
+
s.summary = "Scribe Input/Output plugin for Fluentd event collector"
|
43
|
+
s.test_files = ["test/plugin/in_scribe.rb", "test/plugin/out_scribe.rb"]
|
44
44
|
|
45
45
|
if s.respond_to? :specification_version then
|
46
46
|
s.specification_version = 3
|
@@ -27,8 +27,10 @@ class ScribeInput < Input
|
|
27
27
|
config_param :body_size_limit, :size, :default => 32*1024*1024 # TODO default
|
28
28
|
config_param :add_prefix, :string, :default => nil
|
29
29
|
config_param :remove_newline, :bool, :default => false
|
30
|
+
config_param :msg_format, :string, :default => 'text'
|
30
31
|
|
31
32
|
def initialize
|
33
|
+
require 'cgi'
|
32
34
|
require 'thrift'
|
33
35
|
$:.unshift File.join(File.dirname(__FILE__), 'thrift')
|
34
36
|
require 'fb303_types'
|
@@ -50,6 +52,7 @@ class ScribeInput < Input
|
|
50
52
|
handler = FluentScribeHandler.new
|
51
53
|
handler.add_prefix = @add_prefix
|
52
54
|
handler.remove_newline = @remove_newline
|
55
|
+
handler.msg_format = @msg_format
|
53
56
|
processor = Scribe::Processor.new handler
|
54
57
|
|
55
58
|
@transport = Thrift::ServerSocket.new @bind, @port
|
@@ -59,6 +62,10 @@ class ScribeInput < Input
|
|
59
62
|
transport_factory = Thrift::BufferedTransportFactory.new
|
60
63
|
end
|
61
64
|
|
65
|
+
unless ['text', 'json', 'url_param'].include? @msg_format
|
66
|
+
raise 'Unknown format: msg_format=#{@msg_format}'
|
67
|
+
end
|
68
|
+
|
62
69
|
# 2011/09/29 Kazuki Ohta <kazuki.ohta@gmail.com>
|
63
70
|
# This section is a workaround to set strict_read and strict_write option.
|
64
71
|
# Ruby-Thrift 0.7 set them both 'true' in default, but Scribe protocol set
|
@@ -102,42 +109,18 @@ class ScribeInput < Input
|
|
102
109
|
class FluentScribeHandler
|
103
110
|
attr_accessor :add_prefix
|
104
111
|
attr_accessor :remove_newline
|
112
|
+
attr_accessor :msg_format
|
105
113
|
|
106
114
|
def Log(msgs)
|
107
115
|
begin
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
'message' => msg.message.force_encoding('UTF-8').chomp
|
113
|
-
}
|
114
|
-
Engine.emit(@add_prefix + '.' + msg.category, Engine.now, record)
|
115
|
-
}
|
116
|
-
else
|
117
|
-
msgs.each { |msg|
|
118
|
-
record = {
|
119
|
-
'message' => msg.message.force_encoding('UTF-8')
|
120
|
-
}
|
121
|
-
Engine.emit(@add_prefix + '.' + msg.category, Engine.now, record)
|
122
|
-
}
|
123
|
-
end
|
124
|
-
else
|
125
|
-
if @remove_newline
|
126
|
-
msgs.each { |msg|
|
127
|
-
record = {
|
128
|
-
'message' => msg.message.force_encoding('UTF-8').chomp
|
129
|
-
}
|
130
|
-
Engine.emit(msg.category, Engine.now, record)
|
131
|
-
}
|
116
|
+
msgs.each { |msg|
|
117
|
+
record = create_record(msg)
|
118
|
+
if @add_prefix
|
119
|
+
Engine.emit(@add_prefix + '.' + msg.category, Engine.now, record)
|
132
120
|
else
|
133
|
-
|
134
|
-
record = {
|
135
|
-
'message' => msg.message.force_encoding('UTF-8')
|
136
|
-
}
|
137
|
-
Engine.emit(msg.category, Engine.now, record)
|
138
|
-
}
|
121
|
+
Engine.emit(msg.category, Engine.now, record)
|
139
122
|
end
|
140
|
-
|
123
|
+
}
|
141
124
|
return ResultCode::OK
|
142
125
|
rescue => e
|
143
126
|
$log.error "unexpected error", :error=>$!.to_s
|
@@ -145,6 +128,31 @@ class ScribeInput < Input
|
|
145
128
|
return ResultCode::TRY_LATER
|
146
129
|
end
|
147
130
|
end
|
131
|
+
|
132
|
+
private
|
133
|
+
def create_record(msg)
|
134
|
+
case @msg_format
|
135
|
+
when 'text'
|
136
|
+
if @remove_newline
|
137
|
+
return { 'message' => msg.message.force_encoding('UTF-8').chomp }
|
138
|
+
else
|
139
|
+
return { 'message' => msg.message.force_encoding('UTF-8') }
|
140
|
+
end
|
141
|
+
when 'json'
|
142
|
+
js = JSON.parse(msg.message.force_encoding('UTF-8'))
|
143
|
+
raise 'body must be a Hash, if json_body=true' unless js.is_a?(Hash)
|
144
|
+
return js
|
145
|
+
when 'url_param'
|
146
|
+
s = msg.message.force_encoding('UTF-8')
|
147
|
+
return Hash[ s.split('&').map { |kv|
|
148
|
+
k,v = kv.split('=', 2);
|
149
|
+
[CGI.unescape(k), CGI.unescape(v)]
|
150
|
+
}
|
151
|
+
]
|
152
|
+
else
|
153
|
+
raise 'Invalid format: #{@msg_format}'
|
154
|
+
end
|
155
|
+
end
|
148
156
|
end
|
149
157
|
end
|
150
158
|
|
data/test/plugin/in_scribe.rb
CHANGED
@@ -114,6 +114,62 @@ class ScribeInputTest < Test::Unit::TestCase
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
+
def test_msg_format_json
|
118
|
+
d = create_driver(CONFIG + %[
|
119
|
+
msg_format json
|
120
|
+
])
|
121
|
+
assert_equal 'json', d.instance.msg_format
|
122
|
+
|
123
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
124
|
+
Fluent::Engine.now = time
|
125
|
+
|
126
|
+
d.expect_emit "tag1", time, {"a"=>1}
|
127
|
+
d.expect_emit "tag2", time, {"a"=>1, "b"=>2}
|
128
|
+
d.expect_emit "tag3", time, {"a"=>1, "b"=>2, "c"=>3}
|
129
|
+
|
130
|
+
emits = [
|
131
|
+
['tag1', time, {"a"=>1}.to_json],
|
132
|
+
['tag2', time, {"a"=>1, "b"=>2}.to_json],
|
133
|
+
['tag3', time, {"a"=>1, "b"=>2, "c"=>3}.to_json],
|
134
|
+
]
|
135
|
+
d.run do
|
136
|
+
emits.each { |tag, time, message|
|
137
|
+
res = send(tag, message)
|
138
|
+
assert_equal ResultCode::OK, res
|
139
|
+
}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_msg_format_url_param
|
144
|
+
d = create_driver(CONFIG + %[
|
145
|
+
msg_format url_param
|
146
|
+
])
|
147
|
+
assert_equal 'url_param', d.instance.msg_format
|
148
|
+
|
149
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
150
|
+
Fluent::Engine.now = time
|
151
|
+
|
152
|
+
d.expect_emit "tag0", time, {}
|
153
|
+
d.expect_emit "tag1", time, {"a"=>'1'}
|
154
|
+
d.expect_emit "tag2", time, {"a"=>'1', "b"=>'2'}
|
155
|
+
d.expect_emit "tag3", time, {"a"=>'1', "b"=>'2', "c"=>'3'}
|
156
|
+
d.expect_emit "tag4", time, {"a"=>'1', "b"=>'2', "c"=>'3=4'}
|
157
|
+
|
158
|
+
emits = [
|
159
|
+
['tag0', time, ""],
|
160
|
+
['tag1', time, "a=1"],
|
161
|
+
['tag2', time, "a=1&b=2"],
|
162
|
+
['tag3', time, "a=1&b=2&c=3"],
|
163
|
+
['tag4', time, "a=1&b=2&c=3=4"],
|
164
|
+
]
|
165
|
+
d.run do
|
166
|
+
emits.each { |tag, time, message|
|
167
|
+
res = send(tag, message)
|
168
|
+
assert_equal ResultCode::OK, res
|
169
|
+
}
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
117
173
|
def send(tag, msg)
|
118
174
|
socket = Thrift::Socket.new '127.0.0.1', 14630
|
119
175
|
transport = Thrift::FramedTransport.new socket
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-scribe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 0.10.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: thrift
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: 0.8.0
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.0
|
36
46
|
description:
|
37
47
|
email: kazuki.ohta@gmail.com
|
38
48
|
executables:
|
@@ -82,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
92
|
version: '0'
|
83
93
|
requirements: []
|
84
94
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.8.
|
95
|
+
rubygems_version: 1.8.21
|
86
96
|
signing_key:
|
87
97
|
specification_version: 3
|
88
98
|
summary: Scribe Input/Output plugin for Fluentd event collector
|