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
693602d9
Commit
693602d9
authored
May 09, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keep presentation logic in one place and remove unecessary arguments.
+ fix tests
parent
4f824d2a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
17 deletions
+22
-17
app/models/deployment.rb
app/models/deployment.rb
+1
-2
app/models/project_services/prometheus_service.rb
app/models/project_services/prometheus_service.rb
+3
-2
spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb
spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb
+11
-7
spec/models/deployment_spec.rb
spec/models/deployment_spec.rb
+5
-4
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+1
-1
spec/models/project_services/prometheus_service_spec.rb
spec/models/project_services/prometheus_service_spec.rb
+1
-1
No files found.
app/models/deployment.rb
View file @
693602d9
...
@@ -106,8 +106,7 @@ class Deployment < ActiveRecord::Base
...
@@ -106,8 +106,7 @@ class Deployment < ActiveRecord::Base
def
metrics
def
metrics
return
{}
unless
has_metrics?
return
{}
unless
has_metrics?
metrics
=
project
.
monitoring_service
.
deployment_metrics
(
self
)
project
.
monitoring_service
.
deployment_metrics
(
self
)
metrics
&
.
merge
(
deployment_time:
created_at
.
to_i
)
||
{}
end
end
private
private
...
...
app/models/project_services/prometheus_service.rb
View file @
693602d9
...
@@ -63,12 +63,13 @@ class PrometheusService < MonitoringService
...
@@ -63,12 +63,13 @@ class PrometheusService < MonitoringService
{
success:
false
,
result:
err
}
{
success:
false
,
result:
err
}
end
end
def
environment_metrics
(
environment
,
**
args
)
def
environment_metrics
(
environment
)
with_reactive_cache
(
Gitlab
::
Prometheus
::
Queries
::
EnvironmentQuery
.
name
,
environment
.
id
,
&
:itself
)
with_reactive_cache
(
Gitlab
::
Prometheus
::
Queries
::
EnvironmentQuery
.
name
,
environment
.
id
,
&
:itself
)
end
end
def
deployment_metrics
(
deployment
)
def
deployment_metrics
(
deployment
)
with_reactive_cache
(
Gitlab
::
Prometheus
::
Queries
::
DeploymentQuery
.
name
,
deployment
.
id
,
&
:itself
)
metrics
=
with_reactive_cache
(
Gitlab
::
Prometheus
::
Queries
::
DeploymentQuery
.
name
,
deployment
.
id
,
&
:itself
)
metrics
&
.
merge
(
deployment_time:
created_at
.
to_i
)
||
{}
end
end
# Cache metrics for specific environment
# Cache metrics for specific environment
...
...
spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb
View file @
693602d9
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Prometheus
::
Queries
::
DeploymentQuery
,
lib:
true
do
describe
Gitlab
::
Prometheus
::
Queries
::
DeploymentQuery
,
lib:
true
do
let
(
:environment
)
{
create
(
:environment
)
}
let
(
:environment
)
{
create
(
:environment
,
slug:
'environment-slug'
)
}
let
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
)
}
let
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
)
}
let
(
:client
)
{
double
(
'prometheus_client'
)
}
let
(
:client
)
{
double
(
'prometheus_client'
)
}
subject
{
described_class
.
new
(
client
)
}
subject
{
described_class
.
new
(
client
)
}
around
do
|
example
|
Timecop
.
freeze
{
example
.
run
}
end
it
'sends appropriate queries to prometheus'
do
it
'sends appropriate queries to prometheus'
do
start_time
=
(
deployment
.
created_at
-
30
.
minutes
).
to_f
start_time
=
(
deployment
.
created_at
-
30
.
minutes
).
to_f
stop_time
=
(
deployment
.
created_at
+
30
.
minutes
).
to_f
stop_time
=
(
deployment
.
created_at
+
30
.
minutes
).
to_f
expect
(
client
).
to
receive
(
:query_range
).
with
(
'avg(container_memory_usage_bytes{container_name!="POD",environment="environment
1
"}) / 2^20'
,
expect
(
client
).
to
receive
(
:query_range
).
with
(
'avg(container_memory_usage_bytes{container_name!="POD",environment="environment
-slug
"}) / 2^20'
,
start:
start_time
,
stop:
stop_time
)
start:
start_time
,
stop:
stop_time
)
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment
1
"}[30m]))'
,
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment
-slug
"}[30m]))'
,
time:
deployment
.
created_at
.
to_f
)
time:
deployment
.
created_at
.
to_f
)
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment
1
"}[30m]))'
,
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment
-slug
"}[30m]))'
,
time:
stop_time
)
time:
stop_time
)
expect
(
client
).
to
receive
(
:query_range
).
with
(
'avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment
1
"}[2m])) * 100'
,
expect
(
client
).
to
receive
(
:query_range
).
with
(
'avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment
-slug
"}[2m])) * 100'
,
start:
start_time
,
stop:
stop_time
)
start:
start_time
,
stop:
stop_time
)
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment
1
"}[30m])) * 100'
,
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment
-slug
"}[30m])) * 100'
,
time:
deployment
.
created_at
.
to_f
)
time:
deployment
.
created_at
.
to_f
)
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment
1
"}[30m])) * 100'
,
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment
-slug
"}[30m])) * 100'
,
time:
stop_time
)
time:
stop_time
)
expect
(
subject
.
query
(
deployment
.
id
)).
to
eq
(
memory_values:
nil
,
memory_before:
nil
,
memory_after:
nil
,
expect
(
subject
.
query
(
deployment
.
id
)).
to
eq
(
memory_values:
nil
,
memory_before:
nil
,
memory_after:
nil
,
...
...
spec/models/deployment_spec.rb
View file @
693602d9
...
@@ -52,7 +52,7 @@ describe Deployment, models: true do
...
@@ -52,7 +52,7 @@ describe Deployment, models: true do
describe
'#metrics'
do
describe
'#metrics'
do
let
(
:deployment
)
{
create
(
:deployment
)
}
let
(
:deployment
)
{
create
(
:deployment
)
}
subject
{
deployment
.
metrics
(
1
.
hour
)
}
subject
{
deployment
.
metrics
}
context
'metrics are disabled'
do
context
'metrics are disabled'
do
it
{
is_expected
.
to
eq
({})
}
it
{
is_expected
.
to
eq
({})
}
...
@@ -63,16 +63,17 @@ describe Deployment, models: true do
...
@@ -63,16 +63,17 @@ describe Deployment, models: true do
{
{
success:
true
,
success:
true
,
metrics:
{},
metrics:
{},
last_update:
42
last_update:
42
,
deployment_time:
1494408956
}
}
end
end
before
do
before
do
allow
(
deployment
.
project
).
to
receive_message_chain
(
:monitoring_service
,
:metrics
)
allow
(
deployment
.
project
).
to
receive_message_chain
(
:monitoring_service
,
:
deployment_
metrics
)
.
with
(
any_args
).
and_return
(
simple_metrics
)
.
with
(
any_args
).
and_return
(
simple_metrics
)
end
end
it
{
is_expected
.
to
eq
(
simple_metrics
.
merge
(
deployment_time:
deployment
.
created_at
.
utc
.
to_i
)
)
}
it
{
is_expected
.
to
eq
(
simple_metrics
)
}
end
end
end
end
...
...
spec/models/environment_spec.rb
View file @
693602d9
...
@@ -393,7 +393,7 @@ describe Environment, models: true do
...
@@ -393,7 +393,7 @@ describe Environment, models: true do
it
'returns the metrics from the deployment service'
do
it
'returns the metrics from the deployment service'
do
expect
(
project
.
monitoring_service
)
expect
(
project
.
monitoring_service
)
.
to
receive
(
:metrics
).
with
(
environment
)
.
to
receive
(
:
environment_
metrics
).
with
(
environment
)
.
and_return
(
:fake_metrics
)
.
and_return
(
:fake_metrics
)
is_expected
.
to
eq
(
:fake_metrics
)
is_expected
.
to
eq
(
:fake_metrics
)
...
...
spec/models/project_services/prometheus_service_spec.rb
View file @
693602d9
...
@@ -82,7 +82,7 @@ describe PrometheusService, models: true, caching: true do
...
@@ -82,7 +82,7 @@ describe PrometheusService, models: true, caching: true do
end
end
it
'returns reactive data'
do
it
'returns reactive data'
do
is_expected
.
to
eq
(
prometheus_data
)
is_expected
.
to
eq
(
prometheus_data
.
merge
(
deployment_time:
deployment
.
created_at
.
to_i
)
)
end
end
end
end
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