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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
6a70509a
Commit
6a70509a
authored
Jun 02, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Towards Reviewable prometheus
parent
e74896df
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
35 deletions
+146
-35
lib/gitlab/prometheus/queries/matched_metrics_query.rb
lib/gitlab/prometheus/queries/matched_metrics_query.rb
+3
-4
spec/db/production/settings.rb.orig
spec/db/production/settings.rb.orig
+16
-0
spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb
...b/gitlab/prometheus/queries/matched_metrics_query_spec.rb
+94
-31
spec/support/prometheus/matched_metrics_query_helper.rb
spec/support/prometheus/matched_metrics_query_helper.rb
+33
-0
No files found.
lib/gitlab/prometheus/queries/matched_metrics_query.rb
View file @
6a70509a
...
@@ -23,11 +23,10 @@ module Gitlab::Prometheus::Queries
...
@@ -23,11 +23,10 @@ module Gitlab::Prometheus::Queries
metrics_groups
.
each
do
|
group
|
metrics_groups
.
each
do
|
group
|
groups
[
group
]
||=
{
active_metrics:
0
,
metrics_missing_requirements:
0
}
groups
[
group
]
||=
{
active_metrics:
0
,
metrics_missing_requirements:
0
}
metrics
=
group
.
metrics
.
flat_map
(
&
:required_metrics
)
active_metrics
=
group
.
metrics
.
count
{
|
metric
|
metric
.
required_metrics
.
all?
(
&
lookup
.
method
(
:has_key?
))
}
active_metrics
=
metrics
.
count
(
&
lookup
.
method
(
:has_key?
))
groups
[
group
][
:active_metrics
]
+=
active_metrics
groups
[
group
][
:active_metrics
]
+=
active_metrics
groups
[
group
][
:metrics_missing_requirements
]
+=
metrics
.
count
-
active_metrics
groups
[
group
][
:metrics_missing_requirements
]
+=
group
.
metrics
.
count
-
active_metrics
end
end
groups
groups
...
@@ -48,7 +47,7 @@ module Gitlab::Prometheus::Queries
...
@@ -48,7 +47,7 @@ module Gitlab::Prometheus::Queries
end
end
def
has_matching_label
(
series_info
)
def
has_matching_label
(
series_info
)
series_info
.
has_
key?
(
'environment'
)
series_info
.
key?
(
'environment'
)
end
end
def
available_metrics
def
available_metrics
...
...
spec/db/production/settings.rb.orig
0 → 100644
View file @
6a70509a
require 'spec_helper'
describe 'seed production settings', lib: true do
include StubENV
context 'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN is set in the environment' do
before do
stub_env('GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN', '013456789')
end
it 'writes the token to the database' do
load(File.join(__dir__, '../../../db/fixtures/production/010_settings.rb'))
expect(ApplicationSetting.current.runners_registration_token).to eq('013456789')
end
end
end
spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb
View file @
6a70509a
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Prometheus
::
Queries
::
MatchedMetricsQuery
,
lib:
true
do
describe
Gitlab
::
Prometheus
::
Queries
::
MatchedMetricsQuery
,
lib:
true
do
let
(
:environment
)
{
create
(
:environment
,
slug:
'environment-slug'
)
}
include
Prometheus
::
MatchedMetricsQueryHelper
let
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
)
}
let
(
:metric_group_class
)
{
Gitlab
::
Prometheus
::
MetricGroup
}
let
(
:metric_class
)
{
Gitlab
::
Prometheus
::
Metric
}
let
(
:client
)
{
double
(
'prometheus_client'
)
}
let
(
:client
)
{
double
(
'prometheus_client'
)
}
subject
{
described_class
.
new
(
client
)
}
subject
{
described_class
.
new
(
client
)
}
around
do
|
example
|
context
'with one group where two metrics are found'
do
time_without_subsecond_values
=
Time
.
local
(
2008
,
9
,
1
,
12
,
0
,
0
)
before
do
Timecop
.
freeze
(
time_without_subsecond_values
)
{
example
.
run
}
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
])
end
allow
(
client
).
to
receive
(
:label_values
).
and_return
(
metric_names
)
end
let
(
:metric_group_class
)
{
Gitlab
::
Prometheus
::
MetricGroup
}
context
'both metrics in the group pass requirements'
do
let
(
:metric_class
)
{
Gitlab
::
Prometheus
::
Metric
}
before
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_with_environment
)
end
let
(
:simple_metrics
)
do
it
'responds with both metrics as actve'
do
[
expect
(
subject
.
query
).
to
eq
([{
group:
'name'
,
priority:
1
,
active_metrics:
2
,
metrics_missing_requirements:
0
}])
metric_class
.
new
(
'title'
,
[
'metrica'
,
'metricb'
],
'1'
,
'y_label'
,
[{
:query_range
=>
'avg'
}])
end
]
end
end
let
(
:simple_metric_group
)
do
context
'none of the metrics pass requirements'
do
metric_group_class
.
new
(
'name'
,
1
,
simple_metrics
)
before
do
end
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_without_environment
)
end
let
(
:xx
)
do
it
'responds with both metrics missing requirements'
do
[{
expect
(
subject
.
query
).
to
eq
([{
group:
'name'
,
priority:
1
,
active_metrics:
0
,
metrics_missing_requirements:
2
}])
'__name__'
:
'metrica'
,
end
'environment'
:
'mattermost'
end
},
{
context
'no series information found about the metrics'
do
'__name__'
:
'metricb'
,
before
do
'environment'
:
'mattermost'
allow
(
client
).
to
receive
(
:series
).
and_return
(
empty_series_info
)
}]
end
it
'responds with both metrics missing requirements'
do
expect
(
subject
.
query
).
to
eq
([{
group:
'name'
,
priority:
1
,
active_metrics:
0
,
metrics_missing_requirements:
2
}])
end
end
context
'one of the series info was not found'
do
before
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
partialy_empty_series_info
)
end
it
'responds with one active and one missing metric'
do
expect
(
subject
.
query
).
to
eq
([{
group:
'name'
,
priority:
1
,
active_metrics:
1
,
metrics_missing_requirements:
1
}])
end
end
end
end
before
do
context
'with one group where only one metric is found'
do
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
])
before
do
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
])
allow
(
client
).
to
receive
(
:label_values
).
and_return
(
'metric_a'
)
end
context
'both metrics in the group pass requirements'
do
before
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_with_environment
)
end
it
'responds with one metrics as active and no missing requiremens'
do
expect
(
subject
.
query
).
to
eq
([{
group:
'name'
,
priority:
1
,
active_metrics:
1
,
metrics_missing_requirements:
0
}])
end
end
allow
(
client
).
to
receive
(
:label_values
).
and_return
([
'metrica'
,
'metricb'
])
context
'no metrics in group pass requirements'
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
xx
)
before
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_without_environment
)
end
it
'responds with one metrics as active and no missing requiremens'
do
expect
(
subject
.
query
).
to
eq
([{
group:
'name'
,
priority:
1
,
active_metrics:
0
,
metrics_missing_requirements:
1
}])
end
end
end
end
it
"something something"
do
context
'with two groups where only one metric is found'
do
before
do
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
,
simple_metric_group
(
'nameb'
,
simple_metrics
(
'metric_c'
))])
allow
(
client
).
to
receive
(
:label_values
).
and_return
(
'metric_c'
)
end
context
'both metrics in the group pass requirements'
do
before
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_with_environment
(
'metric_c'
))
end
it
'responds with one metrics as active and no missing requiremens'
do
expect
(
subject
.
query
).
to
eq
([{
group:
'nameb'
,
priority:
1
,
active_metrics:
1
,
metrics_missing_requirements:
0
}])
end
end
context
'no metris in group pass requirements'
do
before
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_without_environment
)
end
expect
(
subject
.
query
).
to
eq
(
"asf"
)
it
'responds with one metrics as active and no missing requiremens'
do
expect
(
subject
.
query
).
to
eq
([{
group:
'nameb'
,
priority:
1
,
active_metrics:
0
,
metrics_missing_requirements:
1
}])
end
end
end
end
end
end
spec/support/prometheus/matched_metrics_query_helper.rb
0 → 100644
View file @
6a70509a
module
Prometheus
module
MatchedMetricsQueryHelper
def
metric_names
%w{metric_a metric_b}
end
def
simple_metrics
(
metric_name
=
'metric_a'
)
[
metric_class
.
new
(
'title'
,
%W(
#{
metric_name
}
metric_b)
,
nil
,
nil
),
metric_class
.
new
(
'title'
,
[
metric_name
],
nil
,
nil
)]
end
def
simple_metric_group
(
name
=
'name'
,
metrics
=
simple_metrics
)
metric_group_class
.
new
(
name
,
1
,
metrics
)
end
def
series_info_with_environment
(
*
more_metrics
)
%w{metric_a metric_b}
.
concat
(
more_metrics
).
map
{
|
metric_name
|
{
'__name__'
=>
metric_name
,
'environment'
=>
''
}
}
end
def
series_info_without_environment
[{
'__name__'
=>
'metric_a'
},
{
'__name__'
=>
'metric_b'
}]
end
def
partialy_empty_series_info
[{
'__name__'
=>
'metric_a'
,
'environment'
=>
''
}]
end
def
empty_series_info
[]
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