Commit eb30b359 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '35552-improve-logging-of-sync-services-alt' into 'master'

Geo: Improve logging of sync services - include host

See merge request gitlab-org/gitlab!22203
parents 0b65c508 0a60b32b
---
title: 'Geo: Include host when logging'
merge_request: 22203
author:
type: other
...@@ -44,13 +44,14 @@ module Geo ...@@ -44,13 +44,14 @@ module Geo
object_type == :lfs object_type == :lfs
end end
def base_log_data(message) # This is called by LogHelpers to build json log with context info
#
# @see ::Gitlab::Geo::LogHelpers
def extra_log_data
{ {
class: self.class.name,
object_type: object_type, object_type: object_type,
object_db_id: object_db_id, object_db_id: object_db_id
message: message }.compact
}
end end
end end
end end
...@@ -16,15 +16,13 @@ module Geo ...@@ -16,15 +16,13 @@ module Geo
Geo::CacheInvalidationEvent.new(key: key) Geo::CacheInvalidationEvent.new(key: key)
end end
# This is called by ProjectLogHelpers to build json log with context info # This is called by LogHelpers to build json log with context info
# #
# @see ::Gitlab::Geo::ProjectLogHelpers # @see ::Gitlab::Geo::LogHelpers
def base_log_data(message) def extra_log_data
{ {
class: self.class.name,
cache_key: key.to_s, cache_key: key.to_s,
job_id: get_sidekiq_job_id, job_id: get_sidekiq_job_id
message: message
}.compact }.compact
end end
end end
......
...@@ -18,14 +18,12 @@ module Geo ...@@ -18,14 +18,12 @@ module Geo
) )
end end
# This is called by ProjectLogHelpers to build json log with context info # This is called by LogHelpers to build json log with context info
# #
# @see ::Gitlab::Geo::ProjectLogHelpers # @see ::Gitlab::Geo::LogHelpers
def base_log_data(message) def extra_log_data
{ {
class: self.class.name, container_repository_id: repository.try(:id)
container_repository_id: repository.try(:id),
message: message
}.compact }.compact
end end
end end
......
...@@ -66,14 +66,12 @@ module Geo ...@@ -66,14 +66,12 @@ module Geo
# This is called by LogHelpers to build json log with context info # This is called by LogHelpers to build json log with context info
# #
# @see ::Gitlab::Geo::LogHelpers # @see ::Gitlab::Geo::LogHelpers
def base_log_data(message) def extra_log_data
{ {
class: self.class.name,
project_id: project.id, project_id: project.id,
project_path: project.full_path, project_path: project.full_path,
project_old_path: old_full_path, project_old_path: old_full_path
message: message }.compact
}
end end
end end
end end
...@@ -25,16 +25,18 @@ module Geo ...@@ -25,16 +25,18 @@ module Geo
job_artifact.file.relative_path if job_artifact.file.present? job_artifact.file.relative_path if job_artifact.file.present?
end end
# This is called by ProjectLogHelpers to build json log with context info def project
job_artifact.project
end
# This is called by LogHelpers to build json log with context info
# #
# @see ::Gitlab::Geo::ProjectLogHelpers # @see ::Gitlab::Geo::LogHelpers
def base_log_data(message) def extra_log_data
{ {
class: self.class.name,
job_artifact_id: job_artifact.id, job_artifact_id: job_artifact.id,
file_path: job_artifact.file.path, file_path: job_artifact.file.path
message: message }.compact
}
end end
end end
end end
...@@ -26,16 +26,14 @@ module Geo ...@@ -26,16 +26,14 @@ module Geo
lfs_object.file.relative_path if lfs_object.file.present? lfs_object.file.relative_path if lfs_object.file.present?
end end
# This is called by ProjectLogHelpers to build json log with context info # This is called by LogHelpers to build json log with context info
# #
# @see ::Gitlab::Geo::ProjectLogHelpers # @see ::Gitlab::Geo::LogHelpers
def base_log_data(message) def extra_log_data
{ {
class: self.class.name,
lfs_object_id: lfs_object.id, lfs_object_id: lfs_object.id,
file_path: lfs_object.file.path, file_path: lfs_object.file.path
message: message }.compact
}
end end
end end
end end
...@@ -24,19 +24,17 @@ module Geo ...@@ -24,19 +24,17 @@ module Geo
) )
end end
# This is called by ProjectLogHelpers to build json log with context info # This is called by LogHelpers to build json log with context info
# #
# @see ::Gitlab::Geo::ProjectLogHelpers # @see ::Gitlab::Geo::LogHelpers
def base_log_data(message) def extra_log_data
{ {
class: self.class.name,
upload_id: upload.id, upload_id: upload.id,
file_path: upload.path, file_path: upload.path,
model_id: upload.model_id, model_id: upload.model_id,
model_type: upload.model_type, model_type: upload.model_type,
uploader: upload.uploader, uploader: upload.uploader
message: message }.compact
}
end end
end end
end end
...@@ -5,14 +5,14 @@ module Gitlab ...@@ -5,14 +5,14 @@ module Gitlab
module ContainerRepositoryLogHelpers module ContainerRepositoryLogHelpers
include LogHelpers include LogHelpers
def base_log_data(message) # This is called by LogHelpers to build json log with context info
#
# @see ::Gitlab::Geo::LogHelpers
def extra_log_data
{ {
class: self.class.name,
project_id: container_repository.project.id, project_id: container_repository.project.id,
project_path: container_repository.project.full_path, project_path: container_repository.project.full_path,
container_repository_name: container_repository.name, container_repository_name: container_repository.name
message: message,
job_id: get_sidekiq_job_id
}.compact }.compact
end end
end end
......
...@@ -52,6 +52,7 @@ module Gitlab ...@@ -52,6 +52,7 @@ module Gitlab
def base_log_data(message, params = {}) def base_log_data(message, params = {})
{ {
pid: PID, pid: PID,
host: Gitlab.config.gitlab.host,
class: caller_name, class: caller_name,
message: message message: message
}.merge(params) }.merge(params)
......
...@@ -23,9 +23,15 @@ module Gitlab ...@@ -23,9 +23,15 @@ module Gitlab
def base_log_data(message) def base_log_data(message)
{ {
class: self.class.name, class: self.class.name,
host: Gitlab.config.gitlab.host,
message: message, message: message,
job_id: get_sidekiq_job_id job_id: get_sidekiq_job_id
}.compact }.merge(extra_log_data).compact
end
# Intended to be overidden elsewhere
def extra_log_data
{}
end end
def geo_logger def geo_logger
...@@ -34,11 +40,9 @@ module Gitlab ...@@ -34,11 +40,9 @@ module Gitlab
def get_sidekiq_job_id def get_sidekiq_job_id
context_data = Thread.current[:sidekiq_context]&.first context_data = Thread.current[:sidekiq_context]&.first
return unless context_data return unless context_data
index = context_data.index('JID-') index = context_data.index('JID-')
return unless index return unless index
context_data[index + 4..-1] context_data[index + 4..-1]
......
...@@ -6,14 +6,11 @@ module Gitlab ...@@ -6,14 +6,11 @@ module Gitlab
include LogHelpers include LogHelpers
def base_log_data(message) def base_log_data(message)
{ super.merge({
class: self.class.name, project_id: project.try(:id),
project_id: project.id, project_path: project.try(:full_path),
project_path: project.full_path, storage_version: project.try(:storage_version)
storage_version: project.storage_version, }).compact
message: message,
job_id: get_sidekiq_job_id
}.compact
end end
end end
end end
......
...@@ -29,6 +29,7 @@ describe Gitlab::Geo::LogCursor::Lease, :clean_gitlab_redis_shared_state do ...@@ -29,6 +29,7 @@ describe Gitlab::Geo::LogCursor::Lease, :clean_gitlab_redis_shared_state do
expect(::Gitlab::Logger).to receive(:debug).with(pid: 111, expect(::Gitlab::Logger).to receive(:debug).with(pid: 111,
class: 'Gitlab::Geo::LogCursor::Lease', class: 'Gitlab::Geo::LogCursor::Lease',
host: "localhost",
message: 'Lease renewed.') message: 'Lease renewed.')
described_class.renew! described_class.renew!
......
...@@ -7,7 +7,7 @@ describe Gitlab::Geo::LogCursor::Logger, :geo do ...@@ -7,7 +7,7 @@ describe Gitlab::Geo::LogCursor::Logger, :geo do
subject(:logger) { described_class.new(LoggerSpec) } subject(:logger) { described_class.new(LoggerSpec) }
let(:data) { { pid: 111, class: 'LoggerSpec', message: 'Test' } } let(:data) { { pid: 111, class: 'LoggerSpec', host: 'localhost', message: 'Test' } }
before do before do
stub_const("#{described_class.name}::PID", 111) stub_const("#{described_class.name}::PID", 111)
...@@ -35,6 +35,7 @@ describe Gitlab::Geo::LogCursor::Logger, :geo do ...@@ -35,6 +35,7 @@ describe Gitlab::Geo::LogCursor::Logger, :geo do
it 'logs an info event' do it 'logs an info event' do
expect(::Gitlab::Logger).to receive(:info).with(pid: 111, expect(::Gitlab::Logger).to receive(:info).with(pid: 111,
class: "LoggerSpec", class: "LoggerSpec",
host: 'localhost',
message: 'Test', message: 'Test',
cursor_delay_s: 0.0) cursor_delay_s: 0.0)
......
...@@ -23,6 +23,7 @@ describe Gitlab::Geo::LogHelpers do ...@@ -23,6 +23,7 @@ describe Gitlab::Geo::LogHelpers do
context 'Sidekiq context' do context 'Sidekiq context' do
it 'does not log empty job_id when running outside of job' do it 'does not log empty job_id when running outside of job' do
expect(Gitlab::Geo::Logger).to receive(:error).with({ class: 'FakeLogHelpersConsumer', expect(Gitlab::Geo::Logger).to receive(:error).with({ class: 'FakeLogHelpersConsumer',
host: 'localhost',
message: 'Test message' }) message: 'Test message' })
FakeLogHelpersConsumer.new.execute FakeLogHelpersConsumer.new.execute
...@@ -30,6 +31,7 @@ describe Gitlab::Geo::LogHelpers do ...@@ -30,6 +31,7 @@ describe Gitlab::Geo::LogHelpers do
it 'logs sidekiq_context' do it 'logs sidekiq_context' do
expect(Gitlab::Geo::Logger).to receive(:error).with({ class: 'FakeLogHelpersConsumer', expect(Gitlab::Geo::Logger).to receive(:error).with({ class: 'FakeLogHelpersConsumer',
host: 'localhost',
message: 'Test message', message: 'Test message',
job_id: '5b9b108c7558fe3c32cc61a5' }) job_id: '5b9b108c7558fe3c32cc61a5' })
......
...@@ -30,6 +30,7 @@ describe Geo::CacheInvalidationEventStore do ...@@ -30,6 +30,7 @@ describe Geo::CacheInvalidationEventStore do
expected_message = { expected_message = {
class: described_class.name, class: described_class.name,
host: "localhost",
cache_key: '', cache_key: '',
message: 'Cache invalidation event could not be created', message: 'Cache invalidation event could not be created',
error: "Validation failed: Key can't be blank" error: "Validation failed: Key can't be blank"
......
...@@ -29,9 +29,10 @@ describe Geo::ContainerRepositoryUpdatedEventStore do ...@@ -29,9 +29,10 @@ describe Geo::ContainerRepositoryUpdatedEventStore do
subject = described_class.new(nil) subject = described_class.new(nil)
expected_message = { expected_message = {
class: described_class.name, class: described_class.name,
message: 'Container repository updated event could not be created', host: 'localhost',
error: "Validation failed: Container repository can't be blank" message: 'Container repository updated event could not be created',
error: "Validation failed: Container repository can't be blank"
} }
expect(Gitlab::Geo::Logger).to receive(:error).with(expected_message).and_call_original expect(Gitlab::Geo::Logger).to receive(:error).with(expected_message).and_call_original
......
...@@ -32,12 +32,16 @@ describe Geo::JobArtifactDeletedEventStore do ...@@ -32,12 +32,16 @@ describe Geo::JobArtifactDeletedEventStore do
it 'logs an error message when event creation fail' do it 'logs an error message when event creation fail' do
invalid_job_artifact = create(:ci_job_artifact) invalid_job_artifact = create(:ci_job_artifact)
project = invalid_job_artifact.project
subject = described_class.new(invalid_job_artifact) subject = described_class.new(invalid_job_artifact)
expected_message = { expected_message = {
class: "Geo::JobArtifactDeletedEventStore", class: "Geo::JobArtifactDeletedEventStore",
host: "localhost",
job_artifact_id: invalid_job_artifact.id, job_artifact_id: invalid_job_artifact.id,
file_path: nil, project_id: project.id,
project_path: project.full_path,
storage_version: project.storage_version,
message: "Job artifact deleted event could not be created", message: "Job artifact deleted event could not be created",
error: "Validation failed: File path can't be blank" error: "Validation failed: File path can't be blank"
} }
......
...@@ -37,8 +37,8 @@ describe Geo::LfsObjectDeletedEventStore do ...@@ -37,8 +37,8 @@ describe Geo::LfsObjectDeletedEventStore do
expected_message = { expected_message = {
class: "Geo::LfsObjectDeletedEventStore", class: "Geo::LfsObjectDeletedEventStore",
host: "localhost",
lfs_object_id: invalid_lfs_object.id, lfs_object_id: invalid_lfs_object.id,
file_path: nil,
message: "Lfs object deleted event could not be created", message: "Lfs object deleted event could not be created",
error: "Validation failed: File path can't be blank" error: "Validation failed: File path can't be blank"
} }
......
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