fluent-plugin-eventlastvalue 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -32,10 +32,10 @@ With a conf like
32
32
  You would get
33
33
 
34
34
  ```
35
- output.lastvalue { 'id': 12345, 'count': 6 }
36
- output.lastvalue { 'id': 1337, 'count': 28 }
37
- output.lastvalue { 'id': 33864, 'count': 24 }
38
- output.lastvalue { 'id': 40555, 'count': 18 }
35
+ output.lastvalue { 'id': 12345, 'count': 6, 'time': 1413544860 }
36
+ output.lastvalue { 'id': 1337, 'count': 28, 'time': 1413544890 }
37
+ output.lastvalue { 'id': 33864, 'count': 24, 'time': 1413544830 }
38
+ output.lastvalue { 'id': 40555, 'count': 18, 'time': 1413544890 }
39
39
  ```
40
40
 
41
41
  ##Installation
@@ -55,11 +55,11 @@ or
55
55
 
56
56
  #### Basic
57
57
 
58
- - **id_key** (**required**)
58
+ - **id_key** (**default**:id)
59
59
  - The key within the record that identifies a group of events to select from.
60
60
 
61
- - **last_value_key** (**required**)
62
- - the key from whose values we want to record the last
61
+ - **last_value_key** (optional)
62
+ - the key from whose values we want to record the last, if present records sent that do not contain the key will be excluded.
63
63
 
64
64
  - **emit_to** (optional) - *string*
65
65
  - Tag to re-emit with
@@ -1,12 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-plugin-eventlastvalue"
4
- gem.version = "0.0.3"
5
- gem.authors = ["Michael Arick", "Change.org"]
6
- gem.email = ["marick@change.org"]
4
+ gem.version = "0.0.5"
5
+ gem.authors = ["Michael Arick", "Sean Dick", "Change.org"]
6
+ gem.email = ["marick@change.org", "sean@change.org"]
7
7
  gem.homepage = "https://github.com/change/fluent-plugin-eventlastvalue"
8
- gem.summary = %q{Fluentd plugin to find the last value in a time-period of a field and emit it or write it to redis}
9
- gem.description = %q{Fluentd plugin to find the last value in a time-period of a field and emit it or write it to redis}
8
+ gem.summary = %q{Fluentd plugin to find the last value in a time-period of a field and emit it}
9
+ gem.description = %q{Fluentd plugin to find the last value in a time-period of a field and emit it}
10
10
  gem.license = "MIT"
11
11
 
12
12
  gem.files = `git ls-files`.split("\n")
@@ -6,7 +6,7 @@ class Fluent::EventLastValueOutput < Fluent::BufferedOutput
6
6
 
7
7
  config_param :emit_to, :string, :default => 'debug.events'
8
8
  config_param :id_key, :string, :default => 'id'
9
- config_param :last_value_key, :string # REQUIRED
9
+ config_param :last_value_key, :string, :default => nil
10
10
  config_param :comparator_key, :string, :default => nil
11
11
 
12
12
  attr_accessor :last_values
@@ -20,8 +20,8 @@ class Fluent::EventLastValueOutput < Fluent::BufferedOutput
20
20
  end
21
21
 
22
22
  def format(tag, time, record)
23
- return '' unless record[@last_value_key]
24
- [record[@id_key], record[@last_value_key], (record[@comparator_key] || 0).to_f].to_json + "\n"
23
+ return '' unless @last_value_key && record[@last_value_key]
24
+ [record[@id_key], record, (record[@comparator_key] || 0).to_f].to_json + "\n"
25
25
  end
26
26
 
27
27
  def write(chunk)
@@ -38,8 +38,8 @@ class Fluent::EventLastValueOutput < Fluent::BufferedOutput
38
38
  end
39
39
  end
40
40
 
41
- last_values.each do |key, value|
42
- Fluent::Engine.emit(@emit_to, Time.now.to_i, @id_key => key, @last_value_key => value, 'ts' => Time.now.to_s)
41
+ last_values.each do |key, last_record|
42
+ Fluent::Engine.emit(@emit_to, Time.now.to_i, last_record)
43
43
  end
44
44
  end
45
45
  end
@@ -16,9 +16,11 @@ describe Fluent::EventLastValueOutput do
16
16
  let (:eventlastvalue) { Fluent::Test::BufferedOutputTestDriver.new(Fluent::EventLastValueOutput.new).configure(conf) }
17
17
  context 'the input contains the last_value key' do
18
18
  it 'produces the expected output' do
19
+ record = { 'id' => '4444', 'timestamp' => 123456789, 'count' => 12345 }
20
+
19
21
  eventlastvalue.tag = 'something'
20
- eventlastvalue.emit( { 'id' => '4444', 'timestamp' => 123456789, 'count' => 12345 }, Time.now )
21
- eventlastvalue.expect_format ["4444", 12345, 123456789].to_json + "\n"
22
+ eventlastvalue.emit( record, Time.now )
23
+ eventlastvalue.expect_format ["4444", record, record['timestamp'].to_f].to_json + "\n"
22
24
  eventlastvalue.run
23
25
  end
24
26
  end
@@ -58,7 +60,7 @@ describe Fluent::EventLastValueOutput do
58
60
  data = JSON.parse line
59
61
  eventlastvalue.emit data, Time.now
60
62
  output = eventlastvalue.run
61
- expect(output['1234']).to eq 12345
63
+ expect(output['1234']).to eq data
62
64
  end
63
65
 
64
66
  it "returns the latest count given the comparator key" do
@@ -66,9 +68,9 @@ describe Fluent::EventLastValueOutput do
66
68
  data = JSON.parse line
67
69
  eventlastvalue.emit data, Time.now
68
70
  end
69
-
71
+ expected = {"email" => "john.doe@example.com", "count" => 12340, "timestamp" => "6", "input_id" => "1234"}
70
72
  output = eventlastvalue.run
71
- expect(output['1234']).to eq 12340
73
+ expect(output['1234']).to eq expected
72
74
  end
73
75
  end
74
76
 
@@ -87,9 +89,9 @@ describe Fluent::EventLastValueOutput do
87
89
  data = JSON.parse line
88
90
  eventlastvalue.emit data, Time.now
89
91
  end
90
-
92
+ expected = {"email"=>"john.doe@example.com", "count"=>12349, "timestamp"=>"5", "input_id"=>"1234"}
91
93
  output = eventlastvalue.run
92
- expect(output['1234']).to eq 12349
94
+ expect(output['1234']).to eq expected
93
95
  end
94
96
  end
95
97
  end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-eventlastvalue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Arick
9
+ - Sean Dick
9
10
  - Change.org
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2015-06-05 00:00:00.000000000 Z
14
+ date: 2015-07-15 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: fluentd
@@ -93,9 +94,10 @@ dependencies:
93
94
  - !ruby/object:Gem::Version
94
95
  version: '0'
95
96
  description: Fluentd plugin to find the last value in a time-period of a field and
96
- emit it or write it to redis
97
+ emit it
97
98
  email:
98
99
  - marick@change.org
100
+ - sean@change.org
99
101
  executables: []
100
102
  extensions: []
101
103
  extra_rdoc_files: []
@@ -133,7 +135,7 @@ rubygems_version: 1.8.23
133
135
  signing_key:
134
136
  specification_version: 3
135
137
  summary: Fluentd plugin to find the last value in a time-period of a field and emit
136
- it or write it to redis
138
+ it
137
139
  test_files:
138
140
  - spec/out_eventlastvalue_spec.rb
139
141
  - spec/spec_helper.rb