FIX: hostname not being checked correctly

FIX: hostname not being checked correctly

Tests missed that it should have been PrometheusExporter.hostname cause unfortunately Sidekiq had no workers in the specs

This makes this a bit more robust by getting the hostname prior to the loop

diff --git a/lib/internal_metric/global.rb b/lib/internal_metric/global.rb
index 0d6cf63..4702632 100644
--- a/lib/internal_metric/global.rb
+++ b/lib/internal_metric/global.rb
@@ -71,9 +71,11 @@ module DiscoursePrometheus::InternalMetric
         stats
       end
 
+      hostname = ::PrometheusExporter.hostname
+
       @sidekiq_processes = 0
       @sidekiq_workers = Sidekiq::ProcessSet.new.sum do |process|
-        if process["hostname"] == ::DiscoursePrometheus.hostname
+        if process["hostname"] == hostname
           @sidekiq_processes += 1
           process["concurrency"]
         else
@@ -82,7 +84,7 @@ module DiscoursePrometheus::InternalMetric
       end
 
       @sidekiq_stuck_workers = Sidekiq::Workers.new.filter do |queue, _, w|
-        queue.start_with?(::DiscoursePrometheus.hostname) && Time.at(w["run_at"]) < (Time.now - 60 * STUCK_JOB_MINUTES)
+        queue.start_with?(hostname) && Time.at(w["run_at"]) < (Time.now - 60 * STUCK_JOB_MINUTES)
       end.count
 
       @sidekiq_paused = sidekiq_paused_states

GitHub sha: b9ca8519

1 Like