fluent-plugin-memcached 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da645ae2f7d674fe83ee1c49746d5f27e391af15
4
- data.tar.gz: ab6d4e05276efecf24f1d97f9e2169970e08bda2
3
+ metadata.gz: ecd435b2a7544144b0d4491bf27dcdbde3983616
4
+ data.tar.gz: 7ba5ef4be3af483784dbe95a09215bb85a2cad36
5
5
  SHA512:
6
- metadata.gz: 7e44da1a22c1f1534934c57ee2595176b1607b2077862d4400530d7763f8302595437692cea143b91d9a8e816638f2d238db9aed4113fe82e00f05a8bbfcc7be
7
- data.tar.gz: 037e6872ef6b7a42be7083a250161dde433daf8576e82f62099f302b14c9650d5234842461bddd05d4fb8a894c2373b3468f8f5b74d8d3a39108d4d62c17220d
6
+ metadata.gz: 1e45543bc50066e97449d032c5e40455471dda3c85fa4f3154e45ae25071f33a13548227282e5a916396568d28747a845cf124054d9edeb565146b57e8d2f5ec
7
+ data.tar.gz: 086c2879c5f2c9bcd366ed14c3483a7f8049a3985ff503a78fdf802d66feb6046b43ad55a985cf3c593fba2e499ce0dbd5d61f7578f237b4bf76b7eefe4f781b
data/README.md CHANGED
@@ -20,11 +20,12 @@ Default values would look like this:
20
20
  type memcached
21
21
  host localhost
22
22
  port 11211
23
+ increment false
23
24
  # value_separater " "
24
25
  </match>
25
26
  ```
26
27
 
27
- To save json, like this:
28
+ To store values as json, like this:
28
29
 
29
30
  ```
30
31
  <match dummy>
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "fluent-plugin-memcached"
7
- gem.version = "0.0.6"
7
+ gem.version = "0.0.7"
8
8
  gem.authors = ["innossh"]
9
9
  gem.email = ["innossh@users.noreply.github.com"]
10
10
 
@@ -4,7 +4,9 @@ class Fluent::MemcachedOutput < Fluent::BufferedOutput
4
4
  config_param :host, :string, :default => 'localhost'
5
5
  config_param :port, :integer, :default => 11211
6
6
 
7
+ config_param :increment, :bool, :default => false
7
8
  config_param :value_separater, :string, :default => ' '
9
+
8
10
  config_param :value_format, :string, :default => 'raw'
9
11
  config_param :param_names, :string, :default => nil # nil doesn't allowed for json
10
12
 
@@ -21,7 +23,7 @@ class Fluent::MemcachedOutput < Fluent::BufferedOutput
21
23
  if @value_format == 'json' and @param_names.nil?
22
24
  raise Fluent::ConfigError, "param_names MUST be specified in the case of json format"
23
25
  end
24
- @formatter = RecordValueFormatter.new(@value_separater, @value_format, @param_names)
26
+ @formatter = RecordValueFormatter.new(@increment, @value_separater, @value_format, @param_names)
25
27
  end
26
28
 
27
29
  def start
@@ -39,16 +41,29 @@ class Fluent::MemcachedOutput < Fluent::BufferedOutput
39
41
 
40
42
  def write(chunk)
41
43
  chunk.msgpack_each { |tag, time, record|
42
- @memcached.set @formatter.key(record), @formatter.value(record)
44
+ key = @formatter.key(record)
45
+ value = @formatter.value(record)
46
+ if @increment
47
+ if @memcached.get(key) == nil
48
+ # initialize increment value
49
+ @memcached.incr(key, 1, nil, 0)
50
+ end
51
+ @memcached.incr(key, amt=value)
52
+
53
+ else
54
+ @memcached.set(key, value)
55
+ end
43
56
  }
44
57
  end
45
58
 
46
59
  class RecordValueFormatter
60
+ attr_reader :increment
47
61
  attr_reader :value_separater
48
62
  attr_reader :value_format
49
63
  attr_reader :param_names
50
64
 
51
- def initialize(value_separater, value_format, param_names)
65
+ def initialize(increment, value_separater, value_format, param_names)
66
+ @increment = increment
52
67
  @value_separater = value_separater
53
68
  @value_format = value_format
54
69
  @param_names = param_names
@@ -59,16 +74,18 @@ class Fluent::MemcachedOutput < Fluent::BufferedOutput
59
74
  end
60
75
 
61
76
  def value(record)
77
+ values = record.values.drop(1)
62
78
  case @value_format
63
79
  when 'json'
64
- values = record.values.drop(1)
65
80
  hash = {}
66
81
  @param_names.split(/\s*,\s*/).each_with_index { |param_name, i|
67
82
  hash[param_name] = (i > values.size - 1) ? nil : values[i]
68
83
  }
69
84
  hash.to_json
70
85
  else
71
- record.values.drop(1).join(@value_separater)
86
+ return values.first.to_i if @increment
87
+
88
+ values.join(@value_separater)
72
89
  end
73
90
  end
74
91
  end
@@ -19,6 +19,12 @@ class MemcachedOutputTest < Test::Unit::TestCase
19
19
  param_names param1,param2
20
20
  ]
21
21
 
22
+ CONFIG_INCREMENT = %[
23
+ host 127.0.0.1
24
+ port 11211
25
+ increment true
26
+ ]
27
+
22
28
  CONFIG_MYSQL = %[
23
29
  host 127.0.0.1
24
30
  port 11211
@@ -33,6 +39,7 @@ class MemcachedOutputTest < Test::Unit::TestCase
33
39
  d = create_driver('')
34
40
  assert_equal 'localhost', d.instance.host
35
41
  assert_equal 11211, d.instance.port
42
+ assert_equal false, d.instance.increment
36
43
  assert_equal ' ', d.instance.value_separater
37
44
 
38
45
  d = create_driver
@@ -53,6 +60,11 @@ class MemcachedOutputTest < Test::Unit::TestCase
53
60
  ]
54
61
  }
55
62
 
63
+ d = create_driver(CONFIG_INCREMENT)
64
+ assert_equal '127.0.0.1', d.instance.host
65
+ assert_equal 11211, d.instance.port
66
+ assert_equal true, d.instance.increment
67
+
56
68
  d = create_driver(CONFIG_MYSQL)
57
69
  assert_equal '127.0.0.1', d.instance.host
58
70
  assert_equal 11211, d.instance.port
@@ -96,6 +108,23 @@ class MemcachedOutputTest < Test::Unit::TestCase
96
108
  assert_equal record2_value_json, d.instance.memcached.get('d')
97
109
  end
98
110
 
111
+ def test_write_increment
112
+ d = create_driver(CONFIG_INCREMENT)
113
+ time = Time.parse('2011-01-02 13:14:15 UTC').to_i
114
+ record1 = {'key' => 'count1', 'param1' => 1}
115
+ record2 = {'key' => 'count2', 'param1' => 2}
116
+ record3 = {'key' => 'count1', 'param1' => 3}
117
+ record4 = {'key' => 'count2', 'param1' => 4}
118
+ d.emit(record1, time)
119
+ d.emit(record2, time)
120
+ d.emit(record3, time)
121
+ d.emit(record4, time)
122
+ d.run
123
+
124
+ assert_equal (1 + 3), d.instance.memcached.get('count1').to_i
125
+ assert_equal (2 + 4), d.instance.memcached.get('count2').to_i
126
+ end
127
+
99
128
  def test_write_to_mysql
100
129
  d = create_driver(CONFIG_MYSQL)
101
130
  time = Time.parse('2011-01-02 13:14:15 UTC').to_i
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.6
4
+ version: 0.0.7
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-28 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd