logstash-filter-mixpanel 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/logstash/filters/mixpanel.rb +41 -10
- data/logstash-filter-mixpanel.gemspec +1 -1
- data/spec/filters/mixpanel_spec.rb +105 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzNhMGYxMmM5OTBkZjFlMjQxZDc0NjE4ZjRmMzk1NWI0ZjQ4N2U2ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTRlMzhmOTc3MzhlZjYwZWZkZWJiMTdlY2Q1Mzk3YWJiOWNhMWMyMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzIyMDhkODU3YWJkMjdlNGY5Yzc4ZGUyMDI4NzRjMWVjZDVmYjhkY2Q5M2Fi
|
10
|
+
NTIxY2RmMTkyYTMzYmNiMzdiYzRjZTNjNTFkYTI2ZWJlN2E4YjNkNzIyZDU0
|
11
|
+
ZTljYTNkZGMzMTE1NTE5ZWY2MzkyYjExOWI4ZmRlZTRiOTI5MDA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWU1NDBjYmUyOGRjNTk3MGFiZjY2MWM2YTc0MDAxNzI2YmQzM2U5YjViMTQz
|
14
|
+
ZGUwYTQ4ZmMzNTJhZjRlOTI1ODBhMTkzMWFhNDQxOWE4MGJiM2Q0MjU1MmJl
|
15
|
+
ZWU4YWVjYmJhYWE4MzIxOGNhYWMzMjY3M2M2YWJhNDczZTIyYzY=
|
@@ -18,14 +18,15 @@ class LogStash::Filters::Mixpanel < LogStash::Filters::Base
|
|
18
18
|
# }
|
19
19
|
# }
|
20
20
|
#
|
21
|
-
config_name
|
22
|
-
|
21
|
+
config_name 'mixpanel'
|
22
|
+
|
23
23
|
# Replace the message with this value.
|
24
24
|
config :api_key, :validate => :string, :required => true
|
25
25
|
config :api_secret, :validate => :string, :required => true
|
26
|
-
config :where, :validate => :
|
26
|
+
config :where, :validate => :array, :required => true
|
27
27
|
config :source, :validate => :string, :default => 'message'
|
28
28
|
config :target, :validate => :string, :default => 'mixpanel'
|
29
|
+
config :tag_on_failure, :validate => :array, :default => ['_mixpanelfilterfailure']
|
29
30
|
|
30
31
|
|
31
32
|
public
|
@@ -40,19 +41,49 @@ class LogStash::Filters::Mixpanel < LogStash::Filters::Base
|
|
40
41
|
def filter(event)
|
41
42
|
|
42
43
|
result = fetch_data
|
43
|
-
|
44
|
-
|
45
|
-
event[@target] = result
|
44
|
+
if !result.nil?
|
45
|
+
event[@target] = result
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
# filter_matched should go in the last line of our successful code
|
48
|
+
filter_matched(event)
|
49
|
+
else
|
50
|
+
@tag_on_failure.each do |tag|
|
51
|
+
event['tags'] ||= []
|
52
|
+
event['tags'] << tag unless event["tags"].include?(tag)
|
53
|
+
end
|
54
|
+
end
|
49
55
|
end # def filter
|
50
56
|
|
51
57
|
private
|
52
58
|
def fetch_data
|
53
59
|
options = {}
|
54
|
-
|
55
|
-
|
60
|
+
options['where'] = prepare_where @where if @where
|
61
|
+
|
62
|
+
response = @mp.request('engage', options)
|
63
|
+
if response['results'].size >= 1
|
64
|
+
single_res = response['results'][0]
|
65
|
+
else
|
66
|
+
return nil
|
67
|
+
end
|
68
|
+
distinct_id = single_res['$distinct_id']
|
69
|
+
result = single_res['$properties']
|
70
|
+
result['$distinct_id'] = distinct_id
|
56
71
|
result
|
57
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def prepare_where wheredata
|
76
|
+
special_properties = %w(email first_name last_name last_seen created)
|
77
|
+
res_array = []
|
78
|
+
wheredata.each { |constraint|
|
79
|
+
constraint.each { |key, value|
|
80
|
+
# prepend key with dollar sigh if key is in special_properties
|
81
|
+
# TODO: add test for special properties without dollar sign
|
82
|
+
key = "$#{key}" if special_properties.include? key
|
83
|
+
|
84
|
+
res_array.push "properties[\"#{key}\"] == \"#{value}\""
|
85
|
+
}
|
86
|
+
}
|
87
|
+
res_array.join ' and '
|
88
|
+
end
|
58
89
|
end # class LogStash::Filters::Example
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-filter-mixpanel'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.3'
|
4
4
|
s.version = "#{s.version}.pre.#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS'] and ENV['TRAVIS_BRANCH'] != 'master'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "This filter checks mixpanel for additional people data and adds it to the event data"
|
@@ -10,15 +10,35 @@ describe LogStash::Filters::Mixpanel do
|
|
10
10
|
before(:all) do
|
11
11
|
@mp = Mixpanel::Tracker.new(ENV['MP_PROJECT_TOKEN'])
|
12
12
|
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
@user_1_id = FFaker::Guid.guid
|
14
|
+
@user_1_ip = FFaker::Internet.ip_v4_address
|
15
|
+
@user_1_email = FFaker::Internet.safe_email
|
16
|
+
@user_1_first_name = FFaker::NameDE.first_name
|
17
|
+
@user_1_last_name = FFaker::NameDE.last_name
|
18
|
+
@user_1_data = {
|
19
|
+
:$first_name => @user_1_first_name,
|
20
|
+
:$last_name => @user_1_last_name,
|
21
|
+
:$email => @user_1_email,
|
22
|
+
'Device ID' => @user_1_id
|
19
23
|
}
|
20
|
-
@mp.people.set(@
|
21
|
-
@mp.track(@
|
24
|
+
@mp.people.set(@user_1_id, @user_1_data, ip=@user_1_ip)
|
25
|
+
@mp.track(@user_1_id, 'user 1 created')
|
26
|
+
|
27
|
+
@user_2_id = FFaker::Guid.guid
|
28
|
+
@user_2_ip = FFaker::Internet.ip_v4_address
|
29
|
+
@user_2_email = FFaker::Internet.safe_email
|
30
|
+
@user_2_first_name = @user_1_first_name
|
31
|
+
@user_2_last_name = @user_1_last_name
|
32
|
+
@user_2_data = {
|
33
|
+
:$first_name => @user_2_first_name,
|
34
|
+
:$last_name => @user_2_last_name,
|
35
|
+
:$email => @user_2_email,
|
36
|
+
'Device ID' => @user_2_id
|
37
|
+
}
|
38
|
+
@mp.people.set(@user_2_id, @user_2_data, ip=@user_2_ip)
|
39
|
+
@mp.track(@user_2_id, 'user 2 created')
|
40
|
+
|
41
|
+
|
22
42
|
end
|
23
43
|
|
24
44
|
context 'raise error' do
|
@@ -53,7 +73,7 @@ describe LogStash::Filters::Mixpanel do
|
|
53
73
|
config = {
|
54
74
|
'api_key' => '123',
|
55
75
|
'api_secret' => '123',
|
56
|
-
'where' => '
|
76
|
+
'where' => [{'Device ID' => @user_1_id}]
|
57
77
|
}
|
58
78
|
filter = LogStash::Filters::Mixpanel.new config
|
59
79
|
filter.register
|
@@ -70,7 +90,7 @@ describe LogStash::Filters::Mixpanel do
|
|
70
90
|
config = {
|
71
91
|
'api_key' => ENV['MP_PROJECT_KEY'],
|
72
92
|
'api_secret' => '123',
|
73
|
-
'where' => '
|
93
|
+
'where' => [{'Device ID' => @user_1_id}]
|
74
94
|
}
|
75
95
|
filter = LogStash::Filters::Mixpanel.new config
|
76
96
|
filter.register
|
@@ -85,29 +105,96 @@ describe LogStash::Filters::Mixpanel do
|
|
85
105
|
end
|
86
106
|
|
87
107
|
context 'fetch created user' do
|
88
|
-
|
108
|
+
context 'by device id' do
|
109
|
+
let(:config) do <<-CONFIG
|
89
110
|
filter {
|
90
111
|
mixpanel {
|
91
112
|
api_key => '#{ENV['MP_PROJECT_KEY']}'
|
92
113
|
api_secret => '#{ENV['MP_PROJECT_SECRET']}'
|
93
|
-
where => '
|
114
|
+
where => [{'Device ID' => '#{@user_1_id}'}]
|
94
115
|
}
|
95
116
|
}
|
96
|
-
|
117
|
+
CONFIG
|
118
|
+
end
|
119
|
+
|
120
|
+
sample("message" => "123") do
|
121
|
+
expect(subject).to include('mixpanel')
|
122
|
+
expect(subject['mixpanel']).to include('Device ID')
|
123
|
+
expect(subject['mixpanel']).to include('$distinct_id')
|
124
|
+
expect(subject['mixpanel']).to include('$email')
|
125
|
+
expect(subject['mixpanel']).to include('$last_name')
|
126
|
+
expect(subject['mixpanel']).to include('Device ID')
|
127
|
+
insist { subject['tags'] }.nil?
|
128
|
+
end
|
97
129
|
end
|
98
130
|
|
99
|
-
|
100
|
-
|
101
|
-
|
131
|
+
context 'by email' do
|
132
|
+
let(:config) do <<-CONFIG
|
133
|
+
filter {
|
134
|
+
mixpanel {
|
135
|
+
api_key => '#{ENV['MP_PROJECT_KEY']}'
|
136
|
+
api_secret => '#{ENV['MP_PROJECT_SECRET']}'
|
137
|
+
where => [{'email' => '#{@user_1_email}'}]
|
138
|
+
}
|
139
|
+
}
|
140
|
+
CONFIG
|
141
|
+
end
|
102
142
|
|
103
|
-
context 'by distinct id' do
|
104
143
|
sample("message" => "123") do
|
105
144
|
expect(subject).to include('mixpanel')
|
145
|
+
expect(subject['mixpanel']).to include('Device ID')
|
146
|
+
expect(subject['mixpanel']).to include('$distinct_id')
|
147
|
+
expect(subject['mixpanel']).to include('$email')
|
148
|
+
expect(subject['mixpanel']).to include('$last_name')
|
149
|
+
expect(subject['mixpanel']).to include('Device ID')
|
150
|
+
insist { subject['tags'] }.nil?
|
106
151
|
end
|
107
152
|
end
|
108
153
|
end
|
109
154
|
|
155
|
+
context 'test on multiple returns' do
|
156
|
+
let(:config) do <<-CONFIG
|
157
|
+
filter {
|
158
|
+
mixpanel {
|
159
|
+
api_key => '#{ENV['MP_PROJECT_KEY']}'
|
160
|
+
api_secret => '#{ENV['MP_PROJECT_SECRET']}'
|
161
|
+
where => [{'first_name' => '#{@user_1_first_name}'}]
|
162
|
+
}
|
163
|
+
}
|
164
|
+
CONFIG
|
165
|
+
end
|
166
|
+
|
167
|
+
sample("message" => "123") do
|
168
|
+
expect(subject).to include('mixpanel')
|
169
|
+
expect(subject['mixpanel']).to include('Device ID')
|
170
|
+
expect(subject['mixpanel']).to include('$distinct_id')
|
171
|
+
expect(subject['mixpanel']).to include('$email')
|
172
|
+
expect(subject['mixpanel']).to include('$last_name')
|
173
|
+
expect(subject['mixpanel']).to include('Device ID')
|
174
|
+
insist { subject['tags'] }.nil?
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'test on no returns' do
|
179
|
+
let(:config) do <<-CONFIG
|
180
|
+
filter {
|
181
|
+
mixpanel {
|
182
|
+
api_key => '#{ENV['MP_PROJECT_KEY']}'
|
183
|
+
api_secret => '#{ENV['MP_PROJECT_SECRET']}'
|
184
|
+
where => [{'first_name' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'}]
|
185
|
+
}
|
186
|
+
}
|
187
|
+
CONFIG
|
188
|
+
end
|
189
|
+
|
190
|
+
sample("message" => "123") do
|
191
|
+
insist { subject["tags"] }.include?('_mixpanelfilterfailure')
|
192
|
+
reject { subject }.include?('mixpanel')
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
110
196
|
after(:all) do
|
111
|
-
@mp.people.delete_user(@
|
197
|
+
@mp.people.delete_user(@user_1_id)
|
198
|
+
@mp.people.delete_user(@user_2_id)
|
112
199
|
end
|
113
200
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-mixpanel
|
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
|
- Torsten Feld
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core
|