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

inline_cluster_metrics_filter.rb « filter « banzai « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a696d3a6f9c7b83eafac096283d6414e1fe2450f (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
# frozen_string_literal: true

module Banzai
  module Filter
    class InlineClusterMetricsFilter < ::Banzai::Filter::InlineEmbedsFilter
      def embed_params(node)
        url = node['href']
        @query_params = query_params(url)
        return unless [:group, :title, :y_label].all? do |param|
          @query_params.include?(param)
        end

        link_pattern.match(url) { |m| m.named_captures }.symbolize_keys
      end

      def xpath_search
        "descendant-or-self::a[contains(@href,'clusters') and \
          starts-with(@href, '#{gitlab_domain}')]"
      end

      def link_pattern
        ::Gitlab::Metrics::Dashboard::Url.clusters_regex
      end

      def metrics_dashboard_url(params)
        ::Gitlab::Routing.url_helpers.metrics_dashboard_namespace_project_cluster_url(
          params[:namespace],
          params[:project],
          params[:cluster_id],
          # Only Project clusters are supported for now
          # admin and group cluster types may be supported in the future
          cluster_type: :project,
          embedded: true,
          format: :json,
          **@query_params
        )
      end
    end
  end
end