fluent-plugin-amplitude 0.0.9 → 0.1.0
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/README.md +4 -0
- data/fluent-plugin-amplitude.gemspec +1 -1
- data/lib/fluent/plugin/out_amplitude.rb +25 -1
- data/spec/out_amplitude_spec.rb +45 -0
- 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: 5a99dfa0622abec2b9b5b7eced10c234698e62f9
|
4
|
+
data.tar.gz: 0b2b2e968e091881426eae51e4b812d22351bc0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dba48d6ac9d57bfc8871c91371bb9ee789f54ff232a28d7405f6cd11275ad606df15d4a58107a4bb45518ad4f3c1fcafcbf0afcbfc818d9d14459c6607e63a1
|
7
|
+
data.tar.gz: b3e098e985a55091aee6e17668e2b92779456f39e96eb3a6e15039555225ab210f211655f45e6062217e49ba6dbfccd0ec68ee700215d70f3bf63e4754cadea1
|
data/README.md
CHANGED
@@ -23,6 +23,7 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-amplitude
|
|
23
23
|
api_key XXXXXX
|
24
24
|
user_id_key user_id
|
25
25
|
device_id_key uuid
|
26
|
+
time_key created_at
|
26
27
|
user_properties first_name, last_name
|
27
28
|
event_properties current_source
|
28
29
|
properties_blacklist user
|
@@ -44,6 +45,9 @@ AmplitudeOutput needs your Amplitude `api_key` ([see Amplitude for more informat
|
|
44
45
|
#### user_id_key and device_id_key
|
45
46
|
You must set at least one of `user_id_key` and `device_id_key`. They will be used to pull out the `user_id` and `device_id` values from the record to send to the Amplitude API. Note these can both be arrays, and the first matching key will be used.
|
46
47
|
|
48
|
+
#### time_key
|
49
|
+
If set, `time_key` will be used to pull out a timestamp field to set as `time` in the Amplitude API request. This can be an array, the first matching key will be used.
|
50
|
+
|
47
51
|
#### user_properties and event_properties
|
48
52
|
You can optionally specify lists of `user_properties` and `event_properties` to pull from the record.
|
49
53
|
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'fluent-plugin-amplitude'
|
7
|
-
spec.version = '0.0
|
7
|
+
spec.version = '0.1.0'
|
8
8
|
spec.authors = ['Vijay Ramesh']
|
9
9
|
spec.email = ['vijay@change.org']
|
10
10
|
spec.summary = 'Fluentd plugin to output event data to Amplitude'
|
@@ -10,6 +10,7 @@ module Fluent
|
|
10
10
|
config_param :api_key, :string, secret: true
|
11
11
|
config_param :device_id_key, :array, default: nil
|
12
12
|
config_param :user_id_key, :array, default: nil
|
13
|
+
config_param :time_key, :array, default: nil
|
13
14
|
config_param :user_properties, :array, default: nil
|
14
15
|
config_param :event_properties, :array, default: nil
|
15
16
|
config_param :properties_blacklist, :array, default: nil
|
@@ -42,6 +43,7 @@ module Fluent
|
|
42
43
|
|
43
44
|
filter_properties_blacklist!(record)
|
44
45
|
extract_user_and_device!(amplitude_hash, record)
|
46
|
+
set_time!(amplitude_hash, record)
|
45
47
|
extract_user_properties!(amplitude_hash, record)
|
46
48
|
extract_event_properties!(amplitude_hash, record)
|
47
49
|
|
@@ -98,6 +100,25 @@ module Fluent
|
|
98
100
|
present?(user_id) || present?(device_id)
|
99
101
|
end
|
100
102
|
|
103
|
+
def set_time!(amplitude_hash, record)
|
104
|
+
return unless @time_key && !@time_key.empty?
|
105
|
+
@time_key.each do |time_key|
|
106
|
+
next unless record[time_key]
|
107
|
+
if (time = parse_time_from_string(record[time_key]))
|
108
|
+
amplitude_hash[:time] = time
|
109
|
+
break
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def parse_time_from_string(time_string)
|
115
|
+
# this should be seconds since epoch; amplitude-api
|
116
|
+
# converts it to milliseconds since epoch as needed.
|
117
|
+
Time.parse(time_string).to_i
|
118
|
+
rescue StandardError => e
|
119
|
+
log.info("failed to parse #{time_string}: #{e.message}")
|
120
|
+
end
|
121
|
+
|
101
122
|
def extract_user_properties!(amplitude_hash, record)
|
102
123
|
# if user_properties are specified, pull them off of the record
|
103
124
|
return unless @user_properties
|
@@ -132,8 +153,11 @@ module Fluent
|
|
132
153
|
errors << [[res.response_code, res.body]]
|
133
154
|
end
|
134
155
|
end
|
135
|
-
|
156
|
+
log_errors(errors)
|
157
|
+
end
|
136
158
|
|
159
|
+
def log_errors(errors)
|
160
|
+
return if errors.empty?
|
137
161
|
errors_string = errors.map do |code, body|
|
138
162
|
"Response: #{code} Body: #{body}"
|
139
163
|
end
|
data/spec/out_amplitude_spec.rb
CHANGED
@@ -285,6 +285,51 @@ describe Fluent::AmplitudeOutput do
|
|
285
285
|
}
|
286
286
|
end
|
287
287
|
|
288
|
+
it 'produces the expected output' do
|
289
|
+
amplitude.expect_format [tag, now, formatted_event].to_msgpack
|
290
|
+
amplitude.run
|
291
|
+
end
|
292
|
+
end
|
293
|
+
context 'time_key specified' do
|
294
|
+
let(:conf) do
|
295
|
+
%(
|
296
|
+
api_key XXXXXX
|
297
|
+
user_id_key user_id
|
298
|
+
device_id_key uuid
|
299
|
+
time_key created_at
|
300
|
+
user_properties first_name, last_name
|
301
|
+
event_properties current_source
|
302
|
+
)
|
303
|
+
end
|
304
|
+
let(:event) do
|
305
|
+
{
|
306
|
+
'user_id' => 42,
|
307
|
+
'uuid' => 'e6153b00-85d8-11e6-b1bc-43192d1e493f',
|
308
|
+
'first_name' => 'Bobby',
|
309
|
+
'last_name' => 'Weir',
|
310
|
+
'state' => 'CA',
|
311
|
+
'current_source' => 'fb_share',
|
312
|
+
'recruiter_id' => 710,
|
313
|
+
'created_at' => '2016-12-20T00:00:06Z'
|
314
|
+
}
|
315
|
+
end
|
316
|
+
|
317
|
+
let(:formatted_event) do
|
318
|
+
{
|
319
|
+
event_type: tag,
|
320
|
+
user_id: 42,
|
321
|
+
device_id: 'e6153b00-85d8-11e6-b1bc-43192d1e493f',
|
322
|
+
time: Time.parse('2016-12-20T00:00:06Z').to_i,
|
323
|
+
user_properties: {
|
324
|
+
first_name: 'Bobby',
|
325
|
+
last_name: 'Weir'
|
326
|
+
},
|
327
|
+
event_properties: {
|
328
|
+
current_source: 'fb_share'
|
329
|
+
}
|
330
|
+
}
|
331
|
+
end
|
332
|
+
|
288
333
|
it 'produces the expected output' do
|
289
334
|
amplitude.expect_format [tag, now, formatted_event].to_msgpack
|
290
335
|
amplitude.run
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-amplitude
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vijay Ramesh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|