Commit a48bbfa0 authored by syasonik's avatar syasonik Committed by Peter Leitzen

Adds regex to match alerts endpoint

To prepare for the addition of support for embedding metrics
tied to an alert in GFM, this adds a regex which can be used
to identify usages of the alerts endpoint.

https://gitlab.com/gitlab-org/gitlab/issues/40997
parent e9abe4df
......@@ -21,6 +21,23 @@ module EE
)
end
end
# Matches dashboard urls for a metric chart embed
# for a specifc firing GitLab alert
#
# EX - https://<host>/<namespace>/<project>/prometheus/alerts/<alert_id>/metrics_dashboard
def alert_regex
strong_memoize(:alert_regex) do
regex_for_project_metrics(
%r{
/prometheus
/alerts
/(?<alert>\d+)
/metrics_dashboard
}x
)
end
end
end
end
end
......
......@@ -31,4 +31,32 @@ describe Gitlab::Metrics::Dashboard::Url do
it_behaves_like 'regex which matches url when expected'
end
describe '#alert_regex' do
let(:url) do
Gitlab::Routing.url_helpers.metrics_dashboard_namespace_project_prometheus_alert_url(
'foo',
'bar',
'1',
start: '2020-02-10T12:59:49.938Z',
end: '2020-02-10T20:59:49.938Z',
anchor: "anchor"
)
end
let(:expected_params) do
{
'url' => url,
'namespace' => 'foo',
'project' => 'bar',
'alert' => '1',
'query' => "?end=2020-02-10T20%3A59%3A49.938Z&start=2020-02-10T12%3A59%3A49.938Z",
'anchor' => '#anchor'
}
end
subject { described_class.alert_regex }
it_behaves_like 'regex which matches url when expected'
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment