From a3aa67b375195d5b8994c91edfeca7d3361a4a45 Mon Sep 17 00:00:00 2001 From: Dany Sam Date: Thu, 3 Oct 2024 13:16:54 +0530 Subject: [PATCH] Fix autoload not picking up prometheus.rb (#5478) **Story card:** [sc-13408](https://app.shortcut.com/simpledotorg/story/13408/migrate-pending-custom-metrics-to-prometheus-from-datadog) ## Because The Zeitwork mode is failing to load the prometheus.rb file in production environments. Even though other .rb files are working fine. ## This addresses As a temporary fix, we'll move Prometheus within the Metrics module --- lib/metrics.rb | 18 ++++++++++++++++++ lib/prometheus.rb | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 lib/prometheus.rb diff --git a/lib/metrics.rb b/lib/metrics.rb index c9e6a8944c..9418e7eecd 100644 --- a/lib/metrics.rb +++ b/lib/metrics.rb @@ -48,4 +48,22 @@ def benchmark_and_record_metric(type, event, labels, description) elapsed_time_seconds = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start record_metric(type, event, elapsed_time_seconds, labels, description) end + + class Prometheus + include Singleton + + def initialize + @client = PrometheusExporter::Client.default + @collectors = {} + end + + def register(type, name, description = nil) + @collectors[name] ||= @client.register(type, name, description) + self + end + + def observe(name, value, labels = {}) + @collectors[name].observe(value, labels) + end + end end diff --git a/lib/prometheus.rb b/lib/prometheus.rb deleted file mode 100644 index 1e67a1aaec..0000000000 --- a/lib/prometheus.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "prometheus_exporter/client" -class Prometheus - include Singleton - - def initialize - @client = PrometheusExporter::Client.default - @collectors = {} - end - - def register(type, name, description = nil) - @collectors[name] ||= @client.register(type, name, description) - self - end - - def observe(name, value, labels = {}) - @collectors[name].observe(value, labels) - end -end