Commit ab2403e3 authored by Ash McKenzie's avatar Ash McKenzie Committed by Douglas Barbosa Alexandre

Add support for #extra_log_data()

extra_log_data() will be merged into
base_log_data().
parent 496ffa03
......@@ -44,13 +44,14 @@ module Geo
object_type == :lfs
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_db_id: object_db_id,
message: message
}
object_db_id: object_db_id
}.compact
end
end
end
......@@ -16,15 +16,13 @@ module Geo
Geo::CacheInvalidationEvent.new(key: key)
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
def base_log_data(message)
# @see ::Gitlab::Geo::LogHelpers
def extra_log_data
{
class: self.class.name,
cache_key: key.to_s,
job_id: get_sidekiq_job_id,
message: message
job_id: get_sidekiq_job_id
}.compact
end
end
......
......@@ -18,14 +18,12 @@ module Geo
)
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
def base_log_data(message)
# @see ::Gitlab::Geo::LogHelpers
def extra_log_data
{
class: self.class.name,
container_repository_id: repository.try(:id),
message: message
container_repository_id: repository.try(:id)
}.compact
end
end
......
......@@ -66,14 +66,12 @@ module Geo
# This is called by LogHelpers to build json log with context info
#
# @see ::Gitlab::Geo::LogHelpers
def base_log_data(message)
def extra_log_data
{
class: self.class.name,
project_id: project.id,
project_path: project.full_path,
project_old_path: old_full_path,
message: message
}
project_old_path: old_full_path
}.compact
end
end
end
......@@ -25,16 +25,18 @@ module Geo
job_artifact.file.relative_path if job_artifact.file.present?
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
def base_log_data(message)
# @see ::Gitlab::Geo::LogHelpers
def extra_log_data
{
class: self.class.name,
job_artifact_id: job_artifact.id,
file_path: job_artifact.file.path,
message: message
}
file_path: job_artifact.file.path
}.compact
end
end
end
......@@ -26,16 +26,14 @@ module Geo
lfs_object.file.relative_path if lfs_object.file.present?
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
def base_log_data(message)
# @see ::Gitlab::Geo::LogHelpers
def extra_log_data
{
class: self.class.name,
lfs_object_id: lfs_object.id,
file_path: lfs_object.file.path,
message: message
}
file_path: lfs_object.file.path
}.compact
end
end
end
......@@ -24,19 +24,17 @@ module Geo
)
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
def base_log_data(message)
# @see ::Gitlab::Geo::LogHelpers
def extra_log_data
{
class: self.class.name,
upload_id: upload.id,
file_path: upload.path,
model_id: upload.model_id,
model_type: upload.model_type,
uploader: upload.uploader,
message: message
}
uploader: upload.uploader
}.compact
end
end
end
......@@ -5,14 +5,14 @@ module Gitlab
module ContainerRepositoryLogHelpers
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_path: container_repository.project.full_path,
container_repository_name: container_repository.name,
message: message,
job_id: get_sidekiq_job_id
container_repository_name: container_repository.name
}.compact
end
end
......
......@@ -25,7 +25,12 @@ module Gitlab
class: self.class.name,
message: message,
job_id: get_sidekiq_job_id
}.compact
}.merge(extra_log_data).compact
end
# Intended to be overidden elsewhere
def extra_log_data
{}
end
def geo_logger
......
......@@ -6,14 +6,11 @@ module Gitlab
include LogHelpers
def base_log_data(message)
{
class: self.class.name,
project_id: project.id,
project_path: project.full_path,
storage_version: project.storage_version,
message: message,
job_id: get_sidekiq_job_id
}.compact
super.merge({
project_id: project.try(:id),
project_path: project.try(:full_path),
storage_version: project.try(:storage_version)
}).compact
end
end
end
......
......@@ -32,12 +32,16 @@ describe Geo::JobArtifactDeletedEventStore do
it 'logs an error message when event creation fail' do
invalid_job_artifact = create(:ci_job_artifact)
project = invalid_job_artifact.project
subject = described_class.new(invalid_job_artifact)
expected_message = {
class: "Geo::JobArtifactDeletedEventStore",
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",
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