Skip to content

Commit 1ed9687

Browse files
authored
feat: update puma and autotuner plugins (#644)
* feat: update puma and autotuner plugins This allows the puma and autotuner to emit an event for stats, or alternavitely aggregate the stats to save on data. Disable stats events for puma and autotuner: ``` puma: insights: events: false autotuner: insights: events: false ``` Note: The autotuner plugin will still event the `report.autotuner` event regardless of the above setting. Enable aggregated metics for puma and autotuner. ``` puma: insights: metrics: true autotuner: insights: metrics: true ``` * Fix test for changes in Sinatra
1 parent dfd3522 commit 1ed9687

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

lib/honeybadger/config/defaults.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,31 @@ class Boolean; end
491491
description: "Number of seconds between registry flushes.",
492492
default: 60,
493493
type: Integer
494+
},
495+
:'puma.insights.events' => {
496+
description: 'Enable automatic event capturing for Puma stats.',
497+
default: true,
498+
type: Boolean
499+
},
500+
:'puma.insights.metrics' => {
501+
description: 'Enable automatic metric data aggregation for Puma stats.',
502+
default: false,
503+
type: Boolean
504+
},
505+
:'puma.insights.collection_interval' => {
506+
description: 'The frequency in which the Honeybadger gem will collect Puma stats.',
507+
default: 1,
508+
type: Integer
509+
},
510+
:'autotuner.insights.events' => {
511+
description: 'Enable automatic event capturing for Autotuner stats.',
512+
default: true,
513+
type: Boolean
514+
},
515+
:'autotuner.insights.metrics' => {
516+
description: 'Enable automatic metric data aggregation for Autotuner stats.',
517+
default: false,
518+
type: Boolean
494519
}
495520
}.freeze
496521

lib/honeybadger/plugins/autotuner.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ module Autotuner
1010
execution do
1111
singleton_class.include(Honeybadger::InstrumentationHelper)
1212

13-
::Autotuner.enabled = true
14-
1513
::Autotuner.reporter = proc do |report|
1614
Honeybadger.event("report.autotuner", report: report.to_s)
1715
end
1816

19-
metric_source 'autotuner'
20-
2117
::Autotuner.metrics_reporter = proc do |metrics|
22-
metrics.each do |key, val|
23-
gauge key, ->{ val }
18+
if config.load_plugin_insights_events?(:autotuner)
19+
Honeybadger.event('stats.autotuner', metrics)
20+
end
21+
22+
if config.load_plugin_insights_metrics?(:autotuner)
23+
metric_source 'autotuner'
24+
metrics.each do |key, val|
25+
gauge key, ->{ val }
26+
end
2427
end
2528
end
2629
end

lib/puma/plugin/honeybadger.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def start(launcher)
1212
in_background do
1313
loop do
1414
puma_plugin.record
15-
sleep 1
15+
sleep [::Honeybadger.config.collection_interval(:puma).to_i, 1].max
1616
end
1717
end
1818
end
@@ -35,8 +35,14 @@ def record
3535
end
3636

3737
def record_puma_stats(stats, context={})
38-
STATS_KEYS.each do |stat|
39-
gauge stat, context, ->{ stats[stat] } if stats[stat]
38+
if Honeybadger.config.load_plugin_insights_events?(:puma)
39+
Honeybadger.event('stats.puma', context.merge(stats))
40+
end
41+
42+
if Honeybadger.config.load_plugin_insights_metrics?(:puma)
43+
STATS_KEYS.each do |stat|
44+
gauge stat, context, ->{ stats[stat] } if stats[stat]
45+
end
4046
end
4147
end
4248
end

spec/fixtures/sinatra/app.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'sinatra/base'
22

33
class SinatraApp < Sinatra::Base
4+
set :host_authorization, { permitted_hosts: [] }
45
set :show_exceptions, false
56
set :honeybadger_api_key, 'gem testing'
67

0 commit comments

Comments
 (0)