fluent-plugin-indicative 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 297d26519e12331031ab2f4b9ed4a170fad5dec9611c63f5ba2e47e602ad5b37
4
- data.tar.gz: 3a88a5d6b99cee6b470210f4d87ca9981fef6b0054a06d2261704626183dbe7b
3
+ metadata.gz: a2d91e885b3638a46fae8fd381a7dcbedcc054d43e11f8c2e99eac1c691c9544
4
+ data.tar.gz: 90152aadeaedcb61989ce25e0bbdf682098c0e6621e102447352a50f98522083
5
5
  SHA512:
6
- metadata.gz: d097056fd8859ad61f884e006e585cecb4638b799f663341ca6d3c06ed59a7fd01d605a80f7006a29ef1b8bc4094ba4d77fdbddc42aa46f265564fad10560f70
7
- data.tar.gz: ca482d442059b2340f1769b9c7345772f944a842f493419e9c63723167d42c67b9ee27c4e7ac79838e216481283668a118398764c16b28cac5e352cf60dc9a2b
6
+ metadata.gz: 59d9539774cac95d2b87ee221cdbde3f757e9637258723fe1a6d6b85dc3cf43aff52cd31755c9f89e2558eaed9bcac3082273da446849c0c135482c5f974ca73
7
+ data.tar.gz: d12cd7b41f43304cae2cfea5f7343e7b55bf9256f9e84ebd7d51ce638ef5d5b566f9fa9ad9dd2b2aefe243d91359392de73f550c4def63ecb0fbf515f9b83f4e
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-indicative"
6
- s.version = "0.1.6"
6
+ s.version = "0.1.7"
7
7
  s.authors = ["Sam Millar"]
8
8
  s.email = ["sam@millar.io"]
9
9
  s.homepage = "https://github.com/millar/fluent-plugin-indicative"
@@ -5,8 +5,6 @@ require 'uri'
5
5
 
6
6
  require 'fluent/plugin/output'
7
7
 
8
- BATCH_SIZE = 15
9
-
10
8
 
11
9
  def flatten_hash(hash)
12
10
  hash.each_with_object({}) do |(k, v), h|
@@ -14,7 +12,16 @@ def flatten_hash(hash)
14
12
  flatten_hash(v).map do |h_k, h_v|
15
13
  h["#{k}.#{h_k}"] = h_v
16
14
  end
17
- elsif !v.is_a? Array
15
+ elsif v.is_a? Array
16
+ # Indicative doesn't support arrays so we use the value of the array as a key and set it to true
17
+ v.each do |item|
18
+ if item.is_a?(Hash) && item.has_key?("key") && item.has_key?("value")
19
+ h["#{k}.#{item["key"]}"] = item["value"]
20
+ else
21
+ h["#{k}.#{item}"] = true
22
+ end
23
+ end
24
+ else
18
25
  h[k] = v
19
26
  end
20
27
  end
@@ -26,12 +33,13 @@ class Fluent::Plugin::IndicativeOutput < Fluent::Plugin::Output
26
33
 
27
34
  config_param :api_key, :string, secret: true
28
35
  config_param :api_url, :string, default: 'https://api.indicative.com/service/event/batch'
36
+ config_param :batch_size, :integer, default: 15
29
37
  config_param :event_name_key, :string
30
38
  config_param :event_time_key, :string
31
39
  config_param :event_unique_id_keys, :array, value_type: :string
32
40
 
33
41
  def process(tag, es)
34
- es.each_slice(BATCH_SIZE) do |events|
42
+ es.each_slice(@batch_size) do |events|
35
43
  send_events(events.map {|time, record| record})
36
44
  end
37
45
  end
@@ -41,7 +49,7 @@ class Fluent::Plugin::IndicativeOutput < Fluent::Plugin::Output
41
49
  chunk.each do |time, record|
42
50
  records << record
43
51
  end
44
- records.each_slice(BATCH_SIZE) do |events|
52
+ records.each_slice(@batch_size) do |events|
45
53
  send_events(events)
46
54
  end
47
55
  end
@@ -77,4 +77,56 @@ class IndicativeOutputTest < Test::Unit::TestCase
77
77
  assert_equal 0, events.length
78
78
  assert_requested :post, d.instance.api_url, times: 1
79
79
  end
80
+
81
+ def test_array_transformation
82
+ d = create_driver(STREAM_CONFIG)
83
+ stub_request(:any, d.instance.api_url)
84
+ d.run(default_tag: 'test') do
85
+ d.feed({'event_name' => 'screen_view', 'created_at' => '2015-01-01T10:00:00.000Z', 'session_id' => 'a3bd2', 'experiments': ['a', 'c']})
86
+ end
87
+ events = d.events
88
+ assert_equal 0, events.length
89
+ assert_requested :post, d.instance.api_url,
90
+ headers: {'Content-Type' => 'application/json'}, body: {
91
+ 'apiKey' => 'INDICATIVE_API_KEY',
92
+ 'events' => [{
93
+ 'eventName' => 'screen_view',
94
+ 'eventUniqueId' => 'a3bd2',
95
+ 'properties' => {
96
+ 'event_name' => 'screen_view',
97
+ 'created_at' => '2015-01-01T10:00:00.000Z',
98
+ 'session_id' => 'a3bd2',
99
+ 'experiments.a' => true,
100
+ 'experiments.c' => true
101
+ },
102
+ 'eventTime' => '2015-01-01T10:00:00+00:00'
103
+ }]
104
+ }.to_json, times: 1
105
+ end
106
+
107
+ def test_key_value_object_transformation
108
+ d = create_driver(STREAM_CONFIG)
109
+ stub_request(:any, d.instance.api_url)
110
+ d.run(default_tag: 'test') do
111
+ d.feed({'event_name' => 'screen_view', 'created_at' => '2015-01-01T10:00:00.000Z', 'session_id' => 'a3bd2', 'experiments': [{'key': 'a', 'value': 1}, {'key': 'b', 'value': 2}]})
112
+ end
113
+ events = d.events
114
+ assert_equal 0, events.length
115
+ assert_requested :post, d.instance.api_url,
116
+ headers: {'Content-Type' => 'application/json'}, body: {
117
+ 'apiKey' => 'INDICATIVE_API_KEY',
118
+ 'events' => [{
119
+ 'eventName' => 'screen_view',
120
+ 'eventUniqueId' => 'a3bd2',
121
+ 'properties' => {
122
+ 'event_name' => 'screen_view',
123
+ 'created_at' => '2015-01-01T10:00:00.000Z',
124
+ 'session_id' => 'a3bd2',
125
+ 'experiments.a' => 1,
126
+ 'experiments.b' => 2
127
+ },
128
+ 'eventTime' => '2015-01-01T10:00:00+00:00'
129
+ }]
130
+ }.to_json, times: 1
131
+ end
80
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-indicative
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Millar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-13 00:00:00.000000000 Z
11
+ date: 2020-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -113,8 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.7.3
116
+ rubygems_version: 3.0.3
118
117
  signing_key:
119
118
  specification_version: 4
120
119
  summary: Fluentd output plugin to send events to Indicative