Commit ba2749f6 authored by Stan Hu's avatar Stan Hu

Only set status variables if Geo node is a secondary

parent c472e8f6
...@@ -15,7 +15,9 @@ class GeoNodeStatus ...@@ -15,7 +15,9 @@ class GeoNodeStatus
end end
def db_replication_lag def db_replication_lag
@db_replication_lag ||= Gitlab::Geo::HealthCheck.db_replication_lag return @db_replication_lag if defined?(@db_replication_lag)
@db_replication_lag = Gitlab::Geo::HealthCheck.db_replication_lag if Gitlab::Geo.secondary?
end end
def db_replication_lag=(value) def db_replication_lag=(value)
...@@ -39,7 +41,9 @@ class GeoNodeStatus ...@@ -39,7 +41,9 @@ class GeoNodeStatus
end end
def cursor_last_event_id def cursor_last_event_id
@cursor_last_event_id ||= cursor_last_processed&.event_id return @cursor_last_event_id if defined?(@cursor_last_event_id)
@cursor_last_event_id = cursor_last_processed&.event_id if Gitlab::Geo.secondary?
end end
def cursor_last_event_id=(value) def cursor_last_event_id=(value)
......
...@@ -104,6 +104,13 @@ describe GeoNodeStatus do ...@@ -104,6 +104,13 @@ describe GeoNodeStatus do
expect(subject.db_replication_lag).to eq(1000) expect(subject.db_replication_lag).to eq(1000)
end end
it "doesn't attempt to set replication lag if primary" do
expect(Gitlab::Geo::HealthCheck).not_to receive(:db_replication_lag)
expect(Gitlab::Geo).to receive(:secondary?).and_return(false)
expect(subject.db_replication_lag).to eq(nil)
end
end end
describe '#lfs_objects_synced_in_percentage' do describe '#lfs_objects_synced_in_percentage' do
...@@ -196,6 +203,14 @@ describe GeoNodeStatus do ...@@ -196,6 +203,14 @@ describe GeoNodeStatus do
expect(subject.cursor_last_event_id).to eq(event.event_id) expect(subject.cursor_last_event_id).to eq(event.event_id)
end end
it "doesn't attempt to retrieve cursor if primary" do
event = create(:geo_event_log_state)
expect(Gitlab::Geo).to receive(:secondary?).exactly(2).times.and_return(false)
expect(subject.cursor_last_event_date).to eq(nil)
expect(subject.cursor_last_event_id).to eq(nil)
end
end end
context 'when no values are available' do context 'when no values are available' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment