From ab6e400a06f031d617b39c881e2b2fda12e4c5d7 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Thu, 14 Sep 2023 10:14:35 +0100 Subject: [PATCH] Move requires to top of file This is needed because I want to use a class from prometheus_exporter/metric as the default for a method parameter, which means I need to require the prometheus code before I use it. Previously these requires happened conditionally, so if `should_configure` was false, the prometheus code wouldn't be loaded at all. From a quick look at the prometheus exporter code, I don't think the requires have any side effects, so it should be fine to load them even when we're not configuring prometheus. --- lib/govuk_app_config/govuk_prometheus_exporter.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/govuk_app_config/govuk_prometheus_exporter.rb b/lib/govuk_app_config/govuk_prometheus_exporter.rb index 0e2be64..986b2f1 100644 --- a/lib/govuk_app_config/govuk_prometheus_exporter.rb +++ b/lib/govuk_app_config/govuk_prometheus_exporter.rb @@ -1,3 +1,8 @@ +require "prometheus_exporter" +require "prometheus_exporter/metric" +require "prometheus_exporter/server" +require "prometheus_exporter/middleware" + module GovukPrometheusExporter def self.should_configure # Allow us to force the Prometheus Exporter for persistent Rake tasks... @@ -11,13 +16,9 @@ def self.should_configure end end - def self.configure(collectors: [], default_aggregation: Prometheus::Metric::Histogram) + def self.configure(collectors: [], default_aggregation: PrometheusExporter::Metric::Histogram) return unless should_configure - require "prometheus_exporter" - require "prometheus_exporter/server" - require "prometheus_exporter/middleware" - # PrometheusExporter::Metric::Histogram.DEFAULT_BUCKETS tops out at 10 but # we have a few controller actions which are slower than this, so we add a # few extra buckets for slower requests