Commit 1fc8efd1 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'sy-alert-regex' into 'master'

Add regex to match Prometheus Alert endpoint for GFM identification

See merge request gitlab-org/gitlab!24832
parents 27165fc1 a48bbfa0
...@@ -21,6 +21,23 @@ module EE ...@@ -21,6 +21,23 @@ module EE
) )
end end
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 end
end end
......
...@@ -31,4 +31,32 @@ describe Gitlab::Metrics::Dashboard::Url do ...@@ -31,4 +31,32 @@ describe Gitlab::Metrics::Dashboard::Url do
it_behaves_like 'regex which matches url when expected' it_behaves_like 'regex which matches url when expected'
end 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 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