diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2018-12-11 15:38:33 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2018-12-11 15:38:33 +0300 |
commit | f03d58171ad62067cf54e44ce80306ef2e5af1fb (patch) | |
tree | 28a30de01247b06f95c13b5965690631ac7ae0f7 /app | |
parent | 352af3e57220e3f0178da8de2c3f03c42c419a9b (diff) | |
parent | 45ebdf82154aa27c4004c65e782e35eccb60dc02 (diff) |
Merge branch 'more-kubernetes-logs' into 'master'
Add more structured JSON logging to Kubernetes classes
See merge request gitlab-org/gitlab-ce!23693
Diffstat (limited to 'app')
-rw-r--r-- | app/services/clusters/gcp/fetch_operation_service.rb | 13 | ||||
-rw-r--r-- | app/services/clusters/gcp/finalize_creation_service.rb | 16 |
2 files changed, 29 insertions, 0 deletions
diff --git a/app/services/clusters/gcp/fetch_operation_service.rb b/app/services/clusters/gcp/fetch_operation_service.rb index 02c96a1e286..6c648b443a0 100644 --- a/app/services/clusters/gcp/fetch_operation_service.rb +++ b/app/services/clusters/gcp/fetch_operation_service.rb @@ -11,8 +11,21 @@ module Clusters yield(operation) if block_given? rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e + logger.error( + exception: e.class.name, + service: self.class.name, + provider_id: provider.id, + message: e.message + ) + provider.make_errored!("Failed to request to CloudPlatform; #{e.message}") end + + private + + def logger + @logger ||= Gitlab::Kubernetes::Logger.build + end end end end diff --git a/app/services/clusters/gcp/finalize_creation_service.rb b/app/services/clusters/gcp/finalize_creation_service.rb index e029323774c..301059f0326 100644 --- a/app/services/clusters/gcp/finalize_creation_service.rb +++ b/app/services/clusters/gcp/finalize_creation_service.rb @@ -16,10 +16,13 @@ module Clusters ClusterPlatformConfigureWorker.perform_async(cluster.id) rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e + log_service_error(e.class.name, provider.id, e.message) provider.make_errored!("Failed to request to CloudPlatform; #{e.message}") rescue Kubeclient::HttpError => e + log_service_error(e.class.name, provider.id, e.message) provider.make_errored!("Failed to run Kubeclient: #{e.message}") rescue ActiveRecord::RecordInvalid => e + log_service_error(e.class.name, provider.id, e.message) provider.make_errored!("Failed to configure Google Kubernetes Engine Cluster: #{e.message}") end @@ -105,6 +108,19 @@ module Clusters def cluster @cluster ||= provider.cluster end + + def logger + @logger ||= Gitlab::Kubernetes::Logger.build + end + + def log_service_error(exception, provider_id, message) + logger.error( + exception: exception.class.name, + service: self.class.name, + provider_id: provider_id, + message: message + ) + end end end end |