Commit f56731fc authored by Toon Claes's avatar Toon Claes

Make Geo::PruneEventLogWorker generate some logging

parent 7d125f1a
...@@ -16,6 +16,7 @@ module Geo ...@@ -16,6 +16,7 @@ module Geo
try_obtain_lease do try_obtain_lease do
if Gitlab::Geo.secondary_nodes.empty? if Gitlab::Geo.secondary_nodes.empty?
log_info('No secondary nodes, delete all Geo Event Log entries')
Geo::EventLog.delete_all Geo::EventLog.delete_all
return return
end end
...@@ -24,9 +25,12 @@ module Geo ...@@ -24,9 +25,12 @@ module Geo
Geo::NodeStatusService.new.call(node).cursor_last_event_id Geo::NodeStatusService.new.call(node).cursor_last_event_id
end end
# Abort when any of the nodes could not be contacted if cursor_last_event_ids.include?(nil)
return if cursor_last_event_ids.include?(nil) log_info('Could not get status of all nodes, not deleting any entries from Geo Event Log', unhealthy_node_count: cursor_last_event_ids.count(nil))
return
end
log_info('Delete Geo Event Log entries up to id', geo_event_log_id: cursor_last_event_ids.min)
Geo::EventLog.delete_all(['id < ?', cursor_last_event_ids.min]) Geo::EventLog.delete_all(['id < ?', cursor_last_event_ids.min])
end end
end end
......
...@@ -43,6 +43,7 @@ describe Geo::PruneEventLogWorker, :geo do ...@@ -43,6 +43,7 @@ describe Geo::PruneEventLogWorker, :geo do
end end
it 'deletes everything from the Geo event log' do it 'deletes everything from the Geo event log' do
expect(worker).to receive(:log_info).with('No secondary nodes, delete all Geo Event Log entries')
expect(Geo::EventLog).to receive(:delete_all) expect(Geo::EventLog).to receive(:delete_all)
worker.perform worker.perform
...@@ -62,6 +63,7 @@ describe Geo::PruneEventLogWorker, :geo do ...@@ -62,6 +63,7 @@ describe Geo::PruneEventLogWorker, :geo do
it 'contacts all secondary nodes for their status' do it 'contacts all secondary nodes for their status' do
expect(node_status_service).to receive(:call).twice { healthy_status } expect(node_status_service).to receive(:call).twice { healthy_status }
expect(worker).to receive(:log_info).with('Delete Geo Event Log entries up to id', anything)
expect(Geo::EventLog).to receive(:delete_all) expect(Geo::EventLog).to receive(:delete_all)
worker.perform worker.perform
...@@ -69,6 +71,7 @@ describe Geo::PruneEventLogWorker, :geo do ...@@ -69,6 +71,7 @@ describe Geo::PruneEventLogWorker, :geo do
it 'aborts when there are unhealthy nodes' do it 'aborts when there are unhealthy nodes' do
expect(node_status_service).to receive(:call).twice.and_return(healthy_status, unhealthy_status) expect(node_status_service).to receive(:call).twice.and_return(healthy_status, unhealthy_status)
expect(worker).to receive(:log_info).with('Could not get status of all nodes, not deleting any entries from Geo Event Log', unhealthy_node_count: 1)
expect(Geo::EventLog).not_to receive(:delete_all) expect(Geo::EventLog).not_to receive(:delete_all)
worker.perform worker.perform
...@@ -79,6 +82,7 @@ describe Geo::PruneEventLogWorker, :geo do ...@@ -79,6 +82,7 @@ describe Geo::PruneEventLogWorker, :geo do
build(:geo_node_status, :healthy, cursor_last_event_id: 3), build(:geo_node_status, :healthy, cursor_last_event_id: 3),
build(:geo_node_status, :healthy, cursor_last_event_id: 10) build(:geo_node_status, :healthy, cursor_last_event_id: 10)
) )
expect(worker).to receive(:log_info).with('Delete Geo Event Log entries up to id', geo_event_log_id: 3)
expect(Geo::EventLog).to receive(:delete_all).with(['id < ?', 3]) expect(Geo::EventLog).to receive(:delete_all).with(['id < ?', 3])
worker.perform worker.perform
......
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