BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
608186d5
Commit
608186d5
authored
May 25, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add per deployment additional metrics
parent
4d8f3978
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
11 deletions
+54
-11
deployments_controller.rb
app/controllers/projects/deployments_controller.rb
+11
-0
deployment.rb
app/models/deployment.rb
+10
-0
project.rb
config/routes/project.rb
+1
-0
additional_metrics_deployment_query.rb
...prometheus/queries/additional_metrics_deployment_query.rb
+17
-0
additional_metrics_query.rb
lib/gitlab/prometheus/queries/additional_metrics_query.rb
+15
-11
No files found.
app/controllers/projects/deployments_controller.rb
View file @
608186d5
...
...
@@ -22,6 +22,17 @@ class Projects::DeploymentsController < Projects::ApplicationController
render_404
end
def
additional_metrics
return
render_404
unless
deployment
.
has_additional_metrics?
metrics
=
deployment
.
additional_metrics
if
metrics
&
.
any?
render
json:
metrics
,
status: :ok
else
head
:no_content
end
end
private
def
deployment
...
...
app/models/deployment.rb
View file @
608186d5
...
...
@@ -103,12 +103,22 @@ class Deployment < ActiveRecord::Base
project
.
monitoring_service
.
present?
end
def
has_additional_metrics?
has_metrics?
&&
project
.
monitoring_service
&
.
respond_to?
(
:reactive_query
)
end
def
metrics
return
{}
unless
has_metrics?
project
.
monitoring_service
.
deployment_metrics
(
self
)
end
def
additional_metrics
return
{}
unless
has_additional_metrics?
metrics
=
project
.
monitoring_service
.
reactive_query
(
Gitlab
::
Prometheus
::
Queries
::
AdditionalMetricsDeploymentQuery
.
name
,
id
,
&
:itself
)
metrics
&
.
merge
(
deployment_time:
created_at
.
to_i
)
||
{}
end
private
def
ref_path
...
...
config/routes/project.rb
View file @
608186d5
...
...
@@ -167,6 +167,7 @@ constraints(ProjectUrlConstrainer.new) do
resources
:deployments
,
only:
[
:index
]
do
member
do
get
:metrics
get
:additional_metrics
end
end
end
...
...
lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
0 → 100644
View file @
608186d5
module
Gitlab::Prometheus::Queries
class
AdditionalMetricsDeploymentQuery
<
AdditionalMetricsQuery
def
query
(
deployment_id
)
deployment
=
Deployment
.
find_by
(
id:
deployment_id
)
query_context
=
{
environment_slug:
deployment
.
environment
.
slug
,
environment_filter:
%{container_name!="POD",environment="#{deployment.environment.slug}"}
,
timeframe_start:
(
deployment
.
created_at
-
30
.
minutes
).
to_f
,
timeframe_end:
(
deployment
.
created_at
+
30
.
minutes
).
to_f
}
query_metrics
(
query_context
)
end
end
end
lib/gitlab/prometheus/queries/additional_metrics_query.rb
View file @
608186d5
module
Gitlab::Prometheus::Queries
class
AdditionalMetricsQuery
<
BaseQuery
def
query
(
environment_id
)
query_processor
=
method
(
:process_query
).
curry
[
query_context
(
environment_id
)]
environment
=
Environment
.
find_by
(
id:
environment_id
)
query_context
=
{
environment_slug:
environment
.
slug
,
environment_filter:
%{container_name!="POD",environment="#{environment.slug}"}
,
timeframe_start:
8
.
hours
.
ago
.
to_f
,
timeframe_end:
Time
.
now
.
to_f
}
query_metrics
(
query_context
)
end
protected
def
query_metrics
(
query_context
)
query_processor
=
method
(
:process_query
).
curry
[
query_context
]
matched_metrics
.
map
do
|
group
|
metrics
=
group
.
metrics
.
map
do
|
metric
|
...
...
@@ -22,16 +36,6 @@ module Gitlab::Prometheus::Queries
private
def
query_context
(
environment_id
)
environment
=
Environment
.
find_by
(
id:
environment_id
)
{
environment_slug:
environment
.
slug
,
environment_filter:
%{container_name!="POD",environment="#{environment.slug}"}
,
timeframe_start:
8
.
hours
.
ago
.
to_f
,
timeframe_end:
Time
.
now
.
to_f
}
end
def
process_query
(
context
,
query
)
query_with_result
=
query
.
dup
query_with_result
[
:result
]
=
...
...
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