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-04-13 15:10:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-13 15:10:03 +0300
commit75ee59f7a108cf0c57e1e66e3ef5e439bae24fcd (patch)
treeb2f1ec89e16c6b27041f608c9fb12b7586e5ce94 /lib/gitlab/metrics
parente79918ce90dc31527be1ef0140a99cfe450d931e (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/metrics')
-rw-r--r--lib/gitlab/metrics/dashboard/stages/alerts_inserter.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/gitlab/metrics/dashboard/stages/alerts_inserter.rb b/lib/gitlab/metrics/dashboard/stages/alerts_inserter.rb
new file mode 100644
index 00000000000..38736158c3b
--- /dev/null
+++ b/lib/gitlab/metrics/dashboard/stages/alerts_inserter.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+require 'set'
+
+module Gitlab
+ module Metrics
+ module Dashboard
+ module Stages
+ class AlertsInserter < BaseStage
+ include ::Gitlab::Utils::StrongMemoize
+
+ def transform!
+ return if metrics_with_alerts.empty?
+
+ for_metrics do |metric|
+ next unless metrics_with_alerts.include?(metric[:metric_id])
+
+ metric[:alert_path] = alert_path(metric[:metric_id], project, params[:environment])
+ end
+ end
+
+ private
+
+ def metrics_with_alerts
+ strong_memoize(:metrics_with_alerts) do
+ alerts = ::Projects::Prometheus::AlertsFinder
+ .new(project: project, environment: params[:environment])
+ .execute
+
+ Set.new(alerts.map(&:prometheus_metric_id))
+ end
+ end
+
+ def alert_path(metric_id, project, environment)
+ ::Gitlab::Routing.url_helpers.project_prometheus_alert_path(project, metric_id, environment_id: environment.id, format: :json)
+ end
+ end
+ end
+ end
+ end
+end