diff --git a/app/services/clusters/applications/base_helm_service.rb b/app/services/clusters/applications/base_helm_service.rb index c38b265626059a6a3f2da4d637418b36bbb3af3e..9619cba533c230ac49ccf92cb66756972fea5347 100644 --- a/app/services/clusters/applications/base_helm_service.rb +++ b/app/services/clusters/applications/base_helm_service.rb @@ -19,7 +19,8 @@ def log_error(error) 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) diff --git a/changelogs/unreleased/add_backtrace_to_kubernetes_log.yml b/changelogs/unreleased/add_backtrace_to_kubernetes_log.yml new file mode 100644 index 0000000000000000000000000000000000000000..26b8ac4b1ef95239896d0eb413c5114b5f836b4a --- /dev/null +++ b/changelogs/unreleased/add_backtrace_to_kubernetes_log.yml @@ -0,0 +1,5 @@ +--- +title: Show error backtrace when logging errors to kubernetes.log +merge_request: 25726 +author: +type: other diff --git a/spec/services/clusters/applications/check_installation_progress_service_spec.rb b/spec/services/clusters/applications/check_installation_progress_service_spec.rb index 19446ce1cf81efd1d799d3bb80e598bc1f3fbc44..6e37a30d142813be491bfecbeb1efd761226070e 100644 --- a/spec/services/clusters/applications/check_installation_progress_service_spec.rb +++ b/spec/services/clusters/applications/check_installation_progress_service_spec.rb @@ -36,6 +36,7 @@ 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 @@ 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 diff --git a/spec/services/clusters/applications/install_service_spec.rb b/spec/services/clusters/applications/install_service_spec.rb index 018d9822d3e11ad3f23d83459824e2829af1aee7..8affc135bc50d57f8accc1db3fe7fb3910e05e1d 100644 --- a/spec/services/clusters/applications/install_service_spec.rb +++ b/spec/services/clusters/applications/install_service_spec.rb @@ -51,6 +51,7 @@ { 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 @@ 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 @@ 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 @@ 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 diff --git a/spec/services/clusters/applications/patch_service_spec.rb b/spec/services/clusters/applications/patch_service_spec.rb index d4ee3243b84016706c8ad4cde6fc1073e2363861..51ca84dcd67b1a3baabbac4e137dab30c390d704 100644 --- a/spec/services/clusters/applications/patch_service_spec.rb +++ b/spec/services/clusters/applications/patch_service_spec.rb @@ -53,6 +53,7 @@ { 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 @@ 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 @@ 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 @@ 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), diff --git a/spec/services/clusters/applications/upgrade_service_spec.rb b/spec/services/clusters/applications/upgrade_service_spec.rb index 1822fc38dbd3b376fc00aec6088e0bb814805288..22e7555d2602ee7f4fde863ca6b0c5560443af09 100644 --- a/spec/services/clusters/applications/upgrade_service_spec.rb +++ b/spec/services/clusters/applications/upgrade_service_spec.rb @@ -53,6 +53,7 @@ { 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 @@ 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 @@ 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 @@ 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),