fluent-plugin-mixpanel 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1511b088e5a44ccfaaf5496c9c6016ed9d0868b
4
- data.tar.gz: 1af1398470ca349149446515f2c23ad41e0bb3b8
3
+ metadata.gz: 6815b604a35a38d95672504bf46dae46899827b8
4
+ data.tar.gz: 653a7be3759ed89216cd98280313271f7ccdd2ea
5
5
  SHA512:
6
- metadata.gz: eb42e76500502a2c4e883041abc18c234f69a687f90bffced64cf578d483d30d5c86f3bb81bec9ee4240bc41a3da4296b863b71e9513b2436f9bd72b5df3e0a3
7
- data.tar.gz: 57418f562b980b1a061c765e9ff78e773f276b3cf77016a1b7dcae23aa514f018b13a77111989c58986e469c65e76bec2f01867e03a20a1d0a4250ffe46160a6
6
+ metadata.gz: a1e5d36ce6c9ec2bd08bf5ad73380d49da7be09caf6bfba38bc464ff03362c8d6a307efc8e2923767fd58a06f8c9df736ec275ad253fb2c7322578a524f6fc4a
7
+ data.tar.gz: 5e862b4b0bc31b9f705b1c43a63737608b2200f51ef41c1039feb0f069836e963e8ca7960cf16a8a80a16b1a84e862eb21e8f330a9142d8d73d95b3471613717
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.0
5
+ - 2.2.0
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/hakobera/fluent-plugin-mixpanel.png?branch=master)](https://travis-ci.org/hakobera/fluent-plugin-mixpanel)
4
4
 
5
+ **CAUTION** This plugin does not support Ruby < 2.0.
6
+
5
7
  ## Component
6
8
 
7
9
  ### MixpanelOutput
@@ -83,6 +85,35 @@ tracker = Mixpanel::Tracker.new(YOUR_PROJECT_TOKEN)
83
85
  tracker.track("123", "event1", { key1: "value1", key2: "value2" })
84
86
  ```
85
87
 
88
+ #### Use the import method to post instead of track
89
+
90
+ You can use tag name as event name like this.
91
+
92
+ ```
93
+ <match output.mixpanel.*>
94
+ type mixpanel
95
+ project_token YOUR_PROJECT_TOKEN
96
+ distinct_id_key user_id
97
+ remove_tag_prefix output.mixpanel
98
+ event_map_tag true
99
+ use_import true
100
+ api_key YOUR_API_KEY
101
+ </match>
102
+ ```
103
+
104
+ If tag name is `output.mixpanel.event1` and record like this:
105
+
106
+ ```rb
107
+ { user_id: "123", key1: "value1", key2: "value2" }
108
+ ```
109
+
110
+ above settings send to the following data to mixpanel, using [mixpanel-ruby](https://github.com/mixpanel/mixpanel-ruby) gem.
111
+
112
+ ```rb
113
+ tracker = Mixpanel::Tracker.new(YOUR_PROJECT_TOKEN)
114
+ tracker.import(api_key, "123", "event1", { key1: "value1", key2: "value2" })
115
+ ```
116
+
86
117
  ### HttpMixpanelInput
87
118
 
88
119
  HttpMixpanelInput has same configuration as [http Input Plugin](http://docs.fluentd.org/en/articles/in_http).
@@ -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-mixpanel"
7
- spec.version = "0.0.5"
7
+ spec.version = "0.0.6"
8
8
  spec.authors = ["Kazuyuki Honda"]
9
9
  spec.email = ["hakobera@gmail.com"]
10
10
  spec.summary = %q{Fluentd plugin to input/output event track data to mixpanel}
@@ -17,9 +17,10 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_runtime_dependency "fluentd"
21
- spec.add_runtime_dependency "mixpanel-ruby"
20
+ spec.add_runtime_dependency "fluentd", ">= 0.10.55"
21
+ spec.add_runtime_dependency "mixpanel-ruby", "~> 2.1.0"
22
22
 
23
23
  spec.add_development_dependency "rake"
24
24
  spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "test-unit", "~> 3.0.2"
25
26
  end
@@ -2,6 +2,8 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
2
2
  Fluent::Plugin.register_output('mixpanel', self)
3
3
 
4
4
  config_param :project_token, :string
5
+ config_param :api_key, :string, :default => ''
6
+ config_param :use_import, :bool, :default => nil
5
7
  config_param :distinct_id_key, :string
6
8
  config_param :event_key, :string, :default => nil
7
9
  config_param :ip_key, :string, :default => nil
@@ -9,6 +11,9 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
9
11
  config_param :remove_tag_prefix, :string, :default => nil
10
12
  config_param :event_map_tag, :bool, :default => false
11
13
 
14
+ class MixpanelError < StandardError
15
+ end
16
+
12
17
  def initialize
13
18
  super
14
19
  require 'mixpanel-ruby'
@@ -22,6 +27,8 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
22
27
  @ip_key = conf['ip_key']
23
28
  @remove_tag_prefix = conf['remove_tag_prefix']
24
29
  @event_map_tag = conf['event_map_tag']
30
+ @api_key = conf['api_key']
31
+ @use_import = conf['use_import']
25
32
 
26
33
  if @event_key.nil? and !@event_map_tag
27
34
  raise Fluent::ConfigError, "'event_key' must be specifed when event_map_tag == false."
@@ -55,7 +62,7 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
55
62
  elsif record[@event_key]
56
63
  data['event'] = record[@event_key]
57
64
  prop.delete(@event_key)
58
- else
65
+ else
59
66
  log.warn('no event')
60
67
  return
61
68
  end
@@ -78,12 +85,21 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
78
85
 
79
86
  prop.select! {|key, _| !key.start_with?('mp_') }
80
87
  prop.merge!('time' => time.to_i)
81
-
88
+
82
89
  records << data
83
90
  end
84
91
 
92
+ send_to_mixpanel(records)
93
+ end
94
+
95
+ def send_to_mixpanel(records)
85
96
  records.each do |record|
86
- @tracker.track(record['distinct_id'], record['event'], record['properties'])
97
+ success = if @use_import
98
+ @tracker.import(@api_key, record['distinct_id'], record['event'], record['properties'])
99
+ else
100
+ @tracker.track(record['distinct_id'], record['event'], record['properties'])
101
+ end
102
+ raise MixpanelError.new("Failed to track event to mixpanel") unless success
87
103
  end
88
104
  end
89
105
  end
@@ -13,6 +13,10 @@ class MixpanelOutputTest < Test::Unit::TestCase
13
13
  distinct_id_key user_id
14
14
  ]
15
15
 
16
+ IMPORT_CONFIG = CONFIG + %[ api_key test_api_key
17
+ use_import true
18
+ ]
19
+
16
20
  def create_driver(conf = CONFIG)
17
21
  Fluent::Test::BufferedOutputTestDriver.new(Fluent::MixpanelOutput, 'mixpanel.test').configure(conf)
18
22
  end
@@ -24,6 +28,10 @@ class MixpanelOutputTest < Test::Unit::TestCase
24
28
  end.to_return(status: 200, body: JSON.generate({ status: 1 }))
25
29
  end
26
30
 
31
+ def stub_mixpanel_import
32
+ stub_mixpanel("https://api.mixpanel.com/import")
33
+ end
34
+
27
35
  def stub_mixpanel_unavailable(url="https://api.mixpanel.com/track")
28
36
  stub_request(:post, url).to_return(status: 503, body: "Service Unavailable")
29
37
  end
@@ -75,8 +83,8 @@ class MixpanelOutputTest < Test::Unit::TestCase
75
83
  end
76
84
 
77
85
  def test_write_multi_request
78
- stub_mixpanel
79
- d = create_driver(CONFIG + "event_key event")
86
+ stub_mixpanel_import
87
+ d = create_driver(IMPORT_CONFIG + "event_key event")
80
88
  time1 = Time.new('2014-01-01T01:23:45+00:00')
81
89
  time2 = Time.new('2014-01-02T01:23:45+00:00')
82
90
 
@@ -106,7 +114,7 @@ class MixpanelOutputTest < Test::Unit::TestCase
106
114
  d.run
107
115
 
108
116
  assert_equal "123", @out[0]['properties']['distinct_id']
109
- assert_equal "event1", @out[0]['event']
117
+ assert_equal "event1", @out[0]['event']
110
118
  assert_equal time.to_i, @out[0]['properties']['time']
111
119
  assert_equal "192.168.0.2", @out[0]['properties']['ip']
112
120
  assert_equal "value1", @out[0]['properties']['key1']
@@ -187,7 +195,7 @@ class MixpanelOutputTest < Test::Unit::TestCase
187
195
  stub_mixpanel_unavailable
188
196
  d = create_driver(CONFIG + "event_key event")
189
197
  d.emit(sample_record)
190
- assert_raise(Mixpanel::ConnectionError) {
198
+ assert_raise(Fluent::MixpanelOutput::MixpanelError) {
191
199
  d.run
192
200
  }
193
201
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mixpanel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyuki Honda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-24 00:00:00.000000000 Z
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.10.55
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.10.55
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mixpanel-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.2
69
83
  description: Fluentd plugin to input/output event track data to mixpanel
70
84
  email:
71
85
  - hakobera@gmail.com
@@ -108,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
122
  version: '0'
109
123
  requirements: []
110
124
  rubyforge_project:
111
- rubygems_version: 2.2.0
125
+ rubygems_version: 2.4.5
112
126
  signing_key:
113
127
  specification_version: 4
114
128
  summary: Fluentd plugin to input/output event track data to mixpanel