trashed 3.0.0 → 3.0.1
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/lib/trashed/rack.rb +15 -8
- data/lib/trashed/reporter.rb +12 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc92cf23f413c7dbc13b7e974f0ff667050296dd
|
4
|
+
data.tar.gz: 83a9dacf210062f9aec4d1632095989ec20be08b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a13685415df07c31c6b3a95afc25ac2b22c18325b8b799c9b3eb4fca7a4bf805bc0c5bf4acb5f787f4a401214b3c79e05f5d5464deb33936cc5488fbe5934d2f
|
7
|
+
data.tar.gz: ad71d73f6ded5cd28c032b54b45ccec80eccbd2cf129c50582740b0d187331fa8af13db2384e26312b4ba8721f37ee11a098c6fa886280e2b03d7e48e3d71ea3
|
data/lib/trashed/rack.rb
CHANGED
@@ -7,14 +7,7 @@ module Trashed
|
|
7
7
|
def initialize(app, reporter, options = {})
|
8
8
|
@reporter = reporter
|
9
9
|
@meters = Array(options.fetch(:meters, [ResourceUsage]))
|
10
|
-
@
|
11
|
-
@sample_rate ||= 1.0
|
12
|
-
|
13
|
-
@request_namespaces = options[:statsd_request_namespaces]
|
14
|
-
@sampler_namespaces = options[:statsd_sampler_namespaces]
|
15
|
-
|
16
|
-
# Wrap the app up in the meters.
|
17
|
-
@app = build_instrumented_app(app, @meters)
|
10
|
+
@app = build_sampled_instrumented_app(app, @meters)
|
18
11
|
end
|
19
12
|
|
20
13
|
def call(env)
|
@@ -26,6 +19,20 @@ module Trashed
|
|
26
19
|
end
|
27
20
|
|
28
21
|
private
|
22
|
+
def build_sampled_instrumented_app(app, meters)
|
23
|
+
build_sampled_app app, build_instrumented_app(app, meters)
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_sampled_app(app, instrumented)
|
27
|
+
lambda do |env|
|
28
|
+
if @reporter.sample? env
|
29
|
+
instrumented.call env
|
30
|
+
else
|
31
|
+
app.call env
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
29
36
|
def build_instrumented_app(app, meters)
|
30
37
|
meters.inject app do |wrapped, meter|
|
31
38
|
lambda do |env|
|
data/lib/trashed/reporter.rb
CHANGED
@@ -15,17 +15,24 @@ module Trashed
|
|
15
15
|
@gauge_dimensions = ->(env) { DEFAULT_DIMENSIONS }
|
16
16
|
end
|
17
17
|
|
18
|
+
# Override in subclasses. Be sure to `super && ...` if you want to rely
|
19
|
+
# on the sample_rate.
|
20
|
+
def sample?(env = nil)
|
21
|
+
random_sample?
|
22
|
+
end
|
23
|
+
|
24
|
+
def random_sample?
|
25
|
+
@sample_rate == 1 or rand < @sample_rate
|
26
|
+
end
|
27
|
+
|
18
28
|
def report(env)
|
19
29
|
report_logger env if @logger
|
20
30
|
report_statsd env if @statsd
|
21
31
|
end
|
22
32
|
|
23
33
|
def report_logger(env)
|
24
|
-
|
25
|
-
|
26
|
-
if elapsed && gc_runs
|
27
|
-
@logger.info "Rack handled in %dms (GC runs: %d)" % [elapsed[1], gc_runs[1]]
|
28
|
-
end
|
34
|
+
timings = env[Trashed::Rack::TIMINGS]
|
35
|
+
@logger.info "Rack handled in %dms (GC runs: %d)" % timings.values_at(:'Time.wall', :'GC.count')
|
29
36
|
end
|
30
37
|
|
31
38
|
def report_statsd(env)
|