debian-mirror-gitlab/lib/banzai/filter/inline_metrics_filter.rb

38 lines
1.1 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
module Banzai
module Filter
# HTML filter that inserts a placeholder element for each
# reference to a metrics dashboard.
class InlineMetricsFilter < Banzai::Filter::InlineEmbedsFilter
# Search params for selecting metrics links. A few
# simple checks is enough to boost performance without
# the cost of doing a full regex match.
def xpath_search
"descendant-or-self::a[contains(@href,'metrics') and \
2020-04-08 14:13:33 +05:30
contains(@href,'environments') and \
2019-09-30 21:07:59 +05:30
starts-with(@href, '#{Gitlab.config.gitlab.url}')]"
end
# Regular expression matching metrics urls
def link_pattern
2020-03-13 15:44:24 +05:30
Gitlab::Metrics::Dashboard::Url.metrics_regex
2019-09-30 21:07:59 +05:30
end
2019-10-12 21:52:04 +05:30
private
# Endpoint FE should hit to collect the appropriate
# chart information
def metrics_dashboard_url(params)
Gitlab::Metrics::Dashboard::Url.build_dashboard_url(
params['namespace'],
params['project'],
params['environment'],
embedded: true,
**query_params(params['url'])
)
end
2019-09-30 21:07:59 +05:30
end
end
end