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
681f2ee5
Commit
681f2ee5
authored
Jul 22, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes broken backend specs
parent
e4ba4ccf
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
104 additions
and
47 deletions
+104
-47
ee/app/models/prometheus_alert.rb
ee/app/models/prometheus_alert.rb
+1
-1
ee/app/models/prometheus_metric.rb
ee/app/models/prometheus_metric.rb
+1
-1
ee/app/policies/ee/project_policy.rb
ee/app/policies/ee/project_policy.rb
+0
-1
ee/app/services/clusters/applications/schedule_update_service.rb
...services/clusters/applications/schedule_update_service.rb
+1
-1
ee/app/services/projects/prometheus/metrics/destroy_service.rb
...p/services/projects/prometheus/metrics/destroy_service.rb
+1
-1
ee/app/services/projects/prometheus/metrics/update_service.rb
...pp/services/projects/prometheus/metrics/update_service.rb
+2
-2
ee/app/workers/cluster_update_app_worker.rb
ee/app/workers/cluster_update_app_worker.rb
+1
-1
ee/lib/ee/gitlab/prometheus/queries/query_additional_metrics.rb
.../ee/gitlab/prometheus/queries/query_additional_metrics.rb
+2
-2
ee/spec/controllers/projects/prometheus/alerts_controller_spec.rb
...controllers/projects/prometheus/alerts_controller_spec.rb
+16
-16
ee/spec/factories/prometheus_alert.rb
ee/spec/factories/prometheus_alert.rb
+0
-2
ee/spec/models/prometheus_alert_spec.rb
ee/spec/models/prometheus_alert_spec.rb
+8
-14
ee/spec/serializers/prometheus_alert_entity_spec.rb
ee/spec/serializers/prometheus_alert_entity_spec.rb
+1
-1
ee/spec/services/projects/prometheus/metrics/destroy_service_spec.rb
...vices/projects/prometheus/metrics/destroy_service_spec.rb
+26
-0
ee/spec/services/projects/prometheus/metrics/update_service_spec.rb
...rvices/projects/prometheus/metrics/update_service_spec.rb
+42
-0
ee/spec/workers/cluster_update_app_worker_spec.rb
ee/spec/workers/cluster_update_app_worker_spec.rb
+2
-4
No files found.
ee/app/models/prometheus_alert.rb
View file @
681f2ee5
...
...
@@ -7,7 +7,7 @@ class PrometheusAlert < ActiveRecord::Base
belongs_to
:environment
,
required:
true
,
validate:
true
,
inverse_of: :prometheus_alerts
belongs_to
:project
,
required:
true
,
validate:
true
,
inverse_of: :prometheus_alerts
belongs_to
:prometheus_metric
,
required:
true
,
validate:
true
belongs_to
:prometheus_metric
,
required:
true
,
validate:
true
,
inverse_of: :prometheus_alert
after_save
:clear_prometheus_adapter_cache!
after_destroy
:clear_prometheus_adapter_cache!
...
...
ee/app/models/prometheus_metric.rb
View file @
681f2ee5
class
PrometheusMetric
<
ActiveRecord
::
Base
belongs_to
:project
,
required:
true
,
validate:
true
,
inverse_of: :prometheus_metrics
has_one
:prometheus_alert
has_one
:prometheus_alert
,
inverse_of: :prometheus_metric
enum
group:
[
:business
,
:response
,
:system
]
...
...
ee/app/policies/ee/project_policy.rb
View file @
681f2ee5
...
...
@@ -49,7 +49,6 @@ module EE
@subject
.
feature_available?
(
:pod_logs
,
@user
)
end
with_scope
:subject
condition
(
:prometheus_alerts_enabled
)
do
@subject
.
feature_available?
(
:prometheus_alerts
,
@user
)
end
...
...
ee/app/services/clusters/applications/schedule_update_service.rb
View file @
681f2ee5
...
...
@@ -29,7 +29,7 @@ module Clusters
def
recently_scheduled?
return
false
unless
application
.
last_update_started_at
application
.
last_update_started_at
>=
Time
.
now
-
BACKOFF_DELAY
application
.
last_update_started_at
.
utc
>=
Time
.
now
.
utc
-
BACKOFF_DELAY
end
end
end
...
...
ee/app/services/projects/prometheus/metrics/destroy_service.rb
View file @
681f2ee5
module
Projects
module
Prometheus
module
Metrics
class
DestroyService
<
BaseService
class
DestroyService
<
Metrics
::
BaseService
def
execute
schedule_alert_update
if
has_alert?
metric
.
destroy
...
...
ee/app/services/projects/prometheus/metrics/update_service.rb
View file @
681f2ee5
module
Projects
module
Prometheus
module
Metrics
class
UpdateService
<
BaseService
class
UpdateService
<
Metrics
::
BaseService
def
execute
metric
.
update
(
params
)
metric
.
update
!
(
params
)
schedule_alert_update
if
requires_alert_update?
metric
end
...
...
ee/app/workers/cluster_update_app_worker.rb
View file @
681f2ee5
...
...
@@ -13,7 +13,7 @@ class ClusterUpdateAppWorker
find_application
(
app_name
,
app_id
)
do
|
app
|
break
if
app
.
updated_since?
(
scheduled_time
)
raise
UpdateAlreadyInProgressError
if
app
.
update_in_progress?
break
if
app
.
update_in_progress?
Clusters
::
Applications
::
PrometheusUpdateService
.
new
(
app
,
project
).
execute
end
...
...
ee/lib/ee/gitlab/prometheus/queries/query_additional_metrics.rb
View file @
681f2ee5
...
...
@@ -16,11 +16,11 @@ module EE
end
proc
do
|
group
|
group
[
:metrics
]
&
.
map!
do
|
metric
|
group
[
:metrics
]
=
group
[
:metrics
]
&
.
map
do
|
metric
|
key
=
metric
[
:id
]
if
key
&&
alerts_map
[
key
]
metric
[
:queries
]
&
.
map!
do
|
item
|
metric
[
:queries
]
=
metric
[
:queries
]
&
.
map
do
|
item
|
item
[
:alert_path
]
=
alert_path
(
alerts_map
,
key
,
project
,
environment
)
item
...
...
ee/spec/controllers/projects/prometheus/alerts_controller_spec.rb
View file @
681f2ee5
...
...
@@ -14,6 +14,14 @@ describe Projects::Prometheus::AlertsController do
describe
'GET #index'
do
context
'when project has no prometheus alert'
do
it
'renders forbidden when unlicensed'
do
stub_licensed_features
(
prometheus_alerts:
false
)
get
:index
,
project_params
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
it
'returns an empty response'
do
get
:index
,
project_params
...
...
@@ -27,14 +35,6 @@ describe Projects::Prometheus::AlertsController do
create_list
(
:prometheus_alert
,
3
,
project:
project
,
environment:
environment
)
end
it
'renders forbidden when unlicensed'
do
stub_licensed_features
(
prometheus_alerts:
false
)
get
:index
,
project_params
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
it
'contains prometheus alerts'
do
get
:index
,
project_params
...
...
@@ -47,7 +47,7 @@ describe Projects::Prometheus::AlertsController do
describe
'GET #show'
do
context
'when alert does not exist'
do
it
'renders 404'
do
get
:show
,
project_params
(
id:
PrometheusAlert
.
all
.
maximum
(
:prometheus_metric_id
).
to_i
)
get
:show
,
project_params
(
id:
PrometheusAlert
.
all
.
maximum
(
:prometheus_metric_id
).
to_i
+
1
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
...
...
@@ -67,7 +67,7 @@ describe Projects::Prometheus::AlertsController do
it
'renders the alert'
do
alert_params
=
{
"id"
=>
alert
.
id
,
"
name"
=>
alert
.
nam
e
,
"
title"
=>
alert
.
titl
e
,
"query"
=>
alert
.
query
,
"operator"
=>
alert
.
computed_operator
,
"threshold"
=>
alert
.
threshold
,
...
...
@@ -88,7 +88,7 @@ describe Projects::Prometheus::AlertsController do
notification_service
=
spy
alert_params
=
{
"alert"
=>
alert
.
nam
e
,
"alert"
=>
alert
.
titl
e
,
"expr"
=>
"
#{
alert
.
query
}
#{
alert
.
computed_operator
}
#{
alert
.
threshold
}
"
,
"for"
=>
"5m"
,
"labels"
=>
{
...
...
@@ -98,10 +98,10 @@ describe Projects::Prometheus::AlertsController do
}
allow
(
NotificationService
).
to
receive
(
:new
).
and_return
(
notification_service
)
expect
(
notification_service
).
to
receive_message_chain
(
:async
,
:prometheus_alerts_fired
).
with
(
project
,
[
alert_params
])
post
:notify
,
project_params
(
alerts:
[
alert
])
expect
(
notification_service
).
to
have_received
(
:prometheus_alerts_fired
).
with
(
project
,
[
alert_params
])
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
...
...
@@ -123,7 +123,7 @@ describe Projects::Prometheus::AlertsController do
it
'creates a new prometheus alert'
do
schedule_update_service
=
spy
alert_params
=
{
"
nam
e"
=>
metric
.
title
,
"
titl
e"
=>
metric
.
title
,
"query"
=>
metric
.
query
,
"operator"
=>
">"
,
"threshold"
=>
1.0
...
...
@@ -155,7 +155,7 @@ describe Projects::Prometheus::AlertsController do
it
'renders forbidden when unlicensed'
do
stub_licensed_features
(
prometheus_alerts:
false
)
put
:update
,
project_params
(
id:
alert
.
prometheus_metric_id
,
name:
"bar
"
)
put
:update
,
project_params
(
id:
alert
.
prometheus_metric_id
,
operator:
"<
"
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
...
...
@@ -163,9 +163,9 @@ describe Projects::Prometheus::AlertsController do
it
'updates an already existing prometheus alert'
do
alert_params
=
{
"id"
=>
alert
.
id
,
"
name"
=>
"bar"
,
"
title"
=>
alert
.
title
,
"query"
=>
alert
.
query
,
"operator"
=>
alert
.
computed_operator
,
"operator"
=>
"<"
,
"threshold"
=>
alert
.
threshold
,
"alert_path"
=>
Gitlab
::
Routing
.
url_helpers
.
project_prometheus_alert_path
(
project
,
alert
.
prometheus_metric_id
,
environment_id:
alert
.
environment
.
id
,
format: :json
)
}
...
...
ee/spec/factories/prometheus_alert.rb
View file @
681f2ee5
...
...
@@ -3,8 +3,6 @@ FactoryBot.define do
project
environment
prometheus_metric
name
{
generate
(
:title
)
}
query
"foo"
operator
:gt
threshold
1
end
...
...
ee/spec/models/prometheus_alert_spec.rb
View file @
681f2ee5
require
'spec_helper'
describe
PrometheusAlert
do
let
(
:metric
)
{
create
(
:prometheus_metric
)
}
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:environment
)
}
end
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
end
describe
'#full_query'
do
it
'returns the concatenated query'
do
subject
.
name
=
"bar"
subject
.
query
=
"foo"
subject
.
operator
=
"gt"
subject
.
threshold
=
1
subject
.
prometheus_metric_id
=
1
subject
.
prometheus_metric_id
=
metric
.
id
expect
(
subject
.
full_query
).
to
eq
(
"
foo
> 1.0"
)
expect
(
subject
.
full_query
).
to
eq
(
"
#{
metric
.
query
}
> 1.0"
)
end
end
describe
'#to_param'
do
it
'returns the params of the prometheus alert'
do
subject
.
name
=
"bar"
subject
.
query
=
"foo"
subject
.
operator
=
"gt"
subject
.
threshold
=
1
subject
.
prometheus_metric_id
=
1
subject
.
prometheus_metric_id
=
metric
.
id
alert_params
=
{
"alert"
=>
"bar"
,
"expr"
=>
"
foo
> 1.0"
,
"alert"
=>
metric
.
title
,
"expr"
=>
"
#{
metric
.
query
}
> 1.0"
,
"for"
=>
"5m"
,
"labels"
=>
{
"gitlab"
=>
"hook"
,
"gitlab_alert_id"
=>
1
"gitlab_alert_id"
=>
metric
.
id
}
}
...
...
ee/spec/serializers/prometheus_alert_entity_spec.rb
View file @
681f2ee5
...
...
@@ -15,7 +15,7 @@ describe PrometheusAlertEntity do
end
it
'exposes prometheus_alert attributes'
do
expect
(
subject
).
to
include
(
:id
,
:
nam
e
,
:query
,
:operator
,
:threshold
)
expect
(
subject
).
to
include
(
:id
,
:
titl
e
,
:query
,
:operator
,
:threshold
)
end
it
'exposes alert_path'
do
...
...
ee/spec/services/projects/prometheus/metrics/destroy_service_spec.rb
0 → 100644
View file @
681f2ee5
require
'spec_helper'
describe
Projects
::
Prometheus
::
Metrics
::
DestroyService
do
let
(
:metric
)
{
create
(
:prometheus_metric
)
}
subject
{
described_class
.
new
(
metric
)
}
it
'destroys metric'
do
subject
.
execute
expect
(
PrometheusMetric
.
find_by
(
id:
metric
.
id
)).
to
be_nil
end
context
'when metric has a prometheus alert associated'
do
it
'schedules a prometheus alert update'
do
create
(
:prometheus_alert
,
prometheus_metric:
metric
)
schedule_update_service
=
spy
allow
(
::
Clusters
::
Applications
::
ScheduleUpdateService
).
to
receive
(
:new
).
and_return
(
schedule_update_service
)
subject
.
execute
expect
(
schedule_update_service
).
to
have_received
(
:execute
)
end
end
end
ee/spec/services/projects/prometheus/metrics/update_service_spec.rb
0 → 100644
View file @
681f2ee5
require
'spec_helper'
describe
Projects
::
Prometheus
::
Metrics
::
UpdateService
do
let
(
:metric
)
{
create
(
:prometheus_metric
)
}
it
'updates the prometheus metric'
do
expect
do
described_class
.
new
(
metric
,
{
title:
"bar"
}).
execute
end
.
to
change
{
metric
.
reload
.
title
}.
to
(
"bar"
)
end
context
'when metric has a prometheus alert associated'
do
let
(
:schedule_update_service
)
{
spy
}
before
do
create
(
:prometheus_alert
,
prometheus_metric:
metric
)
allow
(
::
Clusters
::
Applications
::
ScheduleUpdateService
).
to
receive
(
:new
).
and_return
(
schedule_update_service
)
end
context
'when updating title'
do
it
'schedules a prometheus alert update'
do
described_class
.
new
(
metric
,
{
title:
"bar"
}).
execute
expect
(
schedule_update_service
).
to
have_received
(
:execute
)
end
end
context
'when updating query'
do
it
'schedules a prometheus alert update'
do
described_class
.
new
(
metric
,
{
query:
"sum(bar)"
}).
execute
expect
(
schedule_update_service
).
to
have_received
(
:execute
)
end
end
it
'does not schedule a prometheus alert update without title nor query being changed'
do
described_class
.
new
(
metric
,
{
y_label:
"bar"
}).
execute
expect
(
schedule_update_service
).
not_to
have_received
(
:execute
)
end
end
end
ee/spec/workers/cluster_update_app_worker_spec.rb
View file @
681f2ee5
...
...
@@ -26,12 +26,10 @@ describe ClusterUpdateAppWorker do
end
context
'when another worker is already running'
do
it
'r
aises UpdateAlreadyInProgressError
'
do
it
'r
eturns nil
'
do
application
=
create
(
:clusters_applications_prometheus
,
:updating
)
expect
do
subject
.
perform
(
application
.
name
,
application
.
id
,
project
.
id
,
Time
.
now
)
end
.
to
raise_error
(
described_class
::
UpdateAlreadyInProgressError
)
expect
(
subject
.
perform
(
application
.
name
,
application
.
id
,
project
.
id
,
Time
.
now
)).
to
be_nil
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