Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ddb6f269
Commit
ddb6f269
authored
Jul 08, 2020
by
Sarah Yasonik
Committed by
Peter Leitzen
Jul 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move prometheus alert configuration into context
parent
2556532b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
180 additions
and
108 deletions
+180
-108
spec/presenters/alert_management/prometheus_alert_presenter_spec.rb
...nters/alert_management/prometheus_alert_presenter_spec.rb
+19
-5
spec/presenters/projects/prometheus/alert_presenter_spec.rb
spec/presenters/projects/prometheus/alert_presenter_spec.rb
+23
-81
spec/requests/api/graphql/project/alert_management/alert/metrics_dashboard_url_spec.rb
...ject/alert_management/alert/metrics_dashboard_url_spec.rb
+62
-0
spec/requests/api/graphql/project/alert_management/alerts_spec.rb
...uests/api/graphql/project/alert_management/alerts_spec.rb
+0
-22
spec/support/shared_contexts/prometheus/alert_shared_context.rb
...upport/shared_contexts/prometheus/alert_shared_context.rb
+76
-0
No files found.
spec/presenters/alert_management/prometheus_alert_presenter_spec.rb
View file @
ddb6f269
...
...
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec
.
describe
AlertManagement
::
PrometheusAlertPresenter
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:p
rometheus_p
ayload
)
do
let_it_be
(
:payload
)
do
{
'annotations'
=>
{
'title'
=>
'Alert title'
,
...
...
@@ -15,8 +15,8 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do
'generatorURL'
=>
'http://8d467bd4607a:9090/graph?g0.expr=vector%281%29&g0.tab=1'
}
end
let
_it_be
(
:alert
)
do
create
(
:alert_management_alert
,
:prometheus
,
project:
project
,
payload:
p
rometheus_p
ayload
)
let
(
:alert
)
do
create
(
:alert_management_alert
,
:prometheus
,
project:
project
,
payload:
payload
)
end
subject
(
:presenter
)
{
described_class
.
new
(
alert
)
}
...
...
@@ -47,8 +47,22 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do
end
describe
'#metrics_dashboard_url'
do
it
'is not defined'
do
expect
(
presenter
.
metrics_dashboard_url
).
to
be_nil
subject
{
presenter
.
metrics_dashboard_url
}
context
'for a non-prometheus alert'
do
it
{
is_expected
.
to
be_nil
}
end
context
'for a self-managed prometheus alert'
do
include_context
'self-managed prometheus alert attributes'
it
{
is_expected
.
to
eq
(
dashboard_url_for_alert
)
}
end
context
'for a gitlab-managed prometheus alert'
do
include_context
'gitlab-managed prometheus alert attributes'
it
{
is_expected
.
to
eq
(
dashboard_url_for_alert
)
}
end
end
end
spec/presenters/projects/prometheus/alert_presenter_spec.rb
View file @
ddb6f269
...
...
@@ -20,38 +20,6 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
end
end
shared_context
'self-managed prometheus alert with metrics data'
do
let!
(
:environment
)
{
create
(
:environment
,
project:
project
,
name:
'production'
)
}
let
(
:title
)
{
'title'
}
let
(
:y_label
)
{
'y_label'
}
let
(
:query
)
{
'avg(metric) > 1.0'
}
let
(
:embed_content
)
do
{
panel_groups:
[{
panels:
[{
type:
'line-graph'
,
title:
title
,
y_label:
y_label
,
metrics:
[{
query_range:
query
}]
}]
}]
}
end
before
do
payload
[
'startsAt'
]
=
starts_at
payload
[
'generatorURL'
]
=
"http://host?g0.expr=
#{
CGI
.
escape
(
query
)
}
"
payload
[
'labels'
]
||=
{}
payload
[
'labels'
][
'gitlab_environment_name'
]
=
'production'
payload
[
'annotations'
]
||=
{}
payload
[
'annotations'
][
'title'
]
=
'title'
payload
[
'annotations'
][
'gitlab_y_label'
]
=
'y_label'
end
end
describe
'#project_full_path'
do
subject
{
presenter
.
project_full_path
}
...
...
@@ -214,30 +182,30 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
Timecop
.
freeze
(
starts_at
)
{
example
.
run
}
end
before
do
payload
.
delete
(
'startsAt'
)
end
it
{
is_expected
.
to
eq
(
expected_markdown
)
}
end
context
'with a starting time available'
do
before
do
payload
[
'startsAt'
]
=
starts_at
end
it
{
is_expected
.
to
eq
(
expected_markdown
)
}
end
end
context
'for gitlab-managed prometheus alerts'
do
include_context
'gitlab
alert
'
include_context
'gitlab
-managed prometheus alert attributes
'
before
do
payload
[
'labels'
]
=
{
'gitlab_alert_id'
=>
metric_id
}
let
(
:alert
)
do
create
(
:alerting_alert
,
project:
project
,
metric_id:
prometheus_metric_id
,
payload:
payload
)
end
it_behaves_like
'markdown with metrics embed'
end
context
'for alerts from a self-managed prometheus'
do
include_context
'self-managed prometheus alert
with metrics data
'
include_context
'self-managed prometheus alert
attributes
'
it_behaves_like
'markdown with metrics embed'
...
...
@@ -369,28 +337,6 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
it
{
is_expected
.
to
eq
(
expected_link
)
}
end
describe
'#metrics_dashboard_url'
do
let
(
:starts_at
)
{
'2018-03-12T09:06:00Z'
}
let
(
:expected_url
)
do
metrics_dashboard_project_prometheus_alert_url
(
project
,
metric_id
,
environment_id:
gitlab_alert
.
environment_id
,
embedded:
true
,
end:
'2018-03-12T09:36:00Z'
,
start:
'2018-03-12T08:36:00Z'
)
end
subject
{
presenter
.
metrics_dashboard_url
}
before
do
payload
[
'startsAt'
]
=
starts_at
end
it
{
is_expected
.
to
eq
(
expected_url
)
}
end
end
context
'without gitlab alert'
do
...
...
@@ -431,33 +377,29 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
it
{
is_expected
.
to
eq
(
expected_link
)
}
end
end
describe
'#metrics_dashboard_url'
do
subject
{
presenter
.
metrics_dashboard_url
}
describe
'#metrics_dashboard_url'
do
subject
{
presenter
.
metrics_dashboard_url
}
context
'for a non-prometheus alert'
do
it
{
is_expected
.
to
be_nil
}
end
end
context
'with self-managed prometheus alert with metrics data
'
do
include_context
'self-managed prometheus alert with metrics data
'
context
'for a self-managed prometheus alert
'
do
include_context
'self-managed prometheus alert attributes
'
describe
'#metrics_dashboard_url'
do
let
(
:starts_at
)
{
'2018-03-12T09:06:00Z'
}
let
(
:expected_url
)
do
metrics_dashboard_project_environment_url
(
project
,
environment
,
embed_json:
embed_content
.
to_json
,
embedded:
true
,
end:
'2018-03-12T09:36:00Z'
,
start:
'2018-03-12T08:36:00Z'
)
end
let
(
:prometheus_payload
)
{
payload
}
it
{
is_expected
.
to
eq
(
dashboard_url_for_alert
)
}
end
context
'for a gitlab-managed prometheus alert'
do
include_context
'gitlab-managed prometheus alert attributes'
subject
{
presenter
.
metrics_dashboard_url
}
let
(
:prometheus_payload
)
{
payload
}
it
{
is_expected
.
to
eq
(
expected_url
)
}
it
{
is_expected
.
to
eq
(
dashboard_url_for_alert
)
}
end
end
end
spec/requests/api/graphql/project/alert_management/alert/metrics_dashboard_url_spec.rb
0 → 100644
View file @
ddb6f269
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'getting Alert Management Alert Assignees'
do
include
GraphqlHelpers
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let
(
:fields
)
do
<<~
QUERY
nodes {
iid
metricsDashboardUrl
}
QUERY
end
let
(
:graphql_query
)
do
graphql_query_for
(
'project'
,
{
'fullPath'
=>
project
.
full_path
},
query_graphql_field
(
'alertManagementAlerts'
,
{},
fields
)
)
end
let
(
:alerts
)
{
graphql_data
.
dig
(
'project'
,
'alertManagementAlerts'
,
'nodes'
)
}
let
(
:first_alert
)
{
alerts
.
first
}
before
do
project
.
add_developer
(
current_user
)
end
context
'with self-managed prometheus payload'
do
include_context
'self-managed prometheus alert attributes'
before
do
create
(
:alert_management_alert
,
:prometheus
,
project:
project
,
payload:
payload
)
end
it
'includes the correct metrics dashboard url'
do
post_graphql
(
graphql_query
,
current_user:
current_user
)
expect
(
first_alert
).
to
include
(
'metricsDashboardUrl'
=>
dashboard_url_for_alert
)
end
end
context
'with gitlab-managed prometheus payload'
do
include_context
'gitlab-managed prometheus alert attributes'
before
do
create
(
:alert_management_alert
,
:prometheus
,
project:
project
,
payload:
payload
,
prometheus_alert:
prometheus_alert
)
end
it
'includes the correct metrics dashboard url'
do
post_graphql
(
graphql_query
,
current_user:
current_user
)
expect
(
first_alert
).
to
include
(
'metricsDashboardUrl'
=>
dashboard_url_for_alert
)
end
end
end
spec/requests/api/graphql/project/alert_management/alerts_spec.rb
View file @
ddb6f269
...
...
@@ -136,28 +136,6 @@ RSpec.describe 'getting Alert Management Alerts' do
it
{
expect
(
alerts
.
size
).
to
eq
(
0
)
}
end
end
context
'with prometheus payload'
do
let_it_be
(
:gitlab_alert
)
{
create
(
:prometheus_alert
,
project:
project
)
}
let_it_be
(
:metric_id
)
{
gitlab_alert
.
prometheus_metric_id
}
let_it_be
(
:prometheus_payload
)
{
{
'labels'
=>
{
'gitlab_alert_id'
=>
metric_id
},
'startsAt'
=>
'2018-03-12T09:06:00Z'
}
}
let_it_be
(
:self_managed_alert
)
{
create
(
:alert_management_alert
,
:prometheus
,
project:
project
,
payload:
prometheus_payload
)
}
let
(
:expected_url
)
do
Gitlab
::
Routing
.
url_helpers
.
metrics_dashboard_project_prometheus_alert_url
(
project
,
metric_id
,
environment_id:
gitlab_alert
.
environment_id
,
start:
'2018-03-12T08:36:00Z'
,
end:
'2018-03-12T09:36:00Z'
,
embedded:
true
)
end
it
'includes a metrics dashboard url'
do
expect
(
first_alert
).
to
include
(
'metricsDashboardUrl'
=>
expected_url
)
end
end
end
end
end
spec/support/shared_contexts/prometheus/alert_shared_context.rb
0 → 100644
View file @
ddb6f269
# frozen_string_literal: true
# These contexts expect a `project` to be defined.
# It is expected that these contexts are used to create an
# alert.
RSpec
.
shared_context
'self-managed prometheus alert attributes'
do
let_it_be
(
:environment
)
{
create
(
:environment
,
project:
project
,
name:
'production'
)
}
let
(
:starts_at
)
{
'2018-03-12T09:06:00Z'
}
let
(
:title
)
{
'title'
}
let
(
:y_label
)
{
'y_label'
}
let
(
:query
)
{
'avg(metric) > 1.0'
}
let
(
:embed_content
)
do
{
panel_groups:
[{
panels:
[{
type:
'line-graph'
,
title:
title
,
y_label:
y_label
,
metrics:
[{
query_range:
query
}]
}]
}]
}.
to_json
end
let
(
:payload
)
do
{
'startsAt'
=>
starts_at
,
'generatorURL'
=>
"http://host?g0.expr=
#{
CGI
.
escape
(
query
)
}
"
,
'labels'
=>
{
'gitlab_environment_name'
=>
'production'
},
'annotations'
=>
{
'title'
=>
title
,
'gitlab_y_label'
=>
y_label
}
}
end
let
(
:dashboard_url_for_alert
)
do
Gitlab
::
Routing
.
url_helpers
.
metrics_dashboard_project_environment_url
(
project
,
environment
,
embed_json:
embed_content
,
embedded:
true
,
end:
'2018-03-12T09:36:00Z'
,
start:
'2018-03-12T08:36:00Z'
)
end
end
RSpec
.
shared_context
'gitlab-managed prometheus alert attributes'
do
let_it_be
(
:prometheus_alert
)
{
create
(
:prometheus_alert
,
project:
project
)
}
let
(
:prometheus_metric_id
)
{
prometheus_alert
.
prometheus_metric_id
}
let
(
:payload
)
do
{
'startsAt'
=>
'2018-03-12T09:06:00Z'
,
'labels'
=>
{
'gitlab_alert_id'
=>
prometheus_metric_id
}
}
end
let
(
:dashboard_url_for_alert
)
do
Gitlab
::
Routing
.
url_helpers
.
metrics_dashboard_project_prometheus_alert_url
(
project
,
prometheus_metric_id
,
environment_id:
prometheus_alert
.
environment_id
,
embedded:
true
,
end:
'2018-03-12T09:36:00Z'
,
start:
'2018-03-12T08:36:00Z'
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment