Commit fbb90c10 authored by Stan Hu's avatar Stan Hu

Geo: Log to geo.log when the Log Cursor skips an event

This commit adds messages such as the following:

{
   "severity":"INFO",
   "time":"2018-07-11T20:43:04.505Z",
   "pid":53975,
   "class":"Gitlab::Geo::LogCursor::Daemon",
   "message":"Skipped event",
   "log_event_id":1,
   "event_id":1,
   "event_type":"Geo::RepositoryUpdatedEvent",
   "project_id":1,
   "cursor_delay_s":0.077
}

This will help diagnose whether the cursor is actually skipping events.
parent a997bc26
---
title: 'Geo: Log to geo.log when the Log Cursor skips an event'
merge_request:
author:
type: other
...@@ -45,7 +45,10 @@ module Gitlab ...@@ -45,7 +45,10 @@ module Gitlab
def handle_events(batch) def handle_events(batch)
batch.each do |event_log| batch.each do |event_log|
next unless can_replay?(event_log) unless can_replay?(event_log)
logger.event_info(event_log.created_at, 'Skipped event', event_data(event_log))
next
end
begin begin
event = event_log.event event = event_log.event
...@@ -105,6 +108,15 @@ module Gitlab ...@@ -105,6 +108,15 @@ module Gitlab
def log_level def log_level
options[:debug] ? :debug : Rails.logger.level options[:debug] ? :debug : Rails.logger.level
end end
def event_data(event_log)
{
event_log_id: event_log.id,
event_id: event_log.event.id,
event_type: event_log.event.class.name,
project_id: event_log.project_id
}
end
end end
end end
end end
......
...@@ -115,6 +115,22 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared ...@@ -115,6 +115,22 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
daemon.run_once! daemon.run_once!
end end
it 'logs a message for skipped events' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group_2])
expect(Gitlab::Geo::Logger).to receive(:info).with(hash_including(
:pid,
:cursor_delay_s,
message: 'Skipped event',
class: 'Gitlab::Geo::LogCursor::Daemon',
event_log_id: event_log.id,
event_id: repository_updated_event.id,
event_type: 'Geo::RepositoryUpdatedEvent',
project_id: project.id))
daemon.run_once!
end
it 'does not replay events for projects that do not belong to selected shards to replicate' do it 'does not replay events for projects that do not belong to selected shards to replicate' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken']) secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
......
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