summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2019-03-04 16:28:28 +1300
committerThong Kuah <tkuah@gitlab.com>2019-04-04 17:40:52 +1300
commit5eb2d6ea02631608095847647e02cd899613b8e1 (patch)
treeb71c81f8e04d8d8318f2a5bcebaa03e96e6ad2e9
parentd0a0d3d3d5043d1497a5cd42e6c6bc073f6a5b58 (diff)
downloadgitlab-ce-5eb2d6ea02631608095847647e02cd899613b8e1.tar.gz
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.
-rw-r--r--app/services/clusters/applications/base_helm_service.rb3
-rw-r--r--changelogs/unreleased/add_backtrace_to_kubernetes_log.yml5
-rw-r--r--spec/services/clusters/applications/check_installation_progress_service_spec.rb9
-rw-r--r--spec/services/clusters/applications/install_service_spec.rb12
-rw-r--r--spec/services/clusters/applications/patch_service_spec.rb4
-rw-r--r--spec/services/clusters/applications/upgrade_service_spec.rb4
6 files changed, 31 insertions, 6 deletions
diff --git a/app/services/clusters/applications/base_helm_service.rb b/app/services/clusters/applications/base_helm_service.rb
index c38b2656260..9619cba533c 100644
--- a/app/services/clusters/applications/base_helm_service.rb
+++ b/app/services/clusters/applications/base_helm_service.rb
@@ -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)
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 00000000000..26b8ac4b1ef
--- /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 19446ce1cf8..6e37a30d142 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 @@ 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
diff --git a/spec/services/clusters/applications/install_service_spec.rb b/spec/services/clusters/applications/install_service_spec.rb
index 018d9822d3e..8affc135bc5 100644
--- a/spec/services/clusters/applications/install_service_spec.rb
+++ b/spec/services/clusters/applications/install_service_spec.rb
@@ -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
diff --git a/spec/services/clusters/applications/patch_service_spec.rb b/spec/services/clusters/applications/patch_service_spec.rb
index d4ee3243b84..51ca84dcd67 100644
--- a/spec/services/clusters/applications/patch_service_spec.rb
+++ b/spec/services/clusters/applications/patch_service_spec.rb
@@ -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),
diff --git a/spec/services/clusters/applications/upgrade_service_spec.rb b/spec/services/clusters/applications/upgrade_service_spec.rb
index 1822fc38dbd..22e7555d260 100644
--- a/spec/services/clusters/applications/upgrade_service_spec.rb
+++ b/spec/services/clusters/applications/upgrade_service_spec.rb
@@ -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),