diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-14 03:06:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-14 03:06:25 +0000 |
commit | 29c01c6c91558358c37ba45b03f240632bfb918d (patch) | |
tree | c6475afaf98ce740e8ba5fe227e7bd4a95b692cd /app/models/clusters | |
parent | eed996ac33a60d5fd8315a62fec8beaa8e907e69 (diff) | |
download | gitlab-ce-29c01c6c91558358c37ba45b03f240632bfb918d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/clusters')
-rw-r--r-- | app/models/clusters/applications/elastic_stack.rb | 29 | ||||
-rw-r--r-- | app/models/clusters/concerns/application_core.rb | 18 |
2 files changed, 47 insertions, 0 deletions
diff --git a/app/models/clusters/applications/elastic_stack.rb b/app/models/clusters/applications/elastic_stack.rb index addf092fc5e..8589f8c00cb 100644 --- a/app/models/clusters/applications/elastic_stack.rb +++ b/app/models/clusters/applications/elastic_stack.rb @@ -5,12 +5,15 @@ module Clusters class ElasticStack < ApplicationRecord VERSION = '1.8.0' + ELASTICSEARCH_PORT = 9200 + self.table_name = 'clusters_applications_elastic_stacks' include ::Clusters::Concerns::ApplicationCore include ::Clusters::Concerns::ApplicationStatus include ::Clusters::Concerns::ApplicationVersion include ::Clusters::Concerns::ApplicationData + include ::Gitlab::Utils::StrongMemoize default_value_for :version, VERSION @@ -49,6 +52,28 @@ module Clusters ) end + def elasticsearch_client + strong_memoize(:elasticsearch_client) do + next unless kube_client + + proxy_url = kube_client.proxy_url('service', 'elastic-stack-elasticsearch-client', ::Clusters::Applications::ElasticStack::ELASTICSEARCH_PORT, Gitlab::Kubernetes::Helm::NAMESPACE) + + Elasticsearch::Client.new(url: proxy_url) do |faraday| + # ensures headers containing auth data are appended to original client options + faraday.headers.merge!(kube_client.headers) + # ensure TLS certs are properly verified + faraday.ssl[:verify] = kube_client.ssl_options[:verify_ssl] + faraday.ssl[:cert_store] = kube_client.ssl_options[:cert_store] + end + + rescue Kubeclient::HttpError => error + # If users have mistakenly set parameters or removed the depended clusters, + # `proxy_url` could raise an exception because gitlab can not communicate with the cluster. + # We check for a nil client in downstream use and behaviour is equivalent to an empty state + log_exception(error, :failed_to_create_elasticsearch_client) + end + end + private def specification @@ -74,6 +99,10 @@ module Clusters Gitlab::Kubernetes::KubectlCmd.delete("pvc", "--selector", "release=elastic-stack") ].compact end + + def kube_client + cluster&.kubeclient&.core_client + end end end end diff --git a/app/models/clusters/concerns/application_core.rb b/app/models/clusters/concerns/application_core.rb index 979cf0645f5..21b98534808 100644 --- a/app/models/clusters/concerns/application_core.rb +++ b/app/models/clusters/concerns/application_core.rb @@ -60,6 +60,24 @@ module Clusters # Override if your application needs any action after # being uninstalled by Helm end + + def logger + @logger ||= Gitlab::Kubernetes::Logger.build + end + + def log_exception(error, event) + logger.error({ + exception: error.class.name, + status_code: error.error_code, + cluster_id: cluster&.id, + application_id: id, + class_name: self.class.name, + event: event, + message: error.message + }) + + Gitlab::Sentry.track_acceptable_exception(error, extra: { cluster_id: cluster&.id, application_id: id }) + end end end end |