Skip to content

Commit efabf4f

Browse files
committed
Disable metrics collection in taste tester mode by default
Foo Foo 2
1 parent 8fbed5b commit efabf4f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cookbooks/boxcutter_chef/files/config/metrics_handler.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
module Boxcutter
55
class MetricsHandler < ::Chef::Handler
6+
FORCE_METRICS_COLLECTOR = '/var/chef/chef-force-metrics-collector'.freeze
7+
68
def initialize(path: '/var/chef/reports', filename: 'chef-run-metrics.json')
79
@path = path
810
@filename = filename
@@ -61,8 +63,24 @@ def write_metrics
6163
'updated_resources_count' => run_status.updated_resources.count,
6264
}
6365

66+
if taste_tester? && !force_metrics_collector?
67+
Chef::Log.info(
68+
'boxcutter_chef: metrics_handler - In taste tester mode. Metrics collector not running.' +
69+
"To override, touch #{FORCE_METRICS_COLLECTOR}",
70+
)
71+
return
72+
end
73+
6474
File.open(metrics_path, 'w') { |f| f.write(JSON.pretty_generate(out)) }
65-
Chef::Log.info("wrote chef run metrics to #{metrics_path}")
75+
Chef::Log.info("boxcutter_chef: metrics_hander - wrote chef run metrics to #{metrics_path}")
76+
end
77+
78+
def taste_tester?
79+
!Chef::Config[:chef_server_url].start_with?('chefzero://')
80+
end
81+
82+
def force_metrics_collector?
83+
File.exist?(FORCE_METRICS_COLLECTOR )
6684
end
6785
end
6886
end

0 commit comments

Comments
 (0)