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 +4 -4
- data/README.md +14 -4
- data/lib/app_monit/event.rb +1 -1
- data/lib/app_monit/http.rb +14 -1
- data/lib/app_monit/version.rb +1 -1
- data/spec/app_monit/query_spec.rb +27 -8
- data/test.rb +21 -8
- 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: 77edac5c532fcf5239cfbe239328f0141c7351b5
|
4
|
+
data.tar.gz: e1e5f037eb95285a8fb6e3d2cd906969dbb7930a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
data/lib/app_monit/event.rb
CHANGED
@@ -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
|
data/lib/app_monit/http.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/app_monit/version.rb
CHANGED
@@ -9,17 +9,36 @@ describe AppMonit::Query do
|
|
9
9
|
AppMonit::Config.env = nil
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
18
|
+
params = { valid: 'params' }
|
19
|
+
subject.send(method_name, 'collection_name', params)
|
19
20
|
|
20
|
-
|
21
|
+
params[:event_collection] = 'collection_name'
|
21
22
|
|
22
|
-
|
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
|
5
|
-
AppMonit::Config.api_key
|
6
|
-
AppMonit::Config.enabled
|
7
|
-
AppMonit::Config.async
|
8
|
-
AppMonit::Config.flush_rate
|
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
|
-
|
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
|
-
|
13
|
-
|
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.
|
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:
|
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.
|
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
|