fluent-plugin-mixpanel 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/example/in_http_mixpanel.conf +0 -1
- data/fluent-plugin-mixpanel.gemspec +3 -3
- data/lib/fluent/plugin/in_http_mixpanel.rb +5 -5
- data/lib/fluent/plugin/out_mixpanel.rb +7 -0
- data/test/plugin/test_in_http_mixpanel.rb +4 -6
- data/test/plugin/test_out_mixpanel.rb +24 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9406e78fac736d2fd7b8b6b4dfa4645f741170db
|
4
|
+
data.tar.gz: 43835b93670babcdfe3d6cf184b6b65413507315
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9aa1ecf98277f977a110929ea16356265fc02f858253fcf100f0f5c6f569e65766fce3f20809b0c72286971becb16fae7aa113529774ed5b166f7264898731c4
|
7
|
+
data.tar.gz: 33c231f32a0eed37ff3225ad41f93dfbb72c6e9383e7afb419fc76c037692e1ce3ad8de3f234aaef89480291b4d3a62224247ff0b69525d98bef6717708bd7f9
|
data/README.md
CHANGED
@@ -55,7 +55,7 @@ tracker.track("123", "event1", { key1: "value1", key2: "value2" })
|
|
55
55
|
|
56
56
|
### HttpMixpanelInput
|
57
57
|
|
58
|
-
HttpMixpanelInput
|
58
|
+
HttpMixpanelInput has same configuration as [http Input Plugin](http://docs.fluentd.org/en/articles/in_http).
|
59
59
|
|
60
60
|
```
|
61
61
|
<source>
|
@@ -65,7 +65,6 @@ HttpMixpanelInput is very similar to [http Input Plugin](http://docs.fluentd.org
|
|
65
65
|
body_size_limit 10m
|
66
66
|
keepalive_timeout 5
|
67
67
|
add_http_headers true
|
68
|
-
access_control_allow_origin http://0.0.0.0:8000
|
69
68
|
</source>
|
70
69
|
```
|
71
70
|
|
@@ -4,11 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-mixpanel"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.3"
|
8
8
|
spec.authors = ["Kazuyuki Honda"]
|
9
9
|
spec.email = ["hakobera@gmail.com"]
|
10
|
-
spec.summary = %q{Fluentd plugin to
|
11
|
-
spec.description = %q{Fluentd plugin to
|
10
|
+
spec.summary = %q{Fluentd plugin to input/output event track data to mixpanel}
|
11
|
+
spec.description = %q{Fluentd plugin to input/output event track data to mixpanel}
|
12
12
|
spec.homepage = "https://github.com/hakobera/fluent-plugin-mixpanel"
|
13
13
|
spec.license = "Apache License, Version 2.0"
|
14
14
|
|
@@ -4,15 +4,15 @@ require 'base64'
|
|
4
4
|
class Fluent::HttpMixpanelInput < Fluent::HttpInput
|
5
5
|
Fluent::Plugin.register_input('http_mixpanel', self)
|
6
6
|
|
7
|
-
config_param :access_control_allow_origin
|
8
7
|
config_param :tag_prefix, :default => 'mixpanel'
|
9
8
|
|
10
9
|
def on_request(path_info, params)
|
11
10
|
data = Base64.decode64(params['data']).force_encoding('utf-8')
|
12
11
|
json = JSON.parse(data)
|
12
|
+
props = json['properties']
|
13
13
|
path = "/#{tag_prefix}.#{json['event']}"
|
14
|
-
params['json'] =
|
15
|
-
params['time'] =
|
14
|
+
params['json'] = props.to_json
|
15
|
+
params['time'] = props['time'].to_s if props['time']
|
16
16
|
|
17
17
|
ret = super(path, params)
|
18
18
|
|
@@ -20,12 +20,12 @@ class Fluent::HttpMixpanelInput < Fluent::HttpInput
|
|
20
20
|
'Access-Control-Allow-Credentials' => true,
|
21
21
|
'Access-Control-Allow-Headers' => 'X-Requested-With',
|
22
22
|
'Access-Control-Allow-Methods' => 'GET, POST, OPTIONS',
|
23
|
-
'Access-Control-Allow-Origin' =>
|
23
|
+
'Access-Control-Allow-Origin' => params['HTTP_ORIGIN'],
|
24
24
|
'Access-Control-Max-Age' => 1728000,
|
25
25
|
'Cache-Control' => 'no-cache, no-store',
|
26
26
|
'Content-type' => 'text/plain'
|
27
27
|
}
|
28
28
|
|
29
|
-
[ret[0], headers, (ret[0] == 200 ?
|
29
|
+
[ret[0], headers, (ret[0] == '200 OK' ? '0' : '1')]
|
30
30
|
end
|
31
31
|
end
|
@@ -4,6 +4,7 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
|
|
4
4
|
config_param :project_token, :string
|
5
5
|
config_param :distinct_id_key, :string
|
6
6
|
config_param :event_key, :string
|
7
|
+
config_param :ip_key, :string, :default => nil
|
7
8
|
|
8
9
|
def initialize
|
9
10
|
super
|
@@ -15,6 +16,7 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
|
|
15
16
|
@project_tokey = conf['project_token']
|
16
17
|
@distinct_id_key = conf['distinct_id_key']
|
17
18
|
@event_key = conf['event_key']
|
19
|
+
@ip_key = conf['ip_key']
|
18
20
|
|
19
21
|
if @project_token.empty?
|
20
22
|
raise Fluent::ConfigError, "'project_token' must be specifed."
|
@@ -63,6 +65,11 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
|
|
63
65
|
return
|
64
66
|
end
|
65
67
|
|
68
|
+
if !@ip_key.nil? and record[@ip_key]
|
69
|
+
record['ip'] = record[@ip_key]
|
70
|
+
record.delete(@ip_key)
|
71
|
+
end
|
72
|
+
|
66
73
|
record.merge!(time: time.to_i)
|
67
74
|
data['properties'] = record
|
68
75
|
|
@@ -14,7 +14,6 @@ class HttpMixpanelInputTest < Test::Unit::TestCase
|
|
14
14
|
bind 127.0.0.1
|
15
15
|
body_size_limit 10m
|
16
16
|
keepalive_timeout 5
|
17
|
-
access_control_allow_origin http://foo.example
|
18
17
|
]
|
19
18
|
|
20
19
|
def create_driver(conf=CONFIG)
|
@@ -28,7 +27,6 @@ class HttpMixpanelInputTest < Test::Unit::TestCase
|
|
28
27
|
assert_equal 10*1024*1024, d.instance.body_size_limit
|
29
28
|
assert_equal 5, d.instance.keepalive_timeout
|
30
29
|
assert_equal false, d.instance.add_http_headers
|
31
|
-
assert_equal 'http://foo.example', d.instance.access_control_allow_origin
|
32
30
|
end
|
33
31
|
|
34
32
|
def test_time
|
@@ -44,10 +42,11 @@ class HttpMixpanelInputTest < Test::Unit::TestCase
|
|
44
42
|
d.expected_emits.each {|tag,time,record|
|
45
43
|
res = track("#{tag}", {"json"=>record})
|
46
44
|
assert_equal "200", res.code
|
45
|
+
assert_equal '0', res.body
|
47
46
|
assert_equal 'true', res.header['access-control-allow-credentials']
|
48
47
|
assert_equal 'X-Requested-With', res.header['access-control-allow-headers']
|
49
48
|
assert_equal 'GET, POST, OPTIONS', res.header['access-control-allow-methods']
|
50
|
-
assert_equal
|
49
|
+
assert_equal 'http://foo.example', res.header['access-control-allow-origin']
|
51
50
|
assert_equal '1728000', res.header['access-control-max-age']
|
52
51
|
assert_equal 'no-cache, no-store', res.header['cache-control']
|
53
52
|
}
|
@@ -95,18 +94,17 @@ class HttpMixpanelInputTest < Test::Unit::TestCase
|
|
95
94
|
|
96
95
|
def track(tag, params)
|
97
96
|
event = tag.sub(/^mixpanel\.(.+)$/, '\1')
|
97
|
+
params['json']['time'] = params['time'] if params['time']
|
98
98
|
data = {
|
99
99
|
event: event,
|
100
100
|
properties: params['json']
|
101
101
|
}
|
102
102
|
data = URI.escape(Base64.encode64(data.to_json))
|
103
103
|
query = "data=#{data}"
|
104
|
-
query += "&ip=1"
|
105
|
-
query += "&_=#{params['time']}000" if params['time']
|
106
104
|
path = "/track/?#{query}"
|
107
105
|
|
108
106
|
http = Net::HTTP.new("127.0.0.1", PORT)
|
109
|
-
req = Net::HTTP::Get.new(path)
|
107
|
+
req = Net::HTTP::Get.new(path, { 'origin' => 'http://foo.example' })
|
110
108
|
http.request(req)
|
111
109
|
end
|
112
110
|
|
@@ -41,6 +41,15 @@ class MixpanelOutputTest < Test::Unit::TestCase
|
|
41
41
|
assert_equal 'event', d.instance.event_key
|
42
42
|
end
|
43
43
|
|
44
|
+
def test_configure_with_ip_key
|
45
|
+
d = create_driver(CONFIG + 'ip_key ip')
|
46
|
+
|
47
|
+
assert_equal 'test_token', d.instance.project_token
|
48
|
+
assert_equal 'user_id', d.instance.distinct_id_key
|
49
|
+
assert_equal 'event', d.instance.event_key
|
50
|
+
assert_equal 'ip', d.instance.ip_key
|
51
|
+
end
|
52
|
+
|
44
53
|
def test_write
|
45
54
|
stub_mixpanel
|
46
55
|
d = create_driver
|
@@ -79,6 +88,21 @@ class MixpanelOutputTest < Test::Unit::TestCase
|
|
79
88
|
assert_equal "value2", @out[1]['properties']['key2']
|
80
89
|
end
|
81
90
|
|
91
|
+
def test_write_with_ip_key
|
92
|
+
stub_mixpanel
|
93
|
+
d = create_driver(CONFIG + 'ip_key ip_address')
|
94
|
+
time = Time.new('2014-01-01T01:23:45+00:00')
|
95
|
+
d.emit(sample_record.merge('ip_address' => '192.168.0.2'), time)
|
96
|
+
d.run
|
97
|
+
|
98
|
+
assert_equal "123", @out[0]['properties']['distinct_id']
|
99
|
+
assert_equal "event1", @out[0]['event']
|
100
|
+
assert_equal time.to_i, @out[0]['properties']['time']
|
101
|
+
assert_equal "192.168.0.2", @out[0]['properties']['ip']
|
102
|
+
assert_equal "value1", @out[0]['properties']['key1']
|
103
|
+
assert_equal "value2", @out[0]['properties']['key2']
|
104
|
+
end
|
105
|
+
|
82
106
|
def test_request_error
|
83
107
|
stub_mixpanel_unavailable
|
84
108
|
d = create_driver
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mixpanel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuyuki Honda
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Fluentd plugin to
|
69
|
+
description: Fluentd plugin to input/output event track data to mixpanel
|
70
70
|
email:
|
71
71
|
- hakobera@gmail.com
|
72
72
|
executables: []
|
@@ -111,7 +111,7 @@ rubyforge_project:
|
|
111
111
|
rubygems_version: 2.2.0
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
|
-
summary: Fluentd plugin to
|
114
|
+
summary: Fluentd plugin to input/output event track data to mixpanel
|
115
115
|
test_files:
|
116
116
|
- test/helper.rb
|
117
117
|
- test/plugin/test_in_http_mixpanel.rb
|