Welcome to mirror list, hosted at ThFree Co, Russian Federation.

prometheus_client.rb « concerns « clusters « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d2f69b813aac0a658e5813caa4553e56162d707c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

module Clusters
  module Concerns
    module PrometheusClient
      extend ActiveSupport::Concern

      included do
        include PrometheusAdapter

        def service_name
          'prometheus-prometheus-server'
        end

        def service_port
          80
        end

        def prometheus_client
          return unless kube_client

          proxy_url = kube_client.proxy_url('service', service_name, service_port, Gitlab::Kubernetes::Helm::NAMESPACE)

          # ensures headers containing auth data are appended to original k8s client options
          options = kube_client.rest_client.options
            .merge(prometheus_client_default_options)
            .merge(headers: kube_client.headers)
          Gitlab::PrometheusClient.new(proxy_url, options)
        rescue Kubeclient::HttpError, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::ENETUNREACH
          # 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.
          # Since `PrometheusAdapter#can_query?` is eargely loaded on environment pages in gitlab,
          # we need to silence the exceptions
        end

        def configured?
          kube_client.present? && available?
        rescue Gitlab::UrlBlocker::BlockedUrlError
          false
        end

        private

        def kube_client
          cluster&.kubeclient&.core_client
        end
      end
    end
  end
end