Commit 1ddec596 authored by Kushal Pandya's avatar Kushal Pandya

Toon Claes: Expose Geo Node namespaces in status response

parent 297f1669
......@@ -7,6 +7,7 @@ class GeoNodeStatusEntity < Grape::Entity
expose :health do |node|
node.healthy? ? 'Healthy' : node.health
end
expose :health_status
expose :attachments_count
expose :attachments_synced_count
......@@ -37,4 +38,10 @@ class GeoNodeStatusEntity < Grape::Entity
expose :cursor_last_event_timestamp
expose :last_successful_status_check_timestamp
expose :namespaces, using: NamespaceEntity
def namespaces
object.geo_node.namespaces
end
end
class NamespaceEntity < Grape::Entity
expose :id, :name, :path, :kind, :full_path, :parent_id
end
......@@ -18,6 +18,7 @@ FactoryGirl.define do
last_event_timestamp Time.now.to_i
cursor_last_event_id 1
cursor_last_event_timestamp Time.now.to_i
last_successful_status_check_timestamp Time.now.beginning_of_day
end
trait :unhealthy do
......
......@@ -4,6 +4,7 @@
"geo_node_id",
"healthy",
"health",
"health_status",
"attachments_count",
"attachments_failed_count",
"attachments_synced_count",
......@@ -17,12 +18,14 @@
"last_event_id",
"last_event_timestamp",
"cursor_last_event_id",
"cursor_last_event_timestamp"
"cursor_last_event_timestamp",
"namespaces"
],
"properties" : {
"geo_node_id": { "type": "integer" },
"healthy": { "type": "boolean" },
"health": { "type": ["string", "null"] },
"health_status": { "type": "string" },
"attachments_count": { "type": "integer" },
"attachments_failed_count": { "type": "integer" },
"attachments_synced_count": { "type": "integer" },
......@@ -40,7 +43,8 @@
"last_event_timestamp": { "type": ["integer", "null"] },
"cursor_last_event_id": { "type": ["integer", "null"] },
"cursor_last_event_timestamp": { "type": ["integer", "null"] },
"last_successful_status_check_timestamp": { "type": ["integer", "null"] }
"last_successful_status_check_timestamp": { "type": ["integer", "null"] },
"namespaces": { "type": "array" }
},
"additionalProperties": false
}
require 'spec_helper'
describe GeoNodeStatusEntity, :postgresql do
let(:geo_node_status) do
GeoNodeStatus.new(
geo_node_id: 1,
health: '',
attachments_count: 329,
attachments_failed_count: 25,
attachments_synced_count: 141,
lfs_objects_count: 256,
lfs_objects_failed_count: 12,
lfs_objects_synced_count: 123,
repositories_count: 10,
repositories_synced_count: 5,
repositories_failed_count: 0,
last_successful_status_check_timestamp: Time.now.beginning_of_day
)
end
let(:entity) do
described_class.new(geo_node_status, request: double)
end
let(:error) do
'Could not connect to Geo database'
end
let(:geo_node_status) { build(:geo_node_status) }
let(:entity) { described_class.new(geo_node_status, request: double) }
let(:error) { 'Could not connect to Geo database' }
subject { entity.as_json }
......@@ -44,6 +23,7 @@ describe GeoNodeStatusEntity, :postgresql do
it { is_expected.to have_key(:repositories_synced_count)}
it { is_expected.to have_key(:repositories_synced_in_percentage) }
it { is_expected.to have_key(:last_successful_status_check_timestamp) }
it { is_expected.to have_key(:namespaces) }
describe '#healthy' do
context 'when node is healthy' do
......@@ -87,19 +67,47 @@ describe GeoNodeStatusEntity, :postgresql do
describe '#attachments_synced_in_percentage' do
it 'formats as percentage' do
geo_node_status.assign_attributes(attachments_count: 329,
attachments_failed_count: 25,
attachments_synced_count: 141)
expect(subject[:attachments_synced_in_percentage]).to eq '42.86%'
end
end
describe '#lfs_objects_synced_in_percentage' do
it 'formats as percentage' do
geo_node_status.assign_attributes(lfs_objects_count: 256,
lfs_objects_failed_count: 12,
lfs_objects_synced_count: 123)
expect(subject[:lfs_objects_synced_in_percentage]).to eq '48.05%'
end
end
describe '#repositories_synced_in_percentage' do
it 'formats as percentage' do
geo_node_status.assign_attributes(repositories_count: 10,
repositories_synced_count: 5,
repositories_failed_count: 0)
expect(subject[:repositories_synced_in_percentage]).to eq '50.00%'
end
end
describe '#namespaces' do
it 'returns empty array when full sync is active' do
expect(subject[:namespaces]).to be_empty
end
it 'returns array of namespace ids and paths for selective sync' do
namespace = create(:namespace)
geo_node_status.geo_node.namespaces << namespace
expect(subject[:namespaces]).not_to be_empty
expect(subject[:namespaces]).to be_an(Array)
expect(subject[:namespaces].first[:id]).to eq(namespace.id)
expect(subject[:namespaces].first[:path]).to eq(namespace.path)
end
end
end
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