fluent-plugin-eventcounter 0.0.3 → 0.0.4
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/README.md +16 -8
- data/fluent-plugin-eventcounter.gemspec +1 -1
- data/lib/fluent/plugin/out_eventcounter.rb +10 -9
- data/spec/out_eventcounter_spec.rb +32 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -35,7 +35,7 @@ With a conf like
|
|
35
35
|
You would get
|
36
36
|
|
37
37
|
```
|
38
|
-
event.counts { 12086: { 'seen': 2, 'liked': 1, 'clicked:http://example.com/
|
38
|
+
event.counts { 12086: { 'seen': 2, 'liked': 1, 'clicked:http://example.com/promote': 2 } }
|
39
39
|
event.counts { 1337: { 'seen': 1 } }
|
40
40
|
```
|
41
41
|
|
@@ -56,6 +56,8 @@ or
|
|
56
56
|
|
57
57
|
###Parameters
|
58
58
|
|
59
|
+
#### Basic
|
60
|
+
|
59
61
|
- **count_key** (**required**)
|
60
62
|
- The key within the record to count unique instances of
|
61
63
|
- *eg. event*
|
@@ -71,6 +73,18 @@ or
|
|
71
73
|
- **emit_to** (optional) - *string*
|
72
74
|
- Tag to re-emit with
|
73
75
|
- *default: debug.events*
|
76
|
+
|
77
|
+
#### Extra Capture (optional)
|
78
|
+
|
79
|
+
- **capture_extra_if** (optional)
|
80
|
+
- An additional field to attach to the captured key
|
81
|
+
- *default: nil*
|
82
|
+
|
83
|
+
- **capture_extra_replace** (optional)
|
84
|
+
- A regular expression to replace a portion of the extra capture. *(note: this is passed as a string and parsed as a regex so be aware that you may need to escape reserved characters to preserve their meaning.)*
|
85
|
+
- *default: ''*
|
86
|
+
|
87
|
+
#### Redis Config (optional)
|
74
88
|
|
75
89
|
- **redis_host** (optional) - *string*
|
76
90
|
- Host address of the redis server
|
@@ -92,13 +106,7 @@ or
|
|
92
106
|
- The key to prefix against the tag
|
93
107
|
- *default: ''*
|
94
108
|
|
95
|
-
|
96
|
-
- An additional field to attach to the captured key
|
97
|
-
- *default: nil*
|
98
|
-
|
99
|
-
- **capture_extra_replace** (optional)
|
100
|
-
- A regular expression to replace a portion of the extra capture
|
101
|
-
- *default: ''*
|
109
|
+
#### Other
|
102
110
|
|
103
111
|
- **flush_interval** (optional)
|
104
112
|
- Provided from **Fluent::BufferedOutput** time in seconds between flushes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = "fluent-plugin-eventcounter"
|
4
|
-
gem.version = "0.0.
|
4
|
+
gem.version = "0.0.4"
|
5
5
|
gem.authors = ["Sean Dick", "Change.org"]
|
6
6
|
gem.email = ["sean@change.org"]
|
7
7
|
gem.homepage = "https://github.com/change/fluent-plugin-eventcounter"
|
@@ -17,6 +17,7 @@ class Fluent::EventCounterOutput < Fluent::BufferedOutput
|
|
17
17
|
config_param :input_tag_exclude, :string, :default => ''
|
18
18
|
config_param :capture_extra_if, :string, :default => nil
|
19
19
|
config_param :capture_extra_replace, :string, :default => ''
|
20
|
+
config_param :debug_emit, :boolean, :default => false
|
20
21
|
|
21
22
|
config_param :count_key, :string # REQUIRED
|
22
23
|
|
@@ -58,18 +59,18 @@ class Fluent::EventCounterOutput < Fluent::BufferedOutput
|
|
58
59
|
counts[key][event] += 1
|
59
60
|
end
|
60
61
|
end
|
61
|
-
if @emit_only
|
62
|
+
if @debug_emit || @emit_only
|
62
63
|
counts.each do |tag, events|
|
63
64
|
Fluent::Engine.emit(@emit_to, Time.now, tag => events)
|
64
65
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
66
|
+
return if @emit_only
|
67
|
+
end
|
68
|
+
@redis.pipelined do
|
69
|
+
counts.each do |tag,events|
|
70
|
+
events.each do |event, c|
|
71
|
+
redis_key = [@redis_output_key,tag].join(':')
|
72
|
+
@redis.hincrby(redis_key, event, c.to_i)
|
73
|
+
end
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
@@ -75,4 +75,36 @@ describe Fluent::EventCounterOutput do
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
describe 'output' do
|
80
|
+
let (:conf) {
|
81
|
+
%[
|
82
|
+
count_key event
|
83
|
+
capture_extra_if url
|
84
|
+
capture_extra_replace \\?.*$
|
85
|
+
emit_only true
|
86
|
+
]
|
87
|
+
}
|
88
|
+
let (:input) {
|
89
|
+
%[{"email": "john.doe@example.com", "timestamp": "1337197600", "smtp-id": "<4FB4041F.6080505@example.com>", "event": "processed", "local_record_id": "11"}
|
90
|
+
{"email": "john.doe@example.com", "timestamp": "1337966815", "category": "newuser", "event": "click", "url": "http://example.com?foo=bar&baz=quux", "local_record_id": "72"}
|
91
|
+
{"email": "john.doe@example.com", "timestamp": "1337969592", "smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>", "event": "processed", "local_record_id": "72"}
|
92
|
+
{"email": "john.doe@example.com", "timestamp": "1337197600", "smtp-id": "<4FB4041F.6080505@example.com>", "event": "processed", "local_record_id": "72"}
|
93
|
+
{"email": "john.doe@example.com", "timestamp": "1337966815", "category": "newuser", "event": "click", "url": "http://example.com?blop=spop", "local_record_id": "72"}
|
94
|
+
{"email": "john.doe@example.com", "timestamp": "1337969592", "smtp-id": "<20120525181309.C1A9B40405B3@Example-Mac.local>", "event": "processed", "local_record_id": "72"}]
|
95
|
+
}
|
96
|
+
let (:eventcounter) { Fluent::Test::BufferedOutputTestDriver.new(Fluent::EventCounterOutput.new).configure(conf) }
|
97
|
+
|
98
|
+
it "formats the counts against the provided tag" do
|
99
|
+
eventcounter.tag = 'test'
|
100
|
+
input.split("\n").each do |line|
|
101
|
+
data = JSON.parse line
|
102
|
+
eventcounter.emit data, Time.now
|
103
|
+
end
|
104
|
+
output = eventcounter.run['test']
|
105
|
+
|
106
|
+
expect(output['processed']).to eq 4
|
107
|
+
expect(output['click:http://example.com']).to eq 2
|
108
|
+
end
|
109
|
+
end
|
78
110
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-eventcounter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-10-
|
13
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fluentd
|