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
19812e3e
Commit
19812e3e
authored
Jun 20, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make queries not die when underlying data cannot be found
parent
15b7b9ec
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
46 deletions
+50
-46
lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
...prometheus/queries/additional_metrics_deployment_query.rb
+9
-8
lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
...rometheus/queries/additional_metrics_environment_query.rb
+9
-8
lib/gitlab/prometheus/queries/deployment_query.rb
lib/gitlab/prometheus/queries/deployment_query.rb
+17
-16
lib/gitlab/prometheus/queries/environment_query.rb
lib/gitlab/prometheus/queries/environment_query.rb
+13
-12
spec/controllers/projects/deployments_controller_spec.rb
spec/controllers/projects/deployments_controller_spec.rb
+2
-2
No files found.
lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
View file @
19812e3e
...
@@ -5,15 +5,16 @@ module Gitlab
...
@@ -5,15 +5,16 @@ module Gitlab
include
QueryAdditionalMetrics
include
QueryAdditionalMetrics
def
query
(
deployment_id
)
def
query
(
deployment_id
)
deployment
=
Deployment
.
find_by
(
id:
deployment_id
)
Deployment
.
find_by
(
id:
deployment_id
).
try
do
|
deployment
|
query_context
=
{
query_context
=
{
environment_slug:
deployment
.
environment
.
slug
,
environment_slug:
deployment
.
environment
.
slug
,
environment_filter:
%{container_name!="POD",environment="#{deployment.environment.slug}"}
,
environment_filter:
%{container_name!="POD",environment="#{deployment.environment.slug}"}
,
timeframe_start:
(
deployment
.
created_at
-
30
.
minutes
).
to_f
,
timeframe_start:
(
deployment
.
created_at
-
30
.
minutes
).
to_f
,
timeframe_end:
(
deployment
.
created_at
+
30
.
minutes
).
to_f
timeframe_end:
(
deployment
.
created_at
+
30
.
minutes
).
to_f
}
}
query_metrics
(
query_context
)
query_metrics
(
query_context
)
end
end
end
end
end
end
end
...
...
lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
View file @
19812e3e
...
@@ -5,15 +5,16 @@ module Gitlab
...
@@ -5,15 +5,16 @@ module Gitlab
include
QueryAdditionalMetrics
include
QueryAdditionalMetrics
def
query
(
environment_id
)
def
query
(
environment_id
)
environment
=
Environment
.
find_by
(
id:
environment_id
)
Environment
.
find_by
(
id:
environment_id
).
try
do
|
environment
|
query_context
=
{
query_context
=
{
environment_slug:
environment
.
slug
,
environment_slug:
environment
.
slug
,
environment_filter:
%{container_name!="POD",environment="#{environment.slug}"}
,
environment_filter:
%{container_name!="POD",environment="#{environment.slug}"}
,
timeframe_start:
8
.
hours
.
ago
.
to_f
,
timeframe_start:
8
.
hours
.
ago
.
to_f
,
timeframe_end:
Time
.
now
.
to_f
timeframe_end:
Time
.
now
.
to_f
}
}
query_metrics
(
query_context
)
query_metrics
(
query_context
)
end
end
end
end
end
end
end
...
...
lib/gitlab/prometheus/queries/deployment_query.rb
View file @
19812e3e
...
@@ -3,26 +3,27 @@ module Gitlab
...
@@ -3,26 +3,27 @@ module Gitlab
module
Queries
module
Queries
class
DeploymentQuery
<
BaseQuery
class
DeploymentQuery
<
BaseQuery
def
query
(
deployment_id
)
def
query
(
deployment_id
)
deployment
=
Deployment
.
find_by
(
id:
deployment_id
)
Deployment
.
find_by
(
id:
deployment_id
).
try
do
|
deployment
|
environment_slug
=
deployment
.
environment
.
slug
environment_slug
=
deployment
.
environment
.
slug
memory_query
=
raw_memory_usage_query
(
environment_slug
)
memory_query
=
raw_memory_usage_query
(
environment_slug
)
memory_avg_query
=
%{avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="#{environment_slug}"}[30m]))}
memory_avg_query
=
%{avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="#{environment_slug}"}[30m]))}
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
cpu_avg_query
=
%{avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="#{environment_slug}"}[30m])) * 100}
cpu_avg_query
=
%{avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="#{environment_slug}"}[30m])) * 100}
timeframe_start
=
(
deployment
.
created_at
-
30
.
minutes
).
to_f
timeframe_start
=
(
deployment
.
created_at
-
30
.
minutes
).
to_f
timeframe_end
=
(
deployment
.
created_at
+
30
.
minutes
).
to_f
timeframe_end
=
(
deployment
.
created_at
+
30
.
minutes
).
to_f
{
{
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_before:
client_query
(
memory_avg_query
,
time:
deployment
.
created_at
.
to_f
),
memory_before:
client_query
(
memory_avg_query
,
time:
deployment
.
created_at
.
to_f
),
memory_after:
client_query
(
memory_avg_query
,
time:
timeframe_end
),
memory_after:
client_query
(
memory_avg_query
,
time:
timeframe_end
),
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_before:
client_query
(
cpu_avg_query
,
time:
deployment
.
created_at
.
to_f
),
cpu_before:
client_query
(
cpu_avg_query
,
time:
deployment
.
created_at
.
to_f
),
cpu_after:
client_query
(
cpu_avg_query
,
time:
timeframe_end
)
cpu_after:
client_query
(
cpu_avg_query
,
time:
timeframe_end
)
}
}
end
end
end
end
end
end
end
...
...
lib/gitlab/prometheus/queries/environment_query.rb
View file @
19812e3e
...
@@ -3,20 +3,21 @@ module Gitlab
...
@@ -3,20 +3,21 @@ module Gitlab
module
Queries
module
Queries
class
EnvironmentQuery
<
BaseQuery
class
EnvironmentQuery
<
BaseQuery
def
query
(
environment_id
)
def
query
(
environment_id
)
environment
=
Environment
.
find_by
(
id:
environment_id
)
Environment
.
find_by
(
id:
environment_id
).
try
do
|
environment
|
environment_slug
=
environment
.
slug
environment_slug
=
environment
.
slug
timeframe_start
=
8
.
hours
.
ago
.
to_f
timeframe_start
=
8
.
hours
.
ago
.
to_f
timeframe_end
=
Time
.
now
.
to_f
timeframe_end
=
Time
.
now
.
to_f
memory_query
=
raw_memory_usage_query
(
environment_slug
)
memory_query
=
raw_memory_usage_query
(
environment_slug
)
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
{
{
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_current:
client_query
(
memory_query
,
time:
timeframe_end
),
memory_current:
client_query
(
memory_query
,
time:
timeframe_end
),
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_current:
client_query
(
cpu_query
,
time:
timeframe_end
)
cpu_current:
client_query
(
cpu_query
,
time:
timeframe_end
)
}
}
end
end
end
end
end
end
end
...
...
spec/controllers/projects/deployments_controller_spec.rb
View file @
19812e3e
...
@@ -141,7 +141,7 @@ describe Projects::DeploymentsController do
...
@@ -141,7 +141,7 @@ describe Projects::DeploymentsController do
end
end
it
'returns a empty response 204 response'
do
it
'returns a empty response 204 response'
do
get
:additional_metrics
,
deployment_params
(
id:
deployment
.
id
)
get
:additional_metrics
,
deployment_params
(
id:
deployment
.
id
,
format: :json
)
expect
(
response
).
to
have_http_status
(
204
)
expect
(
response
).
to
have_http_status
(
204
)
expect
(
response
.
body
).
to
eq
(
''
)
expect
(
response
.
body
).
to
eq
(
''
)
end
end
...
@@ -161,7 +161,7 @@ describe Projects::DeploymentsController do
...
@@ -161,7 +161,7 @@ describe Projects::DeploymentsController do
end
end
it
'returns a metrics JSON document'
do
it
'returns a metrics JSON document'
do
get
:additional_metrics
,
deployment_params
(
id:
deployment
.
id
)
get
:additional_metrics
,
deployment_params
(
id:
deployment
.
id
,
format: :json
)
expect
(
response
).
to
be_ok
expect
(
response
).
to
be_ok
expect
(
json_response
[
'success'
]).
to
be
(
true
)
expect
(
json_response
[
'success'
]).
to
be
(
true
)
...
...
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