fluent-plugin-redis-multi-type-counter 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +9 -0
- data/VERSION +1 -1
- data/fluent-plugin-redis-multi-type-counter.gemspec +1 -1
- data/lib/fluent/plugin/out_redis_multi_type_counter.rb +31 -7
- data/test/plugin/out_redis_multi_type_counter.rb +52 -1
- metadata +10 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7575f5b2b303087dc3c5cd93e6fc29925fef2252
|
|
4
|
+
data.tar.gz: d2b6edb521e0f2a5c5454cd8baa9f725a1dbca32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5258c43359764c43b2e5348ae9348e007bd79ebf99869a99cfbb015de4d2f90b56493430d3b362be81e79c17aefdc77b6850934fa2cd1f7f4cc880469ec7a88c
|
|
7
|
+
data.tar.gz: 3edef69b27cf3f00c7d1b1de92316455d55745c0d1134df526aa6ec50396b4e3d41d4b70bf7a3f17017967486e2cd92de17464aa6eb647bc72a8be5933d0c083
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
[](https://waffle.io/HeartSaVioR/fluent-plugin-redis-multi-type-counter)
|
|
1
2
|
# Redis multi-type counter plugin for fluent [](https://travis-ci.org/HeartSaVioR/fluent-plugin-redis-multi-type-counter)
|
|
2
3
|
|
|
3
4
|
fluent-plugin-redis-multi-type-counter is a fluent plugin to count-up/down redis keys, hash, sorted set.
|
|
@@ -50,6 +51,14 @@ fluent-plugin-redis-multi-type-counter is hosted by [RubyGems.org](https://rubyg
|
|
|
50
51
|
count_key_format customer:%_{customer_id}:status2xx-%Y-%m-%d
|
|
51
52
|
</pattern>
|
|
52
53
|
|
|
54
|
+
# you can just store value to list (not counting on, it's something awkward) by store_list to true
|
|
55
|
+
# note that you cannot use store_list with hash or zset
|
|
56
|
+
<pattern>
|
|
57
|
+
match_status ^2[0-9][0-9]$
|
|
58
|
+
count_key_format customer:%_{customer_id}:status2xx-%Y-%m-%d
|
|
59
|
+
store_list true
|
|
60
|
+
</pattern>
|
|
61
|
+
|
|
53
62
|
# you can also sum up key in hash, by configuring count_hash_key_format
|
|
54
63
|
# syntax is same to count_key_format
|
|
55
64
|
# for example, {"custom_id": 123, "date": "20131219" ...}.
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.3
|
|
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "fluent-plugin-redis-multi-type-counter"
|
|
6
|
-
s.version = "0.1.
|
|
6
|
+
s.version = "0.1.3"
|
|
7
7
|
s.description = "fluent-plugin-redis-multi-type-counter is a fluent plugin to count-up/down redis keys, hash keys, zset keys"
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
9
|
s.authors = ["Jungtaek Lim"]
|
|
@@ -59,9 +59,18 @@ module Fluent
|
|
|
59
59
|
count_key = pattern.get_count_key(time, record)
|
|
60
60
|
count_hash_key = pattern.get_count_hash_key(record)
|
|
61
61
|
count_zset_key = pattern.get_count_zset_key(record)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
store_list = pattern.store_list
|
|
63
|
+
|
|
64
|
+
key = RecordKey.new(count_key, count_hash_key, count_zset_key, store_list)
|
|
65
|
+
if store_list
|
|
66
|
+
if table[key] == 0
|
|
67
|
+
table[key] = []
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
table[key] << pattern.get_count_value(record)
|
|
71
|
+
else
|
|
72
|
+
table[key] += pattern.get_count_value(record)
|
|
73
|
+
end
|
|
65
74
|
}
|
|
66
75
|
}
|
|
67
76
|
rescue EOFError
|
|
@@ -79,7 +88,11 @@ module Fluent
|
|
|
79
88
|
elsif key.count_zset_key != nil
|
|
80
89
|
@redis.zincrby(key.count_key, value, key.count_zset_key)
|
|
81
90
|
else
|
|
82
|
-
|
|
91
|
+
if key.store_list
|
|
92
|
+
@redis.rpush(key.count_key, value)
|
|
93
|
+
else
|
|
94
|
+
@redis.incrby(key.count_key, value)
|
|
95
|
+
end
|
|
83
96
|
end
|
|
84
97
|
end
|
|
85
98
|
end
|
|
@@ -87,12 +100,13 @@ module Fluent
|
|
|
87
100
|
end
|
|
88
101
|
|
|
89
102
|
class RecordKey
|
|
90
|
-
attr_reader :count_key, :count_hash_key, :count_zset_key
|
|
103
|
+
attr_reader :count_key, :count_hash_key, :count_zset_key, :store_list
|
|
91
104
|
|
|
92
|
-
def initialize(count_key, count_hash_key, count_zset_key)
|
|
105
|
+
def initialize(count_key, count_hash_key, count_zset_key, store_list)
|
|
93
106
|
@count_key = count_key
|
|
94
107
|
@count_hash_key = count_hash_key
|
|
95
108
|
@count_zset_key = count_zset_key
|
|
109
|
+
@store_list = store_list
|
|
96
110
|
end
|
|
97
111
|
|
|
98
112
|
def hash
|
|
@@ -133,7 +147,7 @@ module Fluent
|
|
|
133
147
|
end
|
|
134
148
|
|
|
135
149
|
class Pattern
|
|
136
|
-
attr_reader :matches, :count_value, :count_value_key
|
|
150
|
+
attr_reader :matches, :count_value, :count_value_key, :store_list
|
|
137
151
|
|
|
138
152
|
def initialize(conf_element)
|
|
139
153
|
if !conf_element.has_key?('count_key') && !conf_element.has_key?('count_key_format')
|
|
@@ -157,6 +171,16 @@ module Fluent
|
|
|
157
171
|
@record_formatter_for_count_key = RecordValueFormatter.new(@count_key_format[0])
|
|
158
172
|
end
|
|
159
173
|
|
|
174
|
+
@store_list = false
|
|
175
|
+
if conf_element.has_key?('store_list') && conf_element['store_list'].downcase == 'true'
|
|
176
|
+
@store_list = true
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
if @store_list && (conf_element.has_key?('count_hash_key_format') ||
|
|
180
|
+
conf_element.has_key?('count_zset_key_format'))
|
|
181
|
+
raise RedisMultiTypeCounterException, 'store_list is true, it should be normal type, not hash or zset'
|
|
182
|
+
end
|
|
183
|
+
|
|
160
184
|
if conf_element.has_key?('count_hash_key_format') && conf_element.has_key?('count_zset_key_format')
|
|
161
185
|
raise RedisMultiTypeCounterException, 'both "count_hash_key_format" "count_zset_key_format" are specified.'
|
|
162
186
|
end
|
|
@@ -20,6 +20,7 @@ class RedisMultiTypeCounterTest < Test::Unit::TestCase
|
|
|
20
20
|
redis.del("item_sum_count:200")
|
|
21
21
|
redis.del("item_sum_count_by_hash:200")
|
|
22
22
|
redis.del("item_sum_count_by_zset:200")
|
|
23
|
+
redis.del("item_list_count:200")
|
|
23
24
|
redis.quit
|
|
24
25
|
end
|
|
25
26
|
|
|
@@ -182,6 +183,36 @@ class RedisMultiTypeCounterTest < Test::Unit::TestCase
|
|
|
182
183
|
end
|
|
183
184
|
end
|
|
184
185
|
|
|
186
|
+
def test_configure_store_list_with_specified_hash_key
|
|
187
|
+
begin
|
|
188
|
+
create_driver %[
|
|
189
|
+
<pattern>
|
|
190
|
+
count_key_format %_{prefix}-foo-bar
|
|
191
|
+
store_list true
|
|
192
|
+
count_hash_key_format %_{host}-hash-key
|
|
193
|
+
</pattern>
|
|
194
|
+
]
|
|
195
|
+
flunk
|
|
196
|
+
rescue Fluent::ConfigError => e
|
|
197
|
+
assert_equal 'store_list is true, it should be normal type, not hash or zset', e.message
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def test_configure_store_list_with_specified_zset_key
|
|
202
|
+
begin
|
|
203
|
+
create_driver %[
|
|
204
|
+
<pattern>
|
|
205
|
+
count_key_format %_{prefix}-foo-bar
|
|
206
|
+
store_list true
|
|
207
|
+
count_zset_key_format %_{host}-zset-key
|
|
208
|
+
</pattern>
|
|
209
|
+
]
|
|
210
|
+
flunk
|
|
211
|
+
rescue Fluent::ConfigError => e
|
|
212
|
+
assert_equal 'store_list is true, it should be normal type, not hash or zset', e.message
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
185
216
|
def test_configure_invalid_count_value
|
|
186
217
|
begin
|
|
187
218
|
create_driver %[
|
|
@@ -330,7 +361,6 @@ class RedisMultiTypeCounterTest < Test::Unit::TestCase
|
|
|
330
361
|
assert_equal 2, driver.instance.redis.zscore("item_sum_count_by_zset:200", "US")
|
|
331
362
|
end
|
|
332
363
|
|
|
333
|
-
|
|
334
364
|
def test_write_with_count_value_key
|
|
335
365
|
driver = create_driver %[
|
|
336
366
|
db_number 1
|
|
@@ -369,4 +399,25 @@ class RedisMultiTypeCounterTest < Test::Unit::TestCase
|
|
|
369
399
|
assert_equal '123', driver.instance.redis.get("item_sum_count:200"), "it should be ignore when count_value_key is not number"
|
|
370
400
|
end
|
|
371
401
|
|
|
402
|
+
def test_write_with_store_list
|
|
403
|
+
driver = create_driver %[
|
|
404
|
+
db_number 1
|
|
405
|
+
<pattern>
|
|
406
|
+
count_key_format item_list_count:%_{item_id}
|
|
407
|
+
count_value_key count
|
|
408
|
+
store_list true
|
|
409
|
+
</pattern>
|
|
410
|
+
]
|
|
411
|
+
|
|
412
|
+
time = Time.parse('2012-06-21 03:01:00 UTC').to_i
|
|
413
|
+
driver.emit({"item_id" => 200, "count" => 123}, time)
|
|
414
|
+
driver.emit({"item_id" => 200, "count" => 456}, time)
|
|
415
|
+
driver.emit({"item_id" => 200, "count" => 789}, time)
|
|
416
|
+
driver.run
|
|
417
|
+
|
|
418
|
+
assert_equal 3, driver.instance.redis.llen("item_list_count:200")
|
|
419
|
+
assert_equal '123', driver.instance.redis.lindex("item_list_count:200", 0)
|
|
420
|
+
assert_equal '456', driver.instance.redis.lindex("item_list_count:200", 1)
|
|
421
|
+
assert_equal '789', driver.instance.redis.lindex("item_list_count:200", 2)
|
|
422
|
+
end
|
|
372
423
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluent-plugin-redis-multi-type-counter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jungtaek Lim
|
|
@@ -14,28 +14,28 @@ dependencies:
|
|
|
14
14
|
name: fluentd
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - ~>
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: 0.10.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - ~>
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: 0.10.0
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: redis
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: 2.2.2
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- -
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: 2.2.2
|
|
41
41
|
description: fluent-plugin-redis-multi-type-counter is a fluent plugin to count-up/down
|
|
@@ -45,8 +45,8 @@ executables: []
|
|
|
45
45
|
extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
|
47
47
|
files:
|
|
48
|
-
- .gitignore
|
|
49
|
-
- .travis.yml
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- ".travis.yml"
|
|
50
50
|
- CHANGELOG.md
|
|
51
51
|
- Gemfile
|
|
52
52
|
- README.md
|
|
@@ -66,17 +66,17 @@ require_paths:
|
|
|
66
66
|
- lib
|
|
67
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
68
|
requirements:
|
|
69
|
-
- -
|
|
69
|
+
- - ">="
|
|
70
70
|
- !ruby/object:Gem::Version
|
|
71
71
|
version: '0'
|
|
72
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements:
|
|
74
|
-
- -
|
|
74
|
+
- - ">="
|
|
75
75
|
- !ruby/object:Gem::Version
|
|
76
76
|
version: '0'
|
|
77
77
|
requirements: []
|
|
78
78
|
rubyforge_project:
|
|
79
|
-
rubygems_version: 2.
|
|
79
|
+
rubygems_version: 2.2.2
|
|
80
80
|
signing_key:
|
|
81
81
|
specification_version: 4
|
|
82
82
|
summary: Redis multi type counter plugin for fluent
|