Show backtrace when logging to kubernetes.log

Just the error message and error class alone makes it hard to determine
the full context of any errors, so we need to know where the error is
occuring as well.
This commit is contained in:
Thong Kuah 2019-03-04 16:28:28 +13:00
parent d0a0d3d3d5
commit 5eb2d6ea02
6 changed files with 31 additions and 6 deletions

View file

@ -19,7 +19,8 @@ module Clusters
app_id: app.id,
project_ids: app.cluster.project_ids,
group_ids: app.cluster.group_ids,
message: error.message
message: error.message,
backtrace: Gitlab::Profiler.clean_backtrace(error.backtrace)
}
logger.error(meta)

View file

@ -0,0 +1,5 @@
---
title: Show error backtrace when logging errors to kubernetes.log
merge_request: 25726
author:
type: other

View file

@ -36,6 +36,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
shared_examples 'error logging' do
context 'when installation raises a Kubeclient::HttpError' do
let(:cluster) { create(:cluster, :provided_by_user, :project) }
let(:logger) { service.send(:logger) }
before do
application.update!(cluster: cluster)
@ -51,7 +52,13 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
end
it 'should log error' do
expect(service.send(:logger)).to receive(:error)
expect(logger).to receive(:error)
service.execute
end
it 'logs error backtrace' do
expect(logger).to receive(:error).with(hash_including(backtrace: instance_of(Array)))
service.execute
end

View file

@ -51,6 +51,7 @@ describe Clusters::Applications::InstallService do
{
exception: 'Kubeclient::HttpError',
message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::InstallService',
app_id: application.id,
project_ids: application.cluster.project_ids,
@ -61,15 +62,16 @@ describe Clusters::Applications::InstallService do
expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with(
error,
extra: {
extra: hash_including(
exception: 'Kubeclient::HttpError',
message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::InstallService',
app_id: application.id,
project_ids: application.cluster.project_ids,
group_ids: [],
error_code: 500
}
)
)
service.execute
@ -99,6 +101,7 @@ describe Clusters::Applications::InstallService do
exception: 'StandardError',
error_code: nil,
message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::InstallService',
app_id: application.id,
project_ids: application.cluster.projects.pluck(:id),
@ -108,15 +111,16 @@ describe Clusters::Applications::InstallService do
expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with(
error,
extra: {
extra: hash_including(
exception: 'StandardError',
error_code: nil,
message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::InstallService',
app_id: application.id,
project_ids: application.cluster.projects.pluck(:id),
group_ids: []
}
)
)
service.execute

View file

@ -53,6 +53,7 @@ describe Clusters::Applications::PatchService do
{
exception: 'Kubeclient::HttpError',
message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::PatchService',
app_id: application.id,
project_ids: application.cluster.project_ids,
@ -66,6 +67,7 @@ describe Clusters::Applications::PatchService do
extra: {
exception: 'Kubeclient::HttpError',
message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::PatchService',
app_id: application.id,
project_ids: application.cluster.project_ids,
@ -101,6 +103,7 @@ describe Clusters::Applications::PatchService do
exception: 'StandardError',
error_code: nil,
message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::PatchService',
app_id: application.id,
project_ids: application.cluster.projects.pluck(:id),
@ -114,6 +117,7 @@ describe Clusters::Applications::PatchService do
exception: 'StandardError',
error_code: nil,
message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::PatchService',
app_id: application.id,
project_ids: application.cluster.projects.pluck(:id),

View file

@ -53,6 +53,7 @@ describe Clusters::Applications::UpgradeService do
{
exception: 'Kubeclient::HttpError',
message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::UpgradeService',
app_id: application.id,
project_ids: application.cluster.project_ids,
@ -66,6 +67,7 @@ describe Clusters::Applications::UpgradeService do
extra: {
exception: 'Kubeclient::HttpError',
message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::UpgradeService',
app_id: application.id,
project_ids: application.cluster.project_ids,
@ -101,6 +103,7 @@ describe Clusters::Applications::UpgradeService do
exception: 'StandardError',
error_code: nil,
message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::UpgradeService',
app_id: application.id,
project_ids: application.cluster.projects.pluck(:id),
@ -114,6 +117,7 @@ describe Clusters::Applications::UpgradeService do
exception: 'StandardError',
error_code: nil,
message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::UpgradeService',
app_id: application.id,
project_ids: application.cluster.projects.pluck(:id),