Commit 0518b427 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'status-on-secondary' into 'master'

Geo: Use database-cached status if redis-cached status is unavailable

See merge request gitlab-org/gitlab-ee!6854
parents 12a04bcb a3f90e6f
---
title: 'Geo: Use database-cached status if redis-cached status is unavailable'
merge_request: 6854
author:
type: fixed
...@@ -77,11 +77,8 @@ module API ...@@ -77,11 +77,8 @@ module API
def geo_node_status def geo_node_status
strong_memoize(:geo_node_status) do strong_memoize(:geo_node_status) do
if geo_node.current? status = GeoNodeStatus.fast_current_node_status if geo_node.current?
GeoNodeStatus.fast_current_node_status status || geo_node.status
else
geo_node.status
end
end end
end end
end end
......
...@@ -89,7 +89,7 @@ describe API::GeoNodes, :geo, :prometheus, api: true do ...@@ -89,7 +89,7 @@ describe API::GeoNodes, :geo, :prometheus, api: true do
expect(links['node']).to end_with("/api/v4/geo_nodes/#{secondary.id}") expect(links['node']).to end_with("/api/v4/geo_nodes/#{secondary.id}")
end end
it 'fetches the current node status' do it 'fetches the current node status from redis' do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
expect(GeoNodeStatus).to receive(:fast_current_node_status).and_return(secondary_status) expect(GeoNodeStatus).to receive(:fast_current_node_status).and_return(secondary_status)
...@@ -101,9 +101,23 @@ describe API::GeoNodes, :geo, :prometheus, api: true do ...@@ -101,9 +101,23 @@ describe API::GeoNodes, :geo, :prometheus, api: true do
expect(response).to match_response_schema('public_api/v4/geo_node_status', dir: 'ee') expect(response).to match_response_schema('public_api/v4/geo_node_status', dir: 'ee')
end end
it 'shows 404 response if current node status does not exist yet' do it 'shows the database-held response if current node status exists in the database, but not redis' do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
expect(GeoNodeStatus).to receive(:fast_current_node_status).and_return(nil)
expect(GeoNode).to receive(:find).and_return(secondary)
get api("/geo_nodes/#{secondary.id}/status", admin)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/geo_node_status', dir: 'ee')
end
it 'shows 404 response if current node status does not exist in database or redis yet' do
stub_current_geo_node(secondary)
secondary_status.destroy!
expect(GeoNodeStatus).to receive(:fast_current_node_status).and_return(nil)
expect(GeoNode).to receive(:find).and_return(secondary) expect(GeoNode).to receive(:find).and_return(secondary)
get api("/geo_nodes/#{secondary.id}/status", admin) get api("/geo_nodes/#{secondary.id}/status", admin)
......
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