Skip to content

Commit

Permalink
Move requires to top of file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
richardTowers committed Sep 14, 2023
1 parent b03fe38 commit ab6e400
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/govuk_app_config/govuk_prometheus_exporter.rb
Original file line number Diff line number Diff line change
@@ -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...
Expand All @@ -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
Expand Down

0 comments on commit ab6e400

Please sign in to comment.