2019-07-10 11:27:25 +00:00
|
|
|
# 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-08-01 00:09:45 +00:00
|
|
|
starts-with(@href, '#{gitlab_domain}')]"
|
2019-07-10 11:27:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Regular expression matching metrics urls
|
|
|
|
def link_pattern
|
2020-02-12 12:09:01 +00:00
|
|
|
Gitlab::Metrics::Dashboard::Url.metrics_regex
|
2019-07-10 11:27:25 +00:00
|
|
|
end
|
2019-08-15 21:38:29 +00:00
|
|
|
|
|
|
|
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,
|
2020-08-31 15:10:41 +00:00
|
|
|
**query_params(params['url']).except(:environment)
|
2019-08-15 21:38:29 +00:00
|
|
|
)
|
|
|
|
end
|
2019-07-10 11:27:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|