fluent-plugin-memcached 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/fluent-plugin-memcached.gemspec +1 -1
- data/lib/fluent/plugin/out_memcached.rb +42 -6
- data/test/plugin/test_out_memcached.rb +41 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 687484353d1845d26e83e4317d0fb046afe7825a
|
4
|
+
data.tar.gz: 1ee6c8f8a305578685e56989ec85ae27472e0cd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b711578a988b4e8e199cd921b4f84deaac9426c9a4537936393132237adc1676f746fe14c06f5787d11dc28e0231b794158328c5d68badfc144ae967d0ea1485
|
7
|
+
data.tar.gz: e312cca1312d2cd41e297544c5b5710f8eb83578697fe5f6fda995fbb24abe81f8401ab2e2cdc6a09c29344922d127250480904cd159e5171b7217de6260f1f4
|
data/README.md
CHANGED
@@ -23,6 +23,18 @@ Default values would look like this:
|
|
23
23
|
</match>
|
24
24
|
```
|
25
25
|
|
26
|
+
To save json, like this:
|
27
|
+
|
28
|
+
```
|
29
|
+
<match dummy>
|
30
|
+
type memcached
|
31
|
+
host localhost
|
32
|
+
port 11211
|
33
|
+
value_format json
|
34
|
+
param_names param1,param2
|
35
|
+
</match>
|
36
|
+
```
|
37
|
+
|
26
38
|
## Contributing
|
27
39
|
|
28
40
|
Bug reports and pull requests are welcome.
|
@@ -1,6 +1,14 @@
|
|
1
1
|
class Fluent::MemcachedOutput < Fluent::BufferedOutput
|
2
2
|
Fluent::Plugin.register_output('memcached', self)
|
3
|
-
|
3
|
+
|
4
|
+
config_param :host, :string, :default => 'localhost'
|
5
|
+
config_param :port, :integer, :default => 11211
|
6
|
+
|
7
|
+
config_param :value_format, :string, :default => 'raw'
|
8
|
+
config_param :param_names, :string, :default => nil # nil doesn't allowed for json
|
9
|
+
|
10
|
+
attr_accessor :memcached
|
11
|
+
attr_accessor :formatter
|
4
12
|
|
5
13
|
def initialize
|
6
14
|
super
|
@@ -9,8 +17,10 @@ class Fluent::MemcachedOutput < Fluent::BufferedOutput
|
|
9
17
|
|
10
18
|
def configure(conf)
|
11
19
|
super
|
12
|
-
@
|
13
|
-
|
20
|
+
if @value_format == 'json' and @param_names.nil?
|
21
|
+
raise Fluent::ConfigError, "param_names MUST be specified in the case of json format"
|
22
|
+
end
|
23
|
+
@formatter = RecordValueFormatter.new(@value_format, @param_names)
|
14
24
|
end
|
15
25
|
|
16
26
|
def start
|
@@ -28,10 +38,36 @@ class Fluent::MemcachedOutput < Fluent::BufferedOutput
|
|
28
38
|
|
29
39
|
def write(chunk)
|
30
40
|
chunk.msgpack_each { |tag, time, record|
|
31
|
-
key
|
32
|
-
value = record.values.drop(1).join(' ')
|
33
|
-
@memcached.set key, value
|
41
|
+
@memcached.set @formatter.key(record), @formatter.value(record)
|
34
42
|
}
|
35
43
|
end
|
36
44
|
|
45
|
+
class RecordValueFormatter
|
46
|
+
attr_reader :value_format
|
47
|
+
attr_reader :param_names
|
48
|
+
|
49
|
+
def initialize(value_format, param_names)
|
50
|
+
@value_format = value_format
|
51
|
+
@param_names = param_names
|
52
|
+
end
|
53
|
+
|
54
|
+
def key(record)
|
55
|
+
record.values.first
|
56
|
+
end
|
57
|
+
|
58
|
+
def value(record)
|
59
|
+
case @value_format
|
60
|
+
when 'json'
|
61
|
+
values = record.values.drop(1)
|
62
|
+
hash = {}
|
63
|
+
@param_names.split(/\s*,\s*/).each_with_index { |param_name, i|
|
64
|
+
hash[param_name] = (i > values.size - 1) ? nil : values[i]
|
65
|
+
}
|
66
|
+
hash.to_json
|
67
|
+
else
|
68
|
+
record.values.drop(1).join(' ')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
37
73
|
end
|
@@ -12,6 +12,13 @@ class MemcachedOutputTest < Test::Unit::TestCase
|
|
12
12
|
port 11211
|
13
13
|
]
|
14
14
|
|
15
|
+
CONFIG_JSON = %[
|
16
|
+
host 127.0.0.1
|
17
|
+
port 11211
|
18
|
+
value_format json
|
19
|
+
param_names param1,param2
|
20
|
+
]
|
21
|
+
|
15
22
|
def create_driver(conf = CONFIG, tag='test')
|
16
23
|
Fluent::Test::BufferedOutputTestDriver.new(Fluent::MemcachedOutput, tag).configure(conf)
|
17
24
|
end
|
@@ -26,12 +33,27 @@ class MemcachedOutputTest < Test::Unit::TestCase
|
|
26
33
|
|
27
34
|
assert_equal '127.0.0.1', d.instance.host
|
28
35
|
assert_equal 11211, d.instance.port
|
36
|
+
|
37
|
+
d = create_driver(CONFIG_JSON)
|
38
|
+
|
39
|
+
assert_equal '127.0.0.1', d.instance.host
|
40
|
+
assert_equal 11211, d.instance.port
|
41
|
+
assert_equal 'json', d.instance.value_format
|
42
|
+
assert_equal 'param1,param2', d.instance.param_names
|
43
|
+
|
44
|
+
assert_raise(Fluent::ConfigError) {
|
45
|
+
create_driver %[
|
46
|
+
host 127.0.0.1
|
47
|
+
port 11211
|
48
|
+
value_format json
|
49
|
+
]
|
50
|
+
}
|
29
51
|
end
|
30
52
|
|
31
53
|
def test_format
|
32
54
|
d = create_driver
|
33
55
|
time = Time.parse('2011-01-02 13:14:15 UTC').to_i
|
34
|
-
record = {
|
56
|
+
record = {'key' => 'key', 'param1' => 'value'}
|
35
57
|
d.emit(record, time)
|
36
58
|
d.expect_format(['test', time, record].to_msgpack)
|
37
59
|
d.run
|
@@ -40,8 +62,8 @@ class MemcachedOutputTest < Test::Unit::TestCase
|
|
40
62
|
def test_write
|
41
63
|
d = create_driver
|
42
64
|
time = Time.parse('2011-01-02 13:14:15 UTC').to_i
|
43
|
-
record1 = {
|
44
|
-
record2 = {
|
65
|
+
record1 = {'key' => 'a', 'param1' => '1'}
|
66
|
+
record2 = {'key' => 'b', 'param1' => '2', 'param2' => '3'}
|
45
67
|
d.emit(record1, time)
|
46
68
|
d.emit(record2, time)
|
47
69
|
d.run
|
@@ -49,4 +71,20 @@ class MemcachedOutputTest < Test::Unit::TestCase
|
|
49
71
|
assert_equal '1', d.instance.memcached.get('a')
|
50
72
|
assert_equal '2 3', d.instance.memcached.get('b')
|
51
73
|
end
|
74
|
+
|
75
|
+
def test_write_json
|
76
|
+
d = create_driver(CONFIG_JSON)
|
77
|
+
time = Time.parse('2011-01-02 13:14:15 UTC').to_i
|
78
|
+
record1 = {'key' => 'c', 'param1' => '4'}
|
79
|
+
record2 = {'key' => 'd', 'param1' => '5', 'param2' => '6'}
|
80
|
+
record1_value_json = {'param1' => '4', 'param2' => nil}.to_json
|
81
|
+
record2_value_json = {'param1' => '5', 'param2' => '6'}.to_json
|
82
|
+
d.emit(record1, time)
|
83
|
+
d.emit(record2, time)
|
84
|
+
d.run
|
85
|
+
|
86
|
+
assert_equal record1_value_json, d.instance.memcached.get('c')
|
87
|
+
assert_equal record2_value_json, d.instance.memcached.get('d')
|
88
|
+
end
|
89
|
+
|
52
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-memcached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- innossh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|