Commit 5eb2d6ea authored by Thong Kuah's avatar Thong Kuah

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.
parent d0a0d3d3
...@@ -19,7 +19,8 @@ module Clusters ...@@ -19,7 +19,8 @@ module Clusters
app_id: app.id, app_id: app.id,
project_ids: app.cluster.project_ids, project_ids: app.cluster.project_ids,
group_ids: app.cluster.group_ids, group_ids: app.cluster.group_ids,
message: error.message message: error.message,
backtrace: Gitlab::Profiler.clean_backtrace(error.backtrace)
} }
logger.error(meta) logger.error(meta)
......
---
title: Show error backtrace when logging errors to kubernetes.log
merge_request: 25726
author:
type: other
...@@ -36,6 +36,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do ...@@ -36,6 +36,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
shared_examples 'error logging' do shared_examples 'error logging' do
context 'when installation raises a Kubeclient::HttpError' do context 'when installation raises a Kubeclient::HttpError' do
let(:cluster) { create(:cluster, :provided_by_user, :project) } let(:cluster) { create(:cluster, :provided_by_user, :project) }
let(:logger) { service.send(:logger) }
before do before do
application.update!(cluster: cluster) application.update!(cluster: cluster)
...@@ -51,7 +52,13 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do ...@@ -51,7 +52,13 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
end end
it 'should log error' do 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 service.execute
end end
......
...@@ -51,6 +51,7 @@ describe Clusters::Applications::InstallService do ...@@ -51,6 +51,7 @@ describe Clusters::Applications::InstallService do
{ {
exception: 'Kubeclient::HttpError', exception: 'Kubeclient::HttpError',
message: 'system failure', message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::InstallService', service: 'Clusters::Applications::InstallService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.project_ids, project_ids: application.cluster.project_ids,
...@@ -61,15 +62,16 @@ describe Clusters::Applications::InstallService do ...@@ -61,15 +62,16 @@ describe Clusters::Applications::InstallService do
expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with( expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with(
error, error,
extra: { extra: hash_including(
exception: 'Kubeclient::HttpError', exception: 'Kubeclient::HttpError',
message: 'system failure', message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::InstallService', service: 'Clusters::Applications::InstallService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.project_ids, project_ids: application.cluster.project_ids,
group_ids: [], group_ids: [],
error_code: 500 error_code: 500
} )
) )
service.execute service.execute
...@@ -99,6 +101,7 @@ describe Clusters::Applications::InstallService do ...@@ -99,6 +101,7 @@ describe Clusters::Applications::InstallService do
exception: 'StandardError', exception: 'StandardError',
error_code: nil, error_code: nil,
message: 'something bad happened', message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::InstallService', service: 'Clusters::Applications::InstallService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.projects.pluck(:id), project_ids: application.cluster.projects.pluck(:id),
...@@ -108,15 +111,16 @@ describe Clusters::Applications::InstallService do ...@@ -108,15 +111,16 @@ describe Clusters::Applications::InstallService do
expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with( expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with(
error, error,
extra: { extra: hash_including(
exception: 'StandardError', exception: 'StandardError',
error_code: nil, error_code: nil,
message: 'something bad happened', message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::InstallService', service: 'Clusters::Applications::InstallService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.projects.pluck(:id), project_ids: application.cluster.projects.pluck(:id),
group_ids: [] group_ids: []
} )
) )
service.execute service.execute
......
...@@ -53,6 +53,7 @@ describe Clusters::Applications::PatchService do ...@@ -53,6 +53,7 @@ describe Clusters::Applications::PatchService do
{ {
exception: 'Kubeclient::HttpError', exception: 'Kubeclient::HttpError',
message: 'system failure', message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::PatchService', service: 'Clusters::Applications::PatchService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.project_ids, project_ids: application.cluster.project_ids,
...@@ -66,6 +67,7 @@ describe Clusters::Applications::PatchService do ...@@ -66,6 +67,7 @@ describe Clusters::Applications::PatchService do
extra: { extra: {
exception: 'Kubeclient::HttpError', exception: 'Kubeclient::HttpError',
message: 'system failure', message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::PatchService', service: 'Clusters::Applications::PatchService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.project_ids, project_ids: application.cluster.project_ids,
...@@ -101,6 +103,7 @@ describe Clusters::Applications::PatchService do ...@@ -101,6 +103,7 @@ describe Clusters::Applications::PatchService do
exception: 'StandardError', exception: 'StandardError',
error_code: nil, error_code: nil,
message: 'something bad happened', message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::PatchService', service: 'Clusters::Applications::PatchService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.projects.pluck(:id), project_ids: application.cluster.projects.pluck(:id),
...@@ -114,6 +117,7 @@ describe Clusters::Applications::PatchService do ...@@ -114,6 +117,7 @@ describe Clusters::Applications::PatchService do
exception: 'StandardError', exception: 'StandardError',
error_code: nil, error_code: nil,
message: 'something bad happened', message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::PatchService', service: 'Clusters::Applications::PatchService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.projects.pluck(:id), project_ids: application.cluster.projects.pluck(:id),
......
...@@ -53,6 +53,7 @@ describe Clusters::Applications::UpgradeService do ...@@ -53,6 +53,7 @@ describe Clusters::Applications::UpgradeService do
{ {
exception: 'Kubeclient::HttpError', exception: 'Kubeclient::HttpError',
message: 'system failure', message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::UpgradeService', service: 'Clusters::Applications::UpgradeService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.project_ids, project_ids: application.cluster.project_ids,
...@@ -66,6 +67,7 @@ describe Clusters::Applications::UpgradeService do ...@@ -66,6 +67,7 @@ describe Clusters::Applications::UpgradeService do
extra: { extra: {
exception: 'Kubeclient::HttpError', exception: 'Kubeclient::HttpError',
message: 'system failure', message: 'system failure',
backtrace: instance_of(Array),
service: 'Clusters::Applications::UpgradeService', service: 'Clusters::Applications::UpgradeService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.project_ids, project_ids: application.cluster.project_ids,
...@@ -101,6 +103,7 @@ describe Clusters::Applications::UpgradeService do ...@@ -101,6 +103,7 @@ describe Clusters::Applications::UpgradeService do
exception: 'StandardError', exception: 'StandardError',
error_code: nil, error_code: nil,
message: 'something bad happened', message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::UpgradeService', service: 'Clusters::Applications::UpgradeService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.projects.pluck(:id), project_ids: application.cluster.projects.pluck(:id),
...@@ -114,6 +117,7 @@ describe Clusters::Applications::UpgradeService do ...@@ -114,6 +117,7 @@ describe Clusters::Applications::UpgradeService do
exception: 'StandardError', exception: 'StandardError',
error_code: nil, error_code: nil,
message: 'something bad happened', message: 'something bad happened',
backtrace: instance_of(Array),
service: 'Clusters::Applications::UpgradeService', service: 'Clusters::Applications::UpgradeService',
app_id: application.id, app_id: application.id,
project_ids: application.cluster.projects.pluck(:id), project_ids: application.cluster.projects.pluck(:id),
......
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