Class: Banzai::Filter::InlineClusterMetricsFilter

Inherits:
InlineEmbedsFilter
  • Object
show all
Defined in:
lib/banzai/filter/inline_cluster_metrics_filter.rb

Instance Method Summary collapse

Methods inherited from InlineEmbedsFilter

#call, #create_element, #element_to_embed, #gitlab_domain, #query_params

Instance Method Details

#embed_params(node) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'lib/banzai/filter/inline_cluster_metrics_filter.rb', line 6

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

21
22
23
# File 'lib/banzai/filter/inline_cluster_metrics_filter.rb', line 21

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

#metrics_dashboard_url(params) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/banzai/filter/inline_cluster_metrics_filter.rb', line 25

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

#xpath_searchObject


16
17
18
19
# File 'lib/banzai/filter/inline_cluster_metrics_filter.rb', line 16

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