Commit 12c0be78 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'ag-add-event-info-logs' into 'master'

Log trigger info for log cursor events

See merge request gitlab-org/gitlab!31926
parents c1cb3fe1 04ae2ca5
......@@ -36,6 +36,14 @@ module Gitlab
def enqueue_job_if_shard_healthy(event)
yield if healthy_shard_for?(event)
end
def log_event(message, params = {})
logger.event_info(
created_at,
message,
params.merge(event_id: event.id)
)
end
end
end
end
......
......@@ -19,8 +19,7 @@ module Gitlab
end
def log_cache_invalidation_event(expired)
logger.event_info(
created_at,
log_event(
'Cache invalidation',
cache_key: event.key,
cache_expired: expired,
......
......@@ -30,12 +30,12 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord
def log_event(job_id)
logger.event_info(
created_at,
super(
'Docker Repository update',
container_repository_id: registry.container_repository_id,
skippable: skippable?,
project: registry.container_repository.project_id)
project: registry.container_repository.project_id,
job_id: job_id)
end
end
end
......
......@@ -30,8 +30,7 @@ module Gitlab
end
def log_event(job_id)
logger.event_info(
created_at,
super(
'Design repository update',
project_id: event.project_id,
scheduled_at: Time.now,
......
......@@ -24,14 +24,12 @@ module Gitlab
end
def log_event(job_id)
logger.event_info(
created_at,
super(
'Migrating attachments to hashed storage',
project_id: event.project_id,
old_attachments_path: event.old_attachments_path,
new_attachments_path: event.new_attachments_path,
job_id: job_id
)
job_id: job_id)
end
end
end
......
......@@ -27,8 +27,7 @@ module Gitlab
end
def log_event(job_id)
logger.event_info(
created_at,
super(
'Migrating project to hashed storage',
project_id: event.project_id,
old_storage_version: event.old_storage_version,
......
......@@ -20,8 +20,7 @@ module Gitlab
end
def log_event(job_id)
logger.event_info(
created_at,
super(
'Delete job artifact scheduled',
file_id: event.job_artifact_id,
file_path: event.file_path,
......
......@@ -20,8 +20,7 @@ module Gitlab
end
def log_event(job_id)
logger.event_info(
created_at,
super(
'Delete LFS object scheduled',
oid: event.oid,
file_id: event.lfs_object_id,
......
......@@ -19,9 +19,14 @@ module Gitlab
def log_event(job_id)
if job_id
logger.info('Scheduled repositories clean up for Geo node', geo_node_id: event.geo_node_id, job_id: job_id)
super(
'Scheduled repositories clean up for Geo node',
geo_node_id: event.geo_node_id,
job_id: job_id)
else
logger.error('Could not schedule repositories clean up for Geo node', geo_node_id: event.geo_node_id)
logger.error(
'Could not schedule repositories clean up for Geo node',
geo_node_id: event.geo_node_id)
end
end
end
......
......@@ -8,25 +8,28 @@ module Gitlab
include BaseEvent
def process
log_event
registry.repository_created!(event)
job_id = nil
enqueue_job_if_shard_healthy(event) do
::Geo::ProjectSyncWorker.perform_async(event.project_id, sync_repository: true, sync_wiki: true)
job_id = ::Geo::ProjectSyncWorker.perform_async(event.project_id, sync_repository: true, sync_wiki: true)
end
log_event(job_id)
end
private
def log_event
logger.event_info(
created_at,
def log_event(job_id)
super(
'Repository created',
project_id: event.project_id,
repo_path: event.repo_path,
wiki_path: event.wiki_path,
resync_repository: registry.resync_repository,
resync_wiki: registry.resync_wiki)
resync_wiki: registry.resync_wiki,
job_id: job_id)
end
end
end
......
......@@ -30,15 +30,13 @@ module Gitlab
end
def log_event(job_id)
logger.event_info(
created_at,
super(
'Deleted project',
project_id: event.project_id,
repository_storage_name: event.repository_storage_name,
disk_path: event.deleted_path,
skippable: skippable?,
job_id: job_id
)
job_id: job_id)
end
end
end
......
......@@ -26,8 +26,7 @@ module Gitlab
end
def log_event(job_id)
logger.event_info(
created_at,
super(
'Renaming project',
project_id: event.project_id,
old_path: event.old_path_with_namespace,
......
......@@ -24,8 +24,7 @@ module Gitlab
private
def log_event(job_id)
logger.event_info(
created_at,
super(
'Repository update',
project_id: event.project_id,
source: event.source,
......
......@@ -9,18 +9,11 @@ module Gitlab
def process
registry.reset_checksum! unless skippable?
log_event
end
private
def log_event
logger.event_info(
created_at,
log_event(
'Reset checksum',
project_id: event.project_id,
skippable: skippable?
)
skippable: skippable?)
end
end
end
......
......@@ -13,8 +13,7 @@ module Gitlab
end
def log_event(job_id)
logger.event_info(
created_at,
super(
'Delete upload file scheduled',
upload_id: event.upload_id,
upload_type: event.upload_type,
......
......@@ -33,7 +33,7 @@ describe Gitlab::Geo::LogCursor::Events::CacheInvalidationEvent, :clean_gitlab_r
expect(::Gitlab::Logger)
.to receive(:info)
.with(hash_including(data))
.with(hash_including(:event_id, data))
subject.process
end
......
......@@ -26,5 +26,7 @@ describe Gitlab::Geo::LogCursor::Events::ContainerRepositoryUpdatedEvent, :clean
subject.process
end
it_behaves_like 'logs event source info'
end
end
......@@ -63,5 +63,7 @@ describe Gitlab::Geo::LogCursor::Events::DesignRepositoryUpdatedEvent, :clean_gi
subject.process
end
end
it_behaves_like 'logs event source info'
end
end
......@@ -28,5 +28,7 @@ describe Gitlab::Geo::LogCursor::Events::HashedStorageAttachmentsEvent, :clean_g
subject.process
end
it_behaves_like 'logs event source info'
end
end
......@@ -40,5 +40,7 @@ describe Gitlab::Geo::LogCursor::Events::HashedStorageMigratedEvent, :clean_gitl
subject.process
end
it_behaves_like 'logs event source info'
end
end
......@@ -72,5 +72,7 @@ describe Gitlab::Geo::LogCursor::Events::JobArtifactDeletedEvent, :clean_gitlab_
expect { subject.process }.not_to change { File.exist?(job_artifact.file.path) }.from(true)
end
end
it_behaves_like 'logs event source info'
end
end
......@@ -31,5 +31,7 @@ describe Gitlab::Geo::LogCursor::Events::LfsObjectDeletedEvent, :clean_gitlab_re
subject.process
end
it_behaves_like 'logs event source info'
end
end
......@@ -35,5 +35,7 @@ describe Gitlab::Geo::LogCursor::Events::RepositoriesChangedEvent, :clean_gitlab
subject.process
end
it_behaves_like 'logs event source info'
end
end
......@@ -52,6 +52,8 @@ describe Gitlab::Geo::LogCursor::Events::RepositoryCreatedEvent, :clean_gitlab_r
subject.process
end
it_behaves_like 'logs event source info'
end
context 'when the associated shard is not healthy' do
......
......@@ -51,5 +51,7 @@ describe Gitlab::Geo::LogCursor::Events::RepositoryDeletedEvent, :clean_gitlab_r
end
end
end
it_behaves_like 'logs event source info'
end
end
......@@ -39,5 +39,7 @@ describe Gitlab::Geo::LogCursor::Events::RepositoryRenamedEvent, :clean_gitlab_r
subject.process
end
it_behaves_like 'logs event source info'
end
end
......@@ -142,6 +142,8 @@ describe Gitlab::Geo::LogCursor::Events::RepositoryUpdatedEvent, :clean_gitlab_r
end
end
end
it_behaves_like 'logs event source info'
end
context 'when associated shard is unhealthy' do
......
......@@ -31,6 +31,8 @@ describe Gitlab::Geo::LogCursor::Events::UploadDeletedEvent, :clean_gitlab_redis
expect { subject.process }.to change(Geo::UploadRegistry, :count).by(-1)
end
it_behaves_like 'logs event source info'
end
end
end
# frozen_string_literal: true
RSpec.shared_examples 'logs event source info' do
it 'logs `job_id` and `event_id' do
expect_any_instance_of(Gitlab::Geo::LogCursor::Logger).to receive(:info)
.with(
anything,
hash_including(:job_id, :event_id))
.at_least(:once)
.and_call_original
subject.process
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