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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /lib/banzai/filter/inline_alert_metrics_filter.rb
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'lib/banzai/filter/inline_alert_metrics_filter.rb')
-rw-r--r--lib/banzai/filter/inline_alert_metrics_filter.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/banzai/filter/inline_alert_metrics_filter.rb b/lib/banzai/filter/inline_alert_metrics_filter.rb
new file mode 100644
index 00000000000..a6140d1ac81
--- /dev/null
+++ b/lib/banzai/filter/inline_alert_metrics_filter.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+module Banzai
+ module Filter
+ # HTML filter that inserts a placeholder element for each
+ # reference to an alert dashboard.
+ class InlineAlertMetricsFilter < ::Banzai::Filter::InlineEmbedsFilter
+ include ::Gitlab::Routing
+ # Search params for selecting alert 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_dashboard') and \
+ contains(@href,'prometheus/alerts') and \
+ starts-with(@href, '#{gitlab_domain}')]"
+ end
+
+ # Regular expression matching alert dashboard urls
+ def link_pattern
+ ::Gitlab::Metrics::Dashboard::Url.alert_regex
+ end
+
+ private
+
+ # Endpoint FE should hit to collect the appropriate
+ # chart information
+ def metrics_dashboard_url(params)
+ metrics_dashboard_namespace_project_prometheus_alert_url(
+ params['namespace'],
+ params['project'],
+ params['alert'],
+ embedded: true,
+ format: :json,
+ **query_params(params['url'])
+ )
+ end
+
+ # Parses query params out from full url string into hash.
+ #
+ # Ex) 'https://<root>/<project>/metrics_dashboard?title=Title&group=Group'
+ # --> { title: 'Title', group: 'Group' }
+ def query_params(url)
+ ::Gitlab::Metrics::Dashboard::Url.parse_query(url)
+ end
+ end
+ end
+end