fluent-plugin-indicative 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a7843f2da828e79b082ce75329b832e8299f50d8970d408be615c37eba450ad2
4
+ data.tar.gz: 64664e64232f705abc6fd7271c6bc554fafd52a38cf2dcc45fbf7d360ef538bd
5
+ SHA512:
6
+ metadata.gz: c6eda450181334ba1faf9e3b079b4083fa9e5a776ccad3248ae207737492c98639b652a890fcbb74b1708930e9f8502639076724a4df7836dd45a4a504704160
7
+ data.tar.gz: 39a44e66a2cc3e26354eacbb6f2999659195b46e43d4c45ac7492250be8a8673f945af500fa95b19676fa28c679113179e2b096fd0ea07941da02c307e626c77
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.3.7
5
+ - 2.4.4
6
+ - 2.5.1
7
+ - 2.6.3
8
+
9
+ gemfile:
10
+ - Gemfile
11
+
12
+ before_install:
13
+ - gem update bundler
14
+
15
+ script: bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-indicative.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-indicative (0.1.0)
5
+ fluentd (>= 0.14.15, < 2)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ addressable (2.6.0)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ cool.io (1.5.4)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ dig_rb (1.0.1)
16
+ fluentd (1.6.0)
17
+ cool.io (>= 1.4.5, < 2.0.0)
18
+ dig_rb (~> 1.0.0)
19
+ http_parser.rb (>= 0.5.1, < 0.7.0)
20
+ msgpack (>= 0.7.0, < 2.0.0)
21
+ serverengine (>= 2.0.4, < 3.0.0)
22
+ sigdump (~> 0.2.2)
23
+ strptime (>= 0.2.2, < 1.0.0)
24
+ tzinfo (~> 1.0)
25
+ tzinfo-data (~> 1.0)
26
+ yajl-ruby (~> 1.0)
27
+ hashdiff (0.4.0)
28
+ http_parser.rb (0.6.0)
29
+ msgpack (1.3.0)
30
+ power_assert (1.1.4)
31
+ public_suffix (3.1.1)
32
+ rake (12.3.2)
33
+ safe_yaml (1.0.5)
34
+ serverengine (2.1.1)
35
+ sigdump (~> 0.2.2)
36
+ sigdump (0.2.4)
37
+ strptime (0.2.3)
38
+ test-unit (3.3.3)
39
+ power_assert
40
+ thread_safe (0.3.6)
41
+ tzinfo (1.2.5)
42
+ thread_safe (~> 0.1)
43
+ tzinfo-data (1.2019.2)
44
+ tzinfo (>= 1.0.0)
45
+ webmock (3.6.0)
46
+ addressable (>= 2.3.6)
47
+ crack (>= 0.3.2)
48
+ hashdiff (>= 0.4.0, < 2.0.0)
49
+ yajl-ruby (1.4.1)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ fluent-plugin-indicative!
56
+ rake
57
+ test-unit (>= 3.1.0)
58
+ webmock (>= 3.6.0, < 4)
59
+
60
+ BUNDLED WITH
61
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Sam Millar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # fluent-plugin-indicative
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.pattern = 'test/**/test_*.rb'
6
+ test.verbose = true
7
+ end
8
+
9
+ task :default => :test
10
+
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "fluent-plugin-indicative"
6
+ s.version = "0.1.0"
7
+ s.authors = ["Sam Millar"]
8
+ s.email = ["sam@millar.io"]
9
+ s.homepage = "https://github.com/millar/fluent-plugin-indicative"
10
+ s.summary = %q{Fluentd output plugin to send events to Indicative}
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ["lib"]
16
+
17
+ # specify any dependencies here; for example:
18
+ s.add_development_dependency "rake"
19
+ s.add_development_dependency "test-unit", ">= 3.1.0"
20
+ s.add_development_dependency "webmock", ">= 3.6.0", "< 4"
21
+ s.add_runtime_dependency "fluentd", ">= 0.14.15", "< 2"
22
+ end
@@ -0,0 +1,56 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'uri'
4
+
5
+ require 'fluent/plugin/output'
6
+
7
+ def flatten_hash(hash)
8
+ hash.each_with_object({}) do |(k, v), h|
9
+ if v.is_a? Hash
10
+ flatten_hash(v).map do |h_k, h_v|
11
+ h["#{k}.#{h_k}"] = h_v
12
+ end
13
+ else
14
+ h[k] = v
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+ class Fluent::Plugin::IndicativeOutput < Fluent::Plugin::Output
21
+ Fluent::Plugin.register_output('indicative', self)
22
+
23
+ config_param :api_key, :string, secret: true
24
+ config_param :api_url, :string, default: 'https://api.indicative.com/service/event'
25
+ config_param :event_name_key, :string
26
+ config_param :event_time_key, :string
27
+ config_param :event_unique_id_keys, :array, value_type: :string
28
+
29
+ def process(tag, es)
30
+ es.each do |time, record|
31
+ send_event(record)
32
+ end
33
+ end
34
+
35
+ def send_event(data)
36
+ uri = URI.parse(@api_url)
37
+
38
+ headers = {'Content-Type' => 'application/json'}
39
+
40
+ unique_id_key = @event_unique_id_keys.find {|k| data[k]}
41
+
42
+ payload = {
43
+ apiKey: @api_key,
44
+ eventName: data[@event_name_key],
45
+ eventUniqueId: unique_id_key && data[unique_id_key],
46
+ properties: flatten_hash(data),
47
+ eventTime: data[@event_time_key]
48
+ }
49
+
50
+ http = Net::HTTP.new(uri.host, uri.port)
51
+ http.use_ssl = true
52
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
53
+ request.body = payload.to_json
54
+ response = http.request(request)
55
+ end
56
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+ require 'test/unit'
3
+
4
+ require 'webmock/test_unit'
5
+
6
+ $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
7
+ $LOAD_PATH.unshift(__dir__)
8
+ require 'fluent/test'
9
+ require 'fluent/test/driver/output'
10
+
11
+ require 'fluent/plugin/out_indicative'
@@ -0,0 +1,54 @@
1
+ require 'helper'
2
+
3
+ class IndicativeOutputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ api_key INDICATIVE_API_KEY
10
+ event_name_key event_name
11
+ event_time_key created_at
12
+ event_unique_id_keys user_id, session_id
13
+ ]
14
+
15
+ def create_driver(conf=CONFIG)
16
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::IndicativeOutput).configure(conf)
17
+ end
18
+
19
+ def test_configure
20
+ assert_raise(Fluent::ConfigError) {
21
+ d = create_driver('')
22
+ }
23
+ d = create_driver CONFIG
24
+ assert_equal 'INDICATIVE_API_KEY', d.instance.api_key
25
+ assert_equal 'event_name', d.instance.event_name_key
26
+ assert_equal 'created_at', d.instance.event_time_key
27
+ assert_equal ['user_id', 'session_id'], d.instance.event_unique_id_keys
28
+ end
29
+
30
+
31
+ def test_emit
32
+ d = create_driver(CONFIG)
33
+ stub_request(:any, d.instance.api_url)
34
+ d.run(default_tag: 'test') do
35
+ d.feed({'event_name' => 'screen_view', 'created_at' => '2015-01-01T00:00:00.000Z', 'session_id' => 'a3bd2', 'user_id' => nil, 'screen' => {'id' => 'index'}})
36
+ end
37
+ events = d.events
38
+ assert_equal 0, events.length
39
+ assert_requested :post, d.instance.api_url,
40
+ headers: {'Content-Type' => 'application/json'}, body: {
41
+ 'apiKey' => 'INDICATIVE_API_KEY',
42
+ 'eventName' => 'screen_view',
43
+ 'eventUniqueId' => 'a3bd2',
44
+ 'properties' => {
45
+ 'event_name' => 'screen_view',
46
+ 'created_at' => '2015-01-01T00:00:00.000Z',
47
+ 'session_id' => 'a3bd2',
48
+ 'user_id' => nil,
49
+ 'screen.id' => 'index'
50
+ },
51
+ 'eventTime' => '2015-01-01T00:00:00.000Z'
52
+ }.to_json, times: 1
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-indicative
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam Millar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.6.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '4'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 3.6.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '4'
61
+ - !ruby/object:Gem::Dependency
62
+ name: fluentd
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 0.14.15
68
+ - - "<"
69
+ - !ruby/object:Gem::Version
70
+ version: '2'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 0.14.15
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: '2'
81
+ description:
82
+ email:
83
+ - sam@millar.io
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - ".travis.yml"
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - fluent-plugin-indicative.gemspec
95
+ - lib/fluent/plugin/out_indicative.rb
96
+ - test/helper.rb
97
+ - test/plugin/test_out_indicative.rb
98
+ homepage: https://github.com/millar/fluent-plugin-indicative
99
+ licenses: []
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.7.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Fluentd output plugin to send events to Indicative
121
+ test_files:
122
+ - test/helper.rb
123
+ - test/plugin/test_out_indicative.rb