Commit f03d5817 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'more-kubernetes-logs' into 'master'

Add more structured JSON logging to Kubernetes classes

See merge request gitlab-org/gitlab-ce!23693
parents 352af3e5 45ebdf82
...@@ -11,8 +11,21 @@ module Clusters ...@@ -11,8 +11,21 @@ module Clusters
yield(operation) if block_given? yield(operation) if block_given?
rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e 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}") provider.make_errored!("Failed to request to CloudPlatform; #{e.message}")
end end
private
def logger
@logger ||= Gitlab::Kubernetes::Logger.build
end
end end
end end
end end
...@@ -16,10 +16,13 @@ module Clusters ...@@ -16,10 +16,13 @@ module Clusters
ClusterPlatformConfigureWorker.perform_async(cluster.id) ClusterPlatformConfigureWorker.perform_async(cluster.id)
rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e 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}") provider.make_errored!("Failed to request to CloudPlatform; #{e.message}")
rescue Kubeclient::HttpError => e rescue Kubeclient::HttpError => e
log_service_error(e.class.name, provider.id, e.message)
provider.make_errored!("Failed to run Kubeclient: #{e.message}") provider.make_errored!("Failed to run Kubeclient: #{e.message}")
rescue ActiveRecord::RecordInvalid => e 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}") provider.make_errored!("Failed to configure Google Kubernetes Engine Cluster: #{e.message}")
end end
...@@ -105,6 +108,19 @@ module Clusters ...@@ -105,6 +108,19 @@ module Clusters
def cluster def cluster
@cluster ||= provider.cluster @cluster ||= provider.cluster
end 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 end
end end
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