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
61d7b7f1
Commit
61d7b7f1
authored
May 25, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finalize refactoring additional metrics query
parent
20614140
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
50 deletions
+49
-50
environment.rb
app/models/environment.rb
+3
-1
prometheus_service.rb
app/models/project_services/prometheus_service.rb
+1
-1
metric_group.rb
lib/gitlab/prometheus/metric_group.rb
+4
-4
additional_metrics_query.rb
lib/gitlab/prometheus/queries/additional_metrics_query.rb
+39
-40
matched_metrics_query.rb
lib/gitlab/prometheus/queries/matched_metrics_query.rb
+2
-4
No files found.
app/models/environment.rb
View file @
61d7b7f1
...
@@ -158,7 +158,9 @@ class Environment < ActiveRecord::Base
...
@@ -158,7 +158,9 @@ class Environment < ActiveRecord::Base
end
end
def
additional_metrics
def
additional_metrics
project
.
monitoring_service
.
reactive_query
(
Gitlab
::
Prometheus
::
Queries
::
AdditionalMetricsQuery
,
self
.
id
)
if
has_additional_metrics?
if
has_additional_metrics?
project
.
monitoring_service
.
reactive_query
(
Gitlab
::
Prometheus
::
Queries
::
AdditionalMetricsQuery
.
name
,
self
.
id
,
&
:itself
)
end
end
end
# An environment name is not necessarily suitable for use in URLs, DNS
# An environment name is not necessarily suitable for use in URLs, DNS
...
...
app/models/project_services/prometheus_service.rb
View file @
61d7b7f1
...
@@ -73,7 +73,7 @@ class PrometheusService < MonitoringService
...
@@ -73,7 +73,7 @@ class PrometheusService < MonitoringService
end
end
def
reactive_query
(
query_class
,
*
args
,
&
block
)
def
reactive_query
(
query_class
,
*
args
,
&
block
)
calculate
_reactive_cache
(
query_class
,
*
args
,
&
block
)
with
_reactive_cache
(
query_class
,
*
args
,
&
block
)
end
end
# Cache metrics for specific environment
# Cache metrics for specific environment
...
...
lib/gitlab/prometheus/metric_group.rb
View file @
61d7b7f1
...
@@ -13,6 +13,10 @@ module Gitlab::Prometheus
...
@@ -13,6 +13,10 @@ module Gitlab::Prometheus
load_groups_from_yaml
load_groups_from_yaml
end
end
def
self
.
load_groups_from_yaml
additional_metrics_raw
.
map
(
&
method
(
:group_from_entry
))
end
def
self
.
group_from_entry
(
entry
)
def
self
.
group_from_entry
(
entry
)
missing_fields
=
[
:group
,
:priority
,
:metrics
].
select
{
|
key
|
!
entry
.
has_key?
(
key
)
}
missing_fields
=
[
:group
,
:priority
,
:metrics
].
select
{
|
key
|
!
entry
.
has_key?
(
key
)
}
raise
ParsingError
.
new
(
"entry missing required fields
#{
missing_fields
}
"
)
unless
missing_fields
.
empty?
raise
ParsingError
.
new
(
"entry missing required fields
#{
missing_fields
}
"
)
unless
missing_fields
.
empty?
...
@@ -22,10 +26,6 @@ module Gitlab::Prometheus
...
@@ -22,10 +26,6 @@ module Gitlab::Prometheus
group
group
end
end
def
self
.
load_groups_from_yaml
additional_metrics_raw
.
map
(
&
method
(
:group_from_entry
))
end
def
self
.
additional_metrics_raw
def
self
.
additional_metrics_raw
@additional_metrics_raw
||=
YAML
.
load_file
(
Rails
.
root
.
join
(
'config/additional_metrics.yml'
))
&
.
map
(
&
:deep_symbolize_keys
).
freeze
@additional_metrics_raw
||=
YAML
.
load_file
(
Rails
.
root
.
join
(
'config/additional_metrics.yml'
))
&
.
map
(
&
:deep_symbolize_keys
).
freeze
end
end
...
...
lib/gitlab/prometheus/queries/additional_metrics_query.rb
View file @
61d7b7f1
module
Gitlab::Prometheus::Queries
module
Gitlab::Prometheus::Queries
class
AdditionalMetricsQuery
<
BaseQuery
class
AdditionalMetricsQuery
<
BaseQuery
def
self
.
metrics
@metrics
||=
YAML
.
load_file
(
Rails
.
root
.
join
(
'config/custom_metrics.yml'
)).
freeze
end
def
query
(
environment_id
)
def
query
(
environment_id
)
environment
=
Environment
.
find_by
(
id:
environment_id
)
query_processor
=
method
(
:process_query
).
curry
[
query_context
(
environment_id
)]
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
matched_metrics
.
map
do
|
group
|
matched_metrics
.
map
do
|
group
|
group
[
:metrics
].
map!
do
|
metric
|
metrics
=
group
.
metrics
.
map
do
|
metric
|
metric
[
:queries
].
map!
do
|
query
|
{
query
=
query
.
symbolize_keys
title:
metric
.
title
,
query
[
:result
]
=
weight:
metric
.
weight
,
if
query
.
has_key?
(
:query_range
)
queries:
metric
.
queries
.
map
(
&
query_processor
)
client_query_range
(
query
[
:query_range
]
%
context
,
start:
timeframe_start
,
stop:
timeframe_end
)
}
else
client_query
(
query
[
:query
]
%
context
,
time:
timeframe_end
)
end
query
end
metric
end
end
group
{
group:
group
.
name
,
priority:
group
.
priority
,
metrics:
metrics
}
end
end
end
end
def
process_query
(
group
,
query
)
private
result
=
if
query
.
has_key?
(
:query_range
)
client_query_range
(
query
[
:query_range
]
%
context
,
start:
timeframe_start
,
stop:
timeframe_end
)
def
query_context
(
environment_id
)
else
environment
=
Environment
.
find_by
(
id:
environment_id
)
client_query
(
query
[
:query
]
%
context
,
time:
timeframe_end
)
{
end
environment_slug:
environment
.
slug
,
contains_metrics
=
result
.
all?
do
|
item
|
environment_filter:
%{container_name!="POD",environment="#{environment.slug}"}
,
item
&
.
[
](
:values
)
&
.
any?
||
item
&
.
[
](
:value
)
&
.
any?
timeframe_start:
8
.
hours
.
ago
.
to_f
,
end
timeframe_end:
Time
.
now
.
to_f
}
end
def
process_query
(
context
,
query
)
query_with_result
=
query
.
dup
query_with_result
[
:result
]
=
if
query
.
has_key?
(
:query_range
)
client_query_range
(
query
[
:query_range
]
%
context
,
start:
context
[
:timeframe_start
],
stop:
context
[
:timeframe_end
])
else
client_query
(
query
[
:query
]
%
context
,
time:
context
[
:timeframe_end
])
end
query_with_result
end
end
def
process_result
(
query_result
)
def
process_result
(
query_result
)
...
@@ -54,17 +53,17 @@ module Gitlab::Prometheus::Queries
...
@@ -54,17 +53,17 @@ module Gitlab::Prometheus::Queries
def
matched_metrics
def
matched_metrics
label_values
=
client_label_values
||
[]
label_values
=
client_label_values
||
[]
Gitlab
::
Prometheus
::
MetricGroup
.
all
result
=
Gitlab
::
Prometheus
::
MetricsSources
.
additional_metrics
.
map
do
|
group
|
result
=
Gitlab
::
Prometheus
::
MetricGroup
.
all
.
map
do
|
group
|
group
[
:metrics
].
map!
(
&
:symbolize_keys
)
group
.
metrics
.
select!
do
|
metric
|
group
[
:metrics
].
select!
do
|
metric
|
matcher
=
Regexp
.
compile
(
metric
.
detect
)
matcher
=
Regexp
.
compile
(
metric
[
:detect
])
label_values
.
any?
&
matcher
.
method
(
:match
)
label_values
.
any?
&
matcher
.
method
(
:match
)
end
end
group
group
end
end
result
.
select
{
|
group
|
!
group
[
:metrics
].
empty?
}
result
.
select
{
|
group
|
group
.
metrics
.
any?
}
end
end
end
end
end
end
lib/gitlab/prometheus/queries/matched_metrics_query.rb
View file @
61d7b7f1
...
@@ -2,10 +2,6 @@ module Gitlab::Prometheus::Queries
...
@@ -2,10 +2,6 @@ module Gitlab::Prometheus::Queries
class
MatchedMetricsQuery
<
BaseQuery
class
MatchedMetricsQuery
<
BaseQuery
MAX_QUERY_ITEMS
=
40
.
freeze
MAX_QUERY_ITEMS
=
40
.
freeze
def
self
.
metrics
@metrics
||=
YAML
.
load_file
(
Rails
.
root
.
join
(
'config/additional_metrics.yml'
)).
map
(
&
:deep_symbolize_keys
)
end
def
query
def
query
groups_data
.
map
do
|
group
,
data
|
groups_data
.
map
do
|
group
,
data
|
{
{
...
@@ -17,6 +13,8 @@ module Gitlab::Prometheus::Queries
...
@@ -17,6 +13,8 @@ module Gitlab::Prometheus::Queries
end
end
end
end
private
def
groups_data
def
groups_data
metrics_series
=
metrics_with_series
(
Gitlab
::
Prometheus
::
MetricGroup
.
all
)
metrics_series
=
metrics_with_series
(
Gitlab
::
Prometheus
::
MetricGroup
.
all
)
lookup
=
active_series_lookup
(
metrics_series
)
lookup
=
active_series_lookup
(
metrics_series
)
...
...
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