librato-rack 0.6.0 → 1.0.0.beta1
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +3 -0
- data/README.md +22 -0
- data/lib/librato/rack.rb +85 -33
- data/lib/librato/rack/configuration.rb +25 -2
- data/lib/librato/rack/configuration/suites.rb +58 -0
- data/lib/librato/rack/errors.rb +3 -1
- data/lib/librato/rack/tracker.rb +4 -0
- data/lib/librato/rack/version.rb +1 -1
- data/test/apps/basic.ru +16 -1
- data/test/apps/custom_suites.ru +18 -0
- data/test/integration/no_suites_test.rb +71 -0
- data/test/integration/suites_test.rb +48 -0
- data/test/support/environment_helpers.rb +23 -0
- data/test/test_helper.rb +1 -0
- data/test/unit/rack/configuration/suites_test.rb +94 -0
- data/test/unit/rack/configuration_test.rb +6 -23
- data/test/unit/rack/tracker_test.rb +11 -0
- metadata +15 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 925119ebbdc1da99d8586de3f7c98b0a02b637af
|
4
|
+
data.tar.gz: 2c584413df2ea05a8fab05eb9e5c5116ffd15dbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8871cf91b56d26f7ed25d54fb6f0e93e3f8b9f012bc34b053bd4b7957601b7086c24c968e941b1791207413d4ff92f8f05684468234d5e9072ee3cdd2c72a5e6
|
7
|
+
data.tar.gz: 95712a3eb73c604413ad33bc9a2f77cdb49de8e75ec58bfb80a5728d948dc38394362a23144b9e38f322485e0156dfefe738ebca7c9c6f625942a4394c4d0205
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -83,6 +83,28 @@ NOTE: if Heroku idles your application no measurements will be sent until it rec
|
|
83
83
|
|
84
84
|
When using in an evented context set LIBRATO_EVENT_MODE to `'eventmachine'` if using [EventMachine](https://github.com/eventmachine/eventmachine) or `'synchrony'` if using [EM Synchrony](https://github.com/igrigorik/em-synchrony) and/or [Rack::FiberPool](https://github.com/alebsack/rack-fiber_pool). We're interested in maturing this support, so please let us know if you have any issues.
|
85
85
|
|
86
|
+
##### Metric Suites
|
87
|
+
|
88
|
+
The metrics recorded by `librato-rack` are organized into named metric suites that can be selecitvely enabled/disabled:
|
89
|
+
|
90
|
+
* `rack`: The `rack.request.total`, `rack.request.time`, `rack.request.slow`, and `rack.request.queue.time` metrics
|
91
|
+
* `rack_status`: All of the `rack.request.status` metrics
|
92
|
+
* `rack_method`: All of the `rack.request.method` metrics
|
93
|
+
|
94
|
+
All three of the metric suites listed above are enabled by default.
|
95
|
+
|
96
|
+
The metric suites can be configured via either the `LIBRATO_SUITES` environment variable or the `suites` attributes on the `Librato::Rack::Configuration` object.
|
97
|
+
|
98
|
+
LIBRATO_SUITES="rack,rack_method" # use ONLY the rack and rack_method suites
|
99
|
+
LIBRATO_SUITES="+foo,+bar" # + prefix indicates that you want the default suites plus foo and bar
|
100
|
+
LIBRATO_SUITES="-rack_status" # - prefix indicates that you want the default suites removing rack_status
|
101
|
+
LIBRATO_SUITES="+foo,-rack_status" # Use all default suites except for rack_status while also adding foo
|
102
|
+
LIBRATO_SUITES="all" # Enable all suites
|
103
|
+
LIBRATO_SUITES="none" # Disable all suites
|
104
|
+
LIBRATO_SUITES="" # Use only the default suites (same as if env var is absent)
|
105
|
+
|
106
|
+
Note that you should EITHER specify an explict list of suites to enable OR add/subtract individual suites from the default list (using the +/- prefixes). If you try to mix these two forms a `Librato::Rack::InvalidSuiteConfiguration` error will be raised.
|
107
|
+
|
86
108
|
## Custom Measurements
|
87
109
|
|
88
110
|
Tracking anything that interests you is easy with Metrics. There are four primary helpers available:
|
data/lib/librato/rack.rb
CHANGED
@@ -37,6 +37,30 @@ module Librato
|
|
37
37
|
# run MyApp
|
38
38
|
#
|
39
39
|
class Rack
|
40
|
+
RECORD_RACK_BODY = <<-'EOS'
|
41
|
+
group.increment 'total'
|
42
|
+
group.timing 'time', duration
|
43
|
+
group.increment 'slow' if duration > 200.0
|
44
|
+
EOS
|
45
|
+
|
46
|
+
RECORD_RACK_STATUS_BODY = <<-'EOS'
|
47
|
+
group.group 'status' do |s|
|
48
|
+
s.increment status
|
49
|
+
s.increment "#{status.to_s[0]}xx"
|
50
|
+
|
51
|
+
s.timing "#{status}.time", duration
|
52
|
+
s.timing "#{status.to_s[0]}xx.time", duration
|
53
|
+
end
|
54
|
+
EOS
|
55
|
+
|
56
|
+
RECORD_RACK_METHOD_BODY = <<-'EOS'
|
57
|
+
group.group 'method' do |m|
|
58
|
+
http_method.downcase!
|
59
|
+
m.increment http_method
|
60
|
+
m.timing "#{http_method}.time", duration
|
61
|
+
end
|
62
|
+
EOS
|
63
|
+
|
40
64
|
attr_reader :config, :tracker
|
41
65
|
|
42
66
|
def initialize(app, options={})
|
@@ -54,15 +78,18 @@ module Librato
|
|
54
78
|
if old_style
|
55
79
|
@tracker.deprecate 'middleware setup no longer takes a single argument, use `use Librato::Rack :config => config` instead.'
|
56
80
|
end
|
81
|
+
|
82
|
+
build_record_request_metrics_method
|
83
|
+
build_record_header_metrics_method
|
84
|
+
build_record_exception_method
|
57
85
|
end
|
58
86
|
|
59
87
|
def call(env)
|
60
88
|
check_log_output(env) unless @log_target
|
61
89
|
@tracker.check_worker
|
62
|
-
request_method = env["REQUEST_METHOD"]
|
63
90
|
record_header_metrics(env)
|
64
91
|
response, duration = process_request(env)
|
65
|
-
record_request_metrics(response.first,
|
92
|
+
record_request_metrics(response.first, env["REQUEST_METHOD"], duration)
|
66
93
|
response
|
67
94
|
end
|
68
95
|
|
@@ -100,47 +127,72 @@ module Librato
|
|
100
127
|
[response, duration]
|
101
128
|
end
|
102
129
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
130
|
+
|
131
|
+
# Dynamically construct :record_request_metrics method based on
|
132
|
+
# configured metric suites
|
133
|
+
def build_record_request_metrics_method
|
134
|
+
body = "def record_request_metrics(status, http_method, duration)\n"
|
135
|
+
body << "return if config.disable_rack_metrics\n"
|
136
|
+
|
137
|
+
unless config.instance_of?(Librato::Rack::Configuration::SuitesNone)
|
138
|
+
body << "tracker.group 'rack.request' do |group|\n"
|
139
|
+
|
140
|
+
if tracker.suite_enabled?(:rack)
|
141
|
+
body << RECORD_RACK_BODY
|
114
142
|
end
|
143
|
+
|
144
|
+
if tracker.suite_enabled?(:rack_status)
|
145
|
+
body << RECORD_RACK_STATUS_BODY
|
146
|
+
end
|
147
|
+
|
148
|
+
if tracker.suite_enabled?(:rack_method)
|
149
|
+
body << RECORD_RACK_METHOD_BODY
|
150
|
+
end
|
151
|
+
|
152
|
+
body << "end\n"
|
115
153
|
end
|
116
|
-
end
|
117
154
|
|
118
|
-
|
119
|
-
return if config.disable_rack_metrics
|
120
|
-
tracker.group 'rack.request' do |group|
|
121
|
-
group.increment 'total'
|
122
|
-
group.timing 'time', duration, percentile: 95
|
123
|
-
group.increment 'slow' if duration > 200.0
|
155
|
+
body << "end\n"
|
124
156
|
|
125
|
-
|
126
|
-
|
127
|
-
s.increment "#{status.to_s[0]}xx"
|
157
|
+
instance_eval(body)
|
158
|
+
end
|
128
159
|
|
129
|
-
|
130
|
-
|
160
|
+
# Dynamically construct :record_header_metrics method based on
|
161
|
+
# configured metric suites
|
162
|
+
def build_record_header_metrics_method
|
163
|
+
if tracker.suite_enabled?(:rack)
|
164
|
+
define_singleton_method(:record_header_metrics) do |env|
|
165
|
+
queue_start = env['HTTP_X_REQUEST_START'] || env['HTTP_X_QUEUE_START']
|
166
|
+
if queue_start
|
167
|
+
queue_start = queue_start.to_s.sub('t=', '').sub('.', '')
|
168
|
+
case queue_start.length
|
169
|
+
when 16 # microseconds
|
170
|
+
wait = ((Time.now.to_f * 1000000).to_i - queue_start.to_i) / 1000.0
|
171
|
+
tracker.timing 'rack.request.queue.time', wait, percentile: 95
|
172
|
+
when 13 # milliseconds
|
173
|
+
wait = (Time.now.to_f * 1000).to_i - queue_start.to_i
|
174
|
+
tracker.timing 'rack.request.queue.time', wait, percentile: 95
|
175
|
+
end
|
176
|
+
end
|
131
177
|
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
m.increment http_method
|
136
|
-
m.timing "#{http_method}.time", duration
|
178
|
+
else
|
179
|
+
define_singleton_method(:record_header_metrics) do |env|
|
180
|
+
# no-op
|
137
181
|
end
|
138
182
|
end
|
139
183
|
end
|
140
184
|
|
141
|
-
def
|
142
|
-
|
143
|
-
|
185
|
+
def build_record_exception_method
|
186
|
+
if tracker.suite_enabled?(:rack)
|
187
|
+
define_singleton_method(:record_exception) do |exception|
|
188
|
+
return if config.disable_rack_metrics
|
189
|
+
tracker.increment 'rack.request.exceptions'
|
190
|
+
end
|
191
|
+
else
|
192
|
+
define_singleton_method(:record_exception) do |exception|
|
193
|
+
# no-op
|
194
|
+
end
|
195
|
+
end
|
144
196
|
end
|
145
197
|
|
146
198
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
|
2
|
+
|
1
3
|
module Librato
|
2
4
|
class Rack
|
3
5
|
# Holds configuration for Librato::Rack middleware to use.
|
@@ -12,9 +14,11 @@ module Librato
|
|
12
14
|
class Configuration
|
13
15
|
EVENT_MODES = [:eventmachine, :synchrony]
|
14
16
|
|
17
|
+
DEFAULT_SUITES = [:rack, :rack_method, :rack_status]
|
18
|
+
|
15
19
|
attr_accessor :user, :token, :autorun, :api_endpoint, :tracker,
|
16
20
|
:source_pids, :log_level, :log_prefix, :log_target,
|
17
|
-
:disable_rack_metrics, :flush_interval, :proxy
|
21
|
+
:disable_rack_metrics, :flush_interval, :proxy, :suites
|
18
22
|
attr_reader :prefix, :source, :deprecations
|
19
23
|
|
20
24
|
def initialize
|
@@ -61,6 +65,7 @@ module Librato
|
|
61
65
|
self.log_level = ENV['LIBRATO_LOG_LEVEL'] || :info
|
62
66
|
self.proxy = ENV['LIBRATO_PROXY'] || ENV['https_proxy'] || ENV['http_proxy']
|
63
67
|
self.event_mode = ENV['LIBRATO_EVENT_MODE']
|
68
|
+
self.suites = ENV['LIBRATO_SUITES'] || ''
|
64
69
|
check_deprecations
|
65
70
|
end
|
66
71
|
|
@@ -80,14 +85,30 @@ module Librato
|
|
80
85
|
|
81
86
|
def dump
|
82
87
|
fields = {}
|
83
|
-
%w{user token log_level source prefix flush_interval source_pids}.each do |field|
|
88
|
+
%w{user token log_level source prefix flush_interval source_pids suites}.each do |field|
|
84
89
|
fields[field.to_sym] = self.send(field)
|
85
90
|
end
|
91
|
+
fields[:metric_suites] = metric_suites.fields
|
86
92
|
fields
|
87
93
|
end
|
88
94
|
|
95
|
+
def metric_suites
|
96
|
+
@metric_suites ||= case suites.downcase.strip
|
97
|
+
when 'all'
|
98
|
+
SuitesAll.new
|
99
|
+
when 'none'
|
100
|
+
SuitesNone.new
|
101
|
+
else
|
102
|
+
Suites.new(suites, default_suites)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
89
106
|
private
|
90
107
|
|
108
|
+
def default_suites
|
109
|
+
DEFAULT_SUITES
|
110
|
+
end
|
111
|
+
|
91
112
|
def check_deprecations
|
92
113
|
%w{USER TOKEN PREFIX SOURCE}.each do |item|
|
93
114
|
if ENV["LIBRATO_METRICS_#{item}"]
|
@@ -114,3 +135,5 @@ module Librato
|
|
114
135
|
end
|
115
136
|
end
|
116
137
|
end
|
138
|
+
|
139
|
+
require_relative 'configuration/suites'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Librato
|
2
|
+
class Rack
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
class Suites
|
6
|
+
attr_reader :fields
|
7
|
+
def initialize(value, defaults)
|
8
|
+
@fields = if value.nil? || value.empty?
|
9
|
+
defaults
|
10
|
+
else
|
11
|
+
resolve_suites(value, defaults)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def include?(field)
|
16
|
+
fields.include?(field)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def resolve_suites(value, defaults)
|
22
|
+
suites = value.to_s.split(/\s*,\s*/)
|
23
|
+
adds = suites.select { |i| i.start_with?('+') }.map { |i| i[1..-1].to_sym }
|
24
|
+
subs = suites.select { |i| i.start_with?('-') }.map { |i| i[1..-1].to_sym }
|
25
|
+
|
26
|
+
if adds.any? || subs.any?
|
27
|
+
|
28
|
+
# Did they try to mix adds/subs with explicit config
|
29
|
+
if (adds.size + subs.size) != suites.size
|
30
|
+
raise InvalidSuiteConfiguration, "Invalid suite value #{value}"
|
31
|
+
end
|
32
|
+
|
33
|
+
(defaults | adds) - subs
|
34
|
+
else
|
35
|
+
suites.map(&:to_sym)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class SuitesAll
|
41
|
+
def fields; [:all]; end
|
42
|
+
|
43
|
+
def include?(value)
|
44
|
+
true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class SuitesNone
|
49
|
+
def fields; []; end
|
50
|
+
|
51
|
+
def include?(value)
|
52
|
+
false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/librato/rack/errors.rb
CHANGED
data/lib/librato/rack/tracker.rb
CHANGED
data/lib/librato/rack/version.rb
CHANGED
data/test/apps/basic.ru
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'librato-rack'
|
3
3
|
|
4
|
+
# Simulate the environment variables Heroku passes along
|
5
|
+
# with each request
|
6
|
+
#
|
7
|
+
class QueueWait
|
8
|
+
def initialize(app)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
env['HTTP_X_QUEUE_START'] = (Time.now.to_f * 1000).to_i.to_s
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
use QueueWait
|
4
19
|
use Librato::Rack
|
5
20
|
|
6
21
|
def application(env)
|
@@ -17,4 +32,4 @@ def application(env)
|
|
17
32
|
end
|
18
33
|
end
|
19
34
|
|
20
|
-
run method(:application)
|
35
|
+
run method(:application)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'librato-rack'
|
3
|
+
|
4
|
+
config = Librato::Rack::Configuration.new
|
5
|
+
config.suites = '-rack_status,-rack_method'
|
6
|
+
|
7
|
+
use Librato::Rack, :config => config
|
8
|
+
|
9
|
+
def application(env)
|
10
|
+
case env['PATH_INFO']
|
11
|
+
when '/exception'
|
12
|
+
raise 'exception raised!'
|
13
|
+
else
|
14
|
+
[200, {"Content-Type" => 'text/html'}, ["Hello!"]]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
run method(:application)
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
# Tests to ensure tracking is disabled when a suite is removed. These tests
|
5
|
+
# largely ensure that behavior verified positively other suites doesn't
|
6
|
+
# happen when specific suites are disabled.
|
7
|
+
#
|
8
|
+
class NoSuitesTest < Minitest::Test
|
9
|
+
include Rack::Test::Methods
|
10
|
+
include EnvironmentHelpers
|
11
|
+
|
12
|
+
def app
|
13
|
+
ENV['LIBRATO_SUITES'] = 'none'
|
14
|
+
Rack::Builder.parse_file('test/apps/basic.ru').first
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
# clear metrics before each run
|
19
|
+
aggregate.delete_all
|
20
|
+
counters.delete_all
|
21
|
+
clear_config_env_vars
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_increment_total
|
25
|
+
get '/'
|
26
|
+
assert last_response.ok?
|
27
|
+
assert_nil counters["rack.request.total"], 'should not increment'
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_track_queue_time
|
31
|
+
get '/'
|
32
|
+
assert last_response.ok?
|
33
|
+
assert_equal nil, aggregate["rack.request.queue.time"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_increment_status
|
37
|
+
get '/'
|
38
|
+
assert last_response.ok?
|
39
|
+
assert_nil counters["rack.request.status.200"], 'should not increment'
|
40
|
+
assert_nil counters["rack.request.status.2xx"], 'should not increment'
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_track_http_method_info
|
44
|
+
get '/'
|
45
|
+
assert_nil counters['rack.request.method.get']
|
46
|
+
|
47
|
+
post '/'
|
48
|
+
assert_nil counters['rack.request.method.post']
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_increment_exception
|
52
|
+
begin
|
53
|
+
get '/exception'
|
54
|
+
rescue RuntimeError => e
|
55
|
+
raise unless e.message == 'exception raised!'
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_nil counters["rack.request.exceptions"], 'should not increment'
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def aggregate
|
64
|
+
Librato.tracker.collector.aggregate
|
65
|
+
end
|
66
|
+
|
67
|
+
def counters
|
68
|
+
Librato.tracker.collector.counters
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
# Tests to ensure config suites work
|
5
|
+
#
|
6
|
+
class SuitesTest < Minitest::Test
|
7
|
+
include Rack::Test::Methods
|
8
|
+
|
9
|
+
def app
|
10
|
+
Rack::Builder.parse_file('test/apps/custom_suites.ru').first
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
# clear metrics before each run
|
15
|
+
aggregate.delete_all
|
16
|
+
counters.delete_all
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_no_rack_status
|
20
|
+
get '/'
|
21
|
+
assert last_response.ok?
|
22
|
+
|
23
|
+
# rack.request metrics (rack suite) should get logged
|
24
|
+
assert_equal 1, counters["rack.request.total"]
|
25
|
+
assert_equal 1, aggregate["rack.request.time"][:count]
|
26
|
+
|
27
|
+
# rack.request.method metrics (rack_method suite) should not get logged
|
28
|
+
assert_equal nil, counters['rack.request.method.get']
|
29
|
+
assert_equal nil, aggregate['rack.request.method.get.time']
|
30
|
+
|
31
|
+
# rack.request.status metrics (rack_status suite) should not get logged
|
32
|
+
assert_equal nil, counters["rack.request.status.200"]
|
33
|
+
assert_equal nil, counters["rack.request.status.2xx"]
|
34
|
+
assert_equal nil, counters["rack.request.status.200.time"]
|
35
|
+
assert_equal nil, counters["rack.request.status.2xx.time"]
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def aggregate
|
41
|
+
Librato.tracker.collector.aggregate
|
42
|
+
end
|
43
|
+
|
44
|
+
def counters
|
45
|
+
Librato.tracker.collector.counters
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Helper methods for environment management that are shared
|
2
|
+
# between test files.
|
3
|
+
#
|
4
|
+
module EnvironmentHelpers
|
5
|
+
|
6
|
+
def clear_config_env_vars
|
7
|
+
ENV.delete('LIBRATO_USER')
|
8
|
+
ENV.delete('LIBRATO_TOKEN')
|
9
|
+
ENV.delete('LIBRATO_PROXY')
|
10
|
+
ENV.delete('LIBRATO_SOURCE')
|
11
|
+
ENV.delete('LIBRATO_PREFIX')
|
12
|
+
ENV.delete('LIBRATO_SUITES')
|
13
|
+
ENV.delete('LIBRATO_LOG_LEVEL')
|
14
|
+
ENV.delete('LIBRATO_EVENT_MODE')
|
15
|
+
# legacy - deprecated
|
16
|
+
ENV.delete('LIBRATO_METRICS_USER')
|
17
|
+
ENV.delete('LIBRATO_METRICS_TOKEN')
|
18
|
+
ENV.delete('LIBRATO_METRICS_SOURCE')
|
19
|
+
# system
|
20
|
+
ENV.delete('http_proxy')
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Librato
|
4
|
+
class Rack
|
5
|
+
class SuitesTest < Minitest::Test
|
6
|
+
include EnvironmentHelpers
|
7
|
+
|
8
|
+
def setup; clear_config_env_vars; end
|
9
|
+
def teardown; clear_config_env_vars; end
|
10
|
+
|
11
|
+
def test_suites_defaults
|
12
|
+
config = Configuration.new
|
13
|
+
assert config.metric_suites.include?(:rack), "should include 'rack' by default"
|
14
|
+
refute config.metric_suites.include?(:foo), "should not include 'foo' by default"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_suites_configured_by_explicit_list
|
18
|
+
ENV['LIBRATO_SUITES'] = 'abc, jkl,prq , xyz'
|
19
|
+
config = Configuration.new
|
20
|
+
[:abc, :jkl, :prq, :xyz].each do |suite|
|
21
|
+
assert config.metric_suites.include?(suite), "expected '#{suite}' to be active"
|
22
|
+
end
|
23
|
+
|
24
|
+
Librato::Rack::Configuration::DEFAULT_SUITES.each do |suite|
|
25
|
+
refute config.metric_suites.include?(suite), "should not include '#{suite}' by default"
|
26
|
+
end
|
27
|
+
|
28
|
+
refute config.metric_suites.include?(:something_else), 'should not include unspecified'
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_suites_configured_by_inclusion
|
32
|
+
ENV['LIBRATO_SUITES'] = '+abc, +jkl,+prq'
|
33
|
+
config = Configuration.new
|
34
|
+
|
35
|
+
[:abc, :jkl, :prq].each do |suite|
|
36
|
+
assert config.metric_suites.include?(suite), "expected '#{suite.to_s}' to be active"
|
37
|
+
end
|
38
|
+
|
39
|
+
Librato::Rack::Configuration::DEFAULT_SUITES.each do |suite|
|
40
|
+
assert config.metric_suites.include?(suite), "should include '#{suite}' by default"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_suites_configured_by_exclusion
|
45
|
+
ENV['LIBRATO_SUITES'] = '-rack_method,-jkl'
|
46
|
+
config = Configuration.new
|
47
|
+
|
48
|
+
[:rack_method, :jkl].each do |suite|
|
49
|
+
refute config.metric_suites.include?(suite), "expected '#{suite.to_s}' to be disabled"
|
50
|
+
end
|
51
|
+
|
52
|
+
assert config.metric_suites.include?(:rack), "should include 'rack' by default"
|
53
|
+
assert config.metric_suites.include?(:rack_status), "should include 'rack_status' by default"
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_suites_configured_by_inclusion_and_exclusion
|
57
|
+
ENV['LIBRATO_SUITES'] = '-rack_method, +foo'
|
58
|
+
config = Configuration.new
|
59
|
+
|
60
|
+
assert config.metric_suites.include?(:rack), "should include 'rack' by default"
|
61
|
+
assert config.metric_suites.include?(:rack_status), "should include 'rack_status' by default"
|
62
|
+
assert config.metric_suites.include?(:foo), "expected 'foo' to be active"
|
63
|
+
refute config.metric_suites.include?(:rack_method), "expected 'rack_method' to be disabled"
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_invalid_suite_config
|
67
|
+
ENV['LIBRATO_SUITES'] = '-rack_method, +foo ,bar'
|
68
|
+
|
69
|
+
assert_raises(Librato::Rack::InvalidSuiteConfiguration) {
|
70
|
+
Configuration.new.metric_suites
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_suites_all
|
75
|
+
ENV['LIBRATO_SUITES'] = 'all'
|
76
|
+
config = Configuration.new
|
77
|
+
|
78
|
+
[:foo, :bar, :baz].each do |suite|
|
79
|
+
assert config.metric_suites.include?(suite), "expected '#{suite}' to be active"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_suites_none
|
84
|
+
ENV['LIBRATO_SUITES'] = 'NONE'
|
85
|
+
config = Configuration.new
|
86
|
+
|
87
|
+
[:foo, :bar, :baz].each do |suite|
|
88
|
+
refute config.metric_suites.include?(suite), "expected '#{suite.to_s}' to be disabled"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -3,19 +3,16 @@ require 'test_helper'
|
|
3
3
|
module Librato
|
4
4
|
class Rack
|
5
5
|
class ConfigurationTest < Minitest::Test
|
6
|
+
include EnvironmentHelpers
|
6
7
|
|
7
|
-
def setup
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
clear_env_vars
|
13
|
-
end
|
8
|
+
def setup; clear_config_env_vars; end
|
9
|
+
def teardown; clear_config_env_vars; end
|
14
10
|
|
15
11
|
def test_defaults
|
16
12
|
config = Configuration.new
|
17
13
|
assert_equal 60, config.flush_interval
|
18
14
|
assert_equal Librato::Metrics.api_endpoint, config.api_endpoint
|
15
|
+
assert_equal '', config.suites
|
19
16
|
end
|
20
17
|
|
21
18
|
def test_environment_variable_config
|
@@ -23,11 +20,13 @@ module Librato
|
|
23
20
|
ENV['LIBRATO_TOKEN'] = 'api_key'
|
24
21
|
ENV['LIBRATO_SOURCE'] = 'source'
|
25
22
|
ENV['LIBRATO_PROXY'] = 'http://localhost:8080'
|
23
|
+
ENV['LIBRATO_SUITES'] = 'foo,bar'
|
26
24
|
config = Configuration.new
|
27
25
|
assert_equal 'foo@bar.com', config.user
|
28
26
|
assert_equal 'api_key', config.token
|
29
27
|
assert_equal 'source', config.source
|
30
28
|
assert_equal 'http://localhost:8080', config.proxy
|
29
|
+
assert_equal 'foo,bar', config.suites
|
31
30
|
#assert Librato::Rails.explicit_source, 'source is explicit'
|
32
31
|
end
|
33
32
|
|
@@ -89,22 +88,6 @@ module Librato
|
|
89
88
|
|
90
89
|
private
|
91
90
|
|
92
|
-
def clear_env_vars
|
93
|
-
ENV.delete('LIBRATO_USER')
|
94
|
-
ENV.delete('LIBRATO_TOKEN')
|
95
|
-
ENV.delete('LIBRATO_PROXY')
|
96
|
-
ENV.delete('LIBRATO_SOURCE')
|
97
|
-
ENV.delete('LIBRATO_PREFIX')
|
98
|
-
ENV.delete('LIBRATO_LOG_LEVEL')
|
99
|
-
ENV.delete('LIBRATO_EVENT_MODE')
|
100
|
-
# legacy
|
101
|
-
ENV.delete('LIBRATO_METRICS_USER')
|
102
|
-
ENV.delete('LIBRATO_METRICS_TOKEN')
|
103
|
-
ENV.delete('LIBRATO_METRICS_SOURCE')
|
104
|
-
# system
|
105
|
-
ENV.delete('http_proxy')
|
106
|
-
end
|
107
|
-
|
108
91
|
def listener_object
|
109
92
|
listener = Object.new
|
110
93
|
def listener.prefix=(prefix)
|
@@ -46,6 +46,17 @@ module Librato
|
|
46
46
|
ENV.delete('LIBRATO_AUTORUN')
|
47
47
|
end
|
48
48
|
|
49
|
+
def test_suite_configured
|
50
|
+
ENV['LIBRATO_SUITES'] = 'abc,prq'
|
51
|
+
|
52
|
+
tracker = Tracker.new(Configuration.new)
|
53
|
+
assert tracker.suite_enabled?(:abc)
|
54
|
+
assert tracker.suite_enabled?(:prq)
|
55
|
+
refute tracker.suite_enabled?(:xyz)
|
56
|
+
ensure
|
57
|
+
ENV.delete('LIBRATO_SUITES')
|
58
|
+
end
|
59
|
+
|
49
60
|
private
|
50
61
|
|
51
62
|
def buffer_lines
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: librato-rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Sanders
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
hvjx0WJP8pzZMJPKJBRZQXJO5ifEPyKjZyMi5XMHmrtDclHLj3sx4RAvEZjGWkRP
|
30
30
|
JSQ=
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
32
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: librato-metrics
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/librato/collector/group.rb
|
94
94
|
- lib/librato/rack.rb
|
95
95
|
- lib/librato/rack/configuration.rb
|
96
|
+
- lib/librato/rack/configuration/suites.rb
|
96
97
|
- lib/librato/rack/errors.rb
|
97
98
|
- lib/librato/rack/logger.rb
|
98
99
|
- lib/librato/rack/tracker.rb
|
@@ -101,20 +102,25 @@ files:
|
|
101
102
|
- lib/librato/rack/worker.rb
|
102
103
|
- test/apps/basic.ru
|
103
104
|
- test/apps/custom.ru
|
105
|
+
- test/apps/custom_suites.ru
|
104
106
|
- test/apps/deprecated.ru
|
105
107
|
- test/apps/no_stats.ru
|
106
108
|
- test/apps/queue_wait.ru
|
107
109
|
- test/integration/custom_test.rb
|
108
110
|
- test/integration/deprecated_test.rb
|
109
111
|
- test/integration/no_stats_test.rb
|
112
|
+
- test/integration/no_suites_test.rb
|
110
113
|
- test/integration/queue_wait_test.rb
|
111
114
|
- test/integration/request_test.rb
|
115
|
+
- test/integration/suites_test.rb
|
112
116
|
- test/remote/tracker_test.rb
|
117
|
+
- test/support/environment_helpers.rb
|
113
118
|
- test/test_helper.rb
|
114
119
|
- test/unit/collector/aggregator_test.rb
|
115
120
|
- test/unit/collector/counter_cache_test.rb
|
116
121
|
- test/unit/collector/group_test.rb
|
117
122
|
- test/unit/collector_test.rb
|
123
|
+
- test/unit/rack/configuration/suites_test.rb
|
118
124
|
- test/unit/rack/configuration_test.rb
|
119
125
|
- test/unit/rack/logger_test.rb
|
120
126
|
- test/unit/rack/tracker_test.rb
|
@@ -134,9 +140,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
140
|
version: '0'
|
135
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
142
|
requirements:
|
137
|
-
- - "
|
143
|
+
- - ">"
|
138
144
|
- !ruby/object:Gem::Version
|
139
|
-
version:
|
145
|
+
version: 1.3.1
|
140
146
|
requirements: []
|
141
147
|
rubyforge_project:
|
142
148
|
rubygems_version: 2.2.2
|
@@ -146,20 +152,25 @@ summary: Use Librato Metrics with your rack application
|
|
146
152
|
test_files:
|
147
153
|
- test/apps/basic.ru
|
148
154
|
- test/apps/custom.ru
|
155
|
+
- test/apps/custom_suites.ru
|
149
156
|
- test/apps/deprecated.ru
|
150
157
|
- test/apps/no_stats.ru
|
151
158
|
- test/apps/queue_wait.ru
|
152
159
|
- test/integration/custom_test.rb
|
153
160
|
- test/integration/deprecated_test.rb
|
154
161
|
- test/integration/no_stats_test.rb
|
162
|
+
- test/integration/no_suites_test.rb
|
155
163
|
- test/integration/queue_wait_test.rb
|
156
164
|
- test/integration/request_test.rb
|
165
|
+
- test/integration/suites_test.rb
|
157
166
|
- test/remote/tracker_test.rb
|
167
|
+
- test/support/environment_helpers.rb
|
158
168
|
- test/test_helper.rb
|
159
169
|
- test/unit/collector/aggregator_test.rb
|
160
170
|
- test/unit/collector/counter_cache_test.rb
|
161
171
|
- test/unit/collector/group_test.rb
|
162
172
|
- test/unit/collector_test.rb
|
173
|
+
- test/unit/rack/configuration/suites_test.rb
|
163
174
|
- test/unit/rack/configuration_test.rb
|
164
175
|
- test/unit/rack/logger_test.rb
|
165
176
|
- test/unit/rack/tracker_test.rb
|
metadata.gz.sig
CHANGED
Binary file
|