Don't set metric if Postgres replica has not been configured.

Don’t set metric if Postgres replica has not been configured.

From e43d5039b6da167fb15b907ea2cd951a1f72d02d Mon Sep 17 00:00:00 2001
From: Guo Xiang Tan <tgx_world@hotmail.com>
Date: Wed, 28 Nov 2018 08:25:25 +0800
Subject: [PATCH] Don't set metric if Postgres replica has not been configured.


diff --git a/lib/internal_metric/global.rb b/lib/internal_metric/global.rb
index ed51716..e455345 100644
--- a/lib/internal_metric/global.rb
+++ b/lib/internal_metric/global.rb
@@ -93,7 +93,7 @@ module DiscoursePrometheus::InternalMetric
             port: config[:replica_port]
           )
         else
-          return 0
+          return nil
         end
       end
 
diff --git a/spec/lib/internal_metric/global_spec.rb b/spec/lib/internal_metric/global_spec.rb
index aede1ac..29723ce 100644
--- a/spec/lib/internal_metric/global_spec.rb
+++ b/spec/lib/internal_metric/global_spec.rb
@@ -8,7 +8,7 @@ module DiscoursePrometheus::InternalMetric
 
       expect(metric.sidekiq_processes).not_to eq(nil)
       expect(metric.postgres_master_available).to eq(1)
-      expect(metric.postgres_replica_available).to eq(0)
+      expect(metric.postgres_replica_available).to eq(nil)
     end
 
     describe 'when a replica has been configured' do

GitHub

1 Like