Commit bf7ed3d4 authored by Stan Hu's avatar Stan Hu Committed by Douglas Barbosa Alexandre

Geo: Fix metrics updates when secondary nodes are cached

Due to https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8802,
`Gitlab::Geo.secondary_nodes` can return an Array instead of an
ActiveRecord relation if the value is retrieved from the cache.  Fix
this by using `each` instead of `find_each`, since loading a few GeoNode
records into memory shouldn't be a big deal.

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/9000
parent c0922480
......@@ -14,7 +14,7 @@ module Geo
update_prometheus_metrics(current_node, current_node_status) if prometheus_enabled?
if Gitlab::Geo.primary? && prometheus_enabled?
Gitlab::Geo.secondary_nodes.find_each { |node| update_prometheus_metrics(node, node.status) }
Gitlab::Geo.secondary_nodes.each { |node| update_prometheus_metrics(node, node.status) }
end
end
......
......@@ -124,6 +124,16 @@ describe Geo::MetricsUpdateService, :geo, :prometheus do
it 'updates the GeoNodeStatus entry' do
expect { subject.execute }.to change { GeoNodeStatus.count }.by(1)
end
it 'updates metrics when secondary nodes are cached', :request_store do
allow(subject).to receive(:update_prometheus_metrics).and_call_original
expect(subject).to receive(:update_prometheus_metrics).with(secondary, anything).twice
expect(subject).to receive(:update_prometheus_metrics).with(another_secondary, anything).twice
2.times do
subject.execute
end
end
end
context 'when node is a secondary' 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