Multisite support for sidekiq paused metric.

Multisite support for sidekiq paused metric.

diff --git a/lib/internal_metric/global.rb b/lib/internal_metric/global.rb
index b7c9577..f041d11 100644
--- a/lib/internal_metric/global.rb
+++ b/lib/internal_metric/global.rb
@@ -61,7 +61,7 @@ module DiscoursePrometheus::InternalMetric
       end
 
       @sidekiq_processes = (Sidekiq::ProcessSet.new.size || 0) rescue 0
-      @sidekiq_paused = Sidekiq.paused? ? 1 : 0
+      @sidekiq_paused = sidekiq_paused_states
     end
 
     private
@@ -131,5 +131,15 @@ module DiscoursePrometheus::InternalMetric
       # no db
       0
     end
+
+    def sidekiq_paused_states
+      paused = {}
+
+      RailsMultisite::ConnectionManagement.each_connection do |db|
+        paused[{ db: db }] = Sidekiq.paused? ? 1 : nil
+      end
+
+      paused
+    end
   end
 end
diff --git a/spec/lib/internal_metric/global_spec.rb b/spec/lib/internal_metric/global_spec.rb
index 622e100..2938f84 100644
--- a/spec/lib/internal_metric/global_spec.rb
+++ b/spec/lib/internal_metric/global_spec.rb
@@ -2,23 +2,35 @@ require 'rails_helper'
 
 module DiscoursePrometheus::InternalMetric
   describe Global do
-    after do
-      $redis.flushall
-    end
-
     it "can collect global metrics" do
       metric = Global.new
       metric.collect
 
       expect(metric.sidekiq_processes).not_to eq(nil)
-      expect(metric.sidekiq_paused).to eq(0)
       expect(metric.postgres_master_available).to eq(1)
       expect(metric.postgres_replica_available).to eq(nil)
+    end
 
-      Sidekiq.pause!
-      metric.collect
+    describe 'sidekiq paused' do
+      after do
+        Sidekiq.unpause_all!
+      end
+
+      it "should collect the right metrics" do
+        metric = Global.new
+        metric.collect
+
+        expect(metric.sidekiq_paused).to eq({
+          {db: RailsMultisite::ConnectionManagement.current_db} => nil
+        })
 
-      expect(metric.sidekiq_paused).to eq(1)
+        Sidekiq.pause!
+        metric.collect
+
+        expect(metric.sidekiq_paused).to eq({
+          {db: RailsMultisite::ConnectionManagement.current_db} => 1
+        })
+      end
     end
 
     describe 'when a replica has been configured' do

GitHub sha: 041c108e

1 Like