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
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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
141 additions
and
30 deletions
+141
-30
matched_metrics_query.rb
lib/gitlab/prometheus/queries/matched_metrics_query.rb
+3
-4
settings.rb.orig
spec/db/production/settings.rb.orig
+16
-0
matched_metrics_query_spec.rb
...b/gitlab/prometheus/queries/matched_metrics_query_spec.rb
+89
-26
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
])
allow
(
client
).
to
receive
(
:label_values
).
and_return
(
metric_names
)
end
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
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_without_environment
)
end
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
context
'with one group where only one metric is found'
do
before
do
before
do
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
])
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
])
allow
(
client
).
to
receive
(
:label_values
).
and_return
(
'metric_a'
)
end
allow
(
client
).
to
receive
(
:label_values
).
and_return
([
'metrica'
,
'metricb'
])
context
'both metrics in the group pass requirements'
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
xx
)
before
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_with_environment
)
end
end
it
"something something"
do
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
context
'no metrics 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:
'name'
,
priority:
1
,
active_metrics:
0
,
metrics_missing_requirements:
1
}])
end
end
end
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
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