app_monit 0.0.10 → 0.0.11

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: 5023058b95f44aab030c66dd92936dc54e165fb7
4
- data.tar.gz: 6f6b8b96777a6847b200c858b77486190ea56770
3
+ metadata.gz: 77edac5c532fcf5239cfbe239328f0141c7351b5
4
+ data.tar.gz: e1e5f037eb95285a8fb6e3d2cd906969dbb7930a
5
5
  SHA512:
6
- metadata.gz: df9e4553cde84385a09506d7beb03f2ddb9e1b0ca2f2619c6e0f1e1e97a00c9b161df826bddf0627881f18327fa7d066fea3a2f1e3d268b44c7d9af9af18b720
7
- data.tar.gz: 316a5421865682ff2f5701135870429a8eb12c6814488f34a6a38357d87095b03d55e37c7a9326caf9667af09379d1d2504294f36f27b509fd52c686f9270baa
6
+ metadata.gz: f5ff7e424a0fb92555deb94a9db0144513b4b3cea233cd33d5aa5ef1069e062db8ab9db94852f46ca913595660fc46269b6db58eddb2e730443009a9afabfece
7
+ data.tar.gz: 36e104bf7cf3a755f5fe698551e4f7f9fccc5a7b435108f04cf3508b1bf903ec5737c441ffcdf54c106dfa77fd28ea5498d6b6a78776c7343792bfae757b4e7b
data/README.md CHANGED
@@ -73,15 +73,15 @@ You can use the following methods to query your data:
73
73
  * `#sum`
74
74
  * `#funnel`
75
75
 
76
- The examples are based on the following events:
76
+ The examples are based on the following events
77
77
 
78
78
  ```ruby
79
79
  AppMonit::Event.create(:registered, user: { id: '1' })
80
80
  AppMonit::Event.create(:registered, user: { id: '2' })
81
81
 
82
- AppMonit::Event.create(:purchase, user: { id: '1' }, product: { price_in_cents: 100, name: 'water', alcoholic: false })
83
- AppMonit::Event.create(:purchase, user: { id: '1' }, product: { price_in_cents: 150, name: 'soda', alcoholic: false })
84
- AppMonit::Event.create(:purchase, user: { id: '1' }, product: { price_in_cents: 200, name: 'beer', alcoholic: true })
82
+ AppMonit::Event.create(:purchase, user: { id: '1' }, product: { price_in_cents: 100, name: 'water', alcoholic: false, tags: ['plain', 'wet'] })
83
+ AppMonit::Event.create(:purchase, user: { id: '1' }, product: { price_in_cents: 150, name: 'soda', alcoholic: false, tags: ['sparkling', 'wet'] })
84
+ AppMonit::Event.create(:purchase, user: { id: '1' }, product: { price_in_cents: 200, name: 'beer', alcoholic: true, tags: ['sparkling', 'wet'] })
85
85
  ```
86
86
 
87
87
  #### `#count`
@@ -177,6 +177,16 @@ AppMonit::Query.count('registered', group_by: 'alcoholic') #=> { 'result' => [{
177
177
  # { 'alcoholic' => false, result => 2 }]
178
178
  ```
179
179
 
180
+ #### Expanded group by
181
+
182
+ You can specify a group to expand when querying your data:
183
+
184
+ ```ruby
185
+ AppMonit::Query.count('registered', expanded_group_by: 'tags') #=> { 'result' => [{ 'tags' => 'wet', result => 3 }
186
+ # { 'tags' => 'sparkling', result => 2 }]
187
+ # { 'tags' => 'plain', result => 1 }]
188
+ ```
189
+
180
190
  #### Filter
181
191
 
182
192
  You can specify a filter when querying your data:
@@ -7,7 +7,7 @@ module AppMonit
7
7
  rescue Http::Error
8
8
  false
9
9
  rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse,
10
- Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ETIMEDOUT => error
10
+ Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ETIMEDOUT, Errno::ECONNREFUSED => error
11
11
  raise error unless AppMonit::Config.fail_silent
12
12
  false
13
13
  end
@@ -39,7 +39,8 @@ module AppMonit
39
39
  end
40
40
 
41
41
  # set headers so event data ends up in the correct bucket on the other side
42
- request.add_field('Appmonit-Api-Key', AppMonit::Config.api_key)
42
+ # only add Appmonit-Api-Key header if there was no api_key configured in the params
43
+ request.add_field('Appmonit-Api-Key', AppMonit::Config.api_key) unless api_key(path)
43
44
  request.add_field('Appmonit-Env', AppMonit::Config.env)
44
45
  response = client.request(request)
45
46
 
@@ -47,5 +48,17 @@ module AppMonit
47
48
 
48
49
  response
49
50
  end
51
+
52
+ private
53
+
54
+ def api_key(path)
55
+ params(path).fetch('api_key', nil)
56
+ end
57
+
58
+ def params(path)
59
+ URI.decode_www_form(URI.parse(path).query).to_h
60
+ rescue
61
+ {}
62
+ end
50
63
  end
51
64
  end
@@ -1,3 +1,3 @@
1
1
  module AppMonit
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -9,17 +9,36 @@ describe AppMonit::Query do
9
9
  AppMonit::Config.env = nil
10
10
  end
11
11
 
12
- %w(count count_unique minimum maximum average sum funnel).each do |method_name|
13
- describe method_name do
14
- it 'gets the results with the given params' do
15
- stub_request(:get, /api.appmon.it\/v1\/queries\/#{method_name}/).to_return(body: {result: '0'}.to_json)
12
+ describe 'No api_key has been added to the params' do
13
+ %w(count count_unique minimum maximum average sum funnel).each do |method_name|
14
+ describe method_name do
15
+ it 'gets the results with the given params' do
16
+ stub_request(:get, /api.appmon.it\/v1\/queries\/#{method_name}/).to_return(body: {result: '0'}.to_json)
16
17
 
17
- params = { valid: 'params' }
18
- subject.send(method_name, 'collection_name', params)
18
+ params = { valid: 'params' }
19
+ subject.send(method_name, 'collection_name', params)
19
20
 
20
- params[:event_collection] = 'collection_name'
21
+ params[:event_collection] = 'collection_name'
21
22
 
22
- assert_requested(:get, /api.appmon.it\/v1\/queries\/#{method_name}\?query=#{params.to_json}/)
23
+ assert_requested(:get, /api.appmon.it\/v1\/queries\/#{method_name}\?query=#{params.to_json}/)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ describe 'An api_key has been added to the params' do
30
+ %w(count count_unique minimum maximum average sum funnel).each do |method_name|
31
+ describe method_name do
32
+ it 'gets the results with the given params' do
33
+ stub_request(:get, /api.appmon.it\/v1\/queries\/#{method_name}/).to_return(body: {result: '0'}.to_json)
34
+
35
+ params = { valid: 'params', api_key: 'XXX' }
36
+ subject.send(method_name, 'collection_name', params)
37
+
38
+ params[:event_collection] = 'collection_name'
39
+
40
+ assert_requested(:get, /api.appmon.it\/v1\/queries\/#{method_name}\?api_key=XXX&query=#{params.to_json}/)
41
+ end
23
42
  end
24
43
  end
25
44
  end
data/test.rb CHANGED
@@ -1,13 +1,26 @@
1
1
  $:<<'lib'
2
2
  require 'app_monit'
3
3
 
4
- AppMonit::Config.end_point = 'http://localhost:3000'
5
- AppMonit::Config.api_key = 'SOMEKEY'
6
- AppMonit::Config.enabled = true
7
- AppMonit::Config.async = true
8
- AppMonit::Config.flush_rate = 1
4
+ AppMonit::Config.end_point = 'http://localhost:3000'
5
+ AppMonit::Config.api_key = 'SOMEKEY'
6
+ AppMonit::Config.enabled = true
7
+ AppMonit::Config.async = false
8
+ AppMonit::Config.flush_rate = 1
9
+ AppMonit::Config.fail_silent = true
9
10
 
10
- AppMonit::Event.create('test', with: 'payload')
11
+ trap(:INT) { @running = false }
12
+ @running = true
13
+ index = 0
14
+ t = Time.now
15
+ while @running do
16
+ AppMonit::Event.create('test', with: 'payload', also: { nested: 'values' })
17
+ index += 1
11
18
 
12
- AppMonit.logger.debug 'Press enter to exit'
13
- gets
19
+ # @running = index < 10
20
+
21
+ if index == 1000
22
+ p "Events per second: #{1000 / (Time.now - t)}"
23
+ index = 0
24
+ t = Time.now
25
+ end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_monit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Redmar Kerkhoff
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-03 00:00:00.000000000 Z
12
+ date: 2016-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.4.5
135
+ rubygems_version: 2.5.1
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Client gem for pushing events from ruby to the appmon.it service