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
969b8124
Commit
969b8124
authored
Jun 06, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add schema matcher for non response objects + use schema to test additional metrics compliance
parent
ccf89acc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
71 deletions
+88
-71
spec/fixtures/api/schemas/prometheus/additional_metrics_query_result.json
...i/schemas/prometheus/additional_metrics_query_result.json
+58
-0
spec/support/api/schema_matcher.rb
spec/support/api/schema_matcher.rb
+11
-3
spec/support/prometheus/additional_metrics_shared_examples.rb
.../support/prometheus/additional_metrics_shared_examples.rb
+18
-67
spec/support/prometheus/metric_builders.rb
spec/support/prometheus/metric_builders.rb
+1
-1
No files found.
spec/fixtures/api/schemas/prometheus/additional_metrics_query_result.json
0 → 100644
View file @
969b8124
{
"items"
:
{
"properties"
:
{
"group"
:
{
"type"
:
"string"
},
"metrics"
:
{
"items"
:
{
"properties"
:
{
"queries"
:
{
"items"
:
{
"properties"
:
{
"query_range"
:
{
"type"
:
"string"
},
"query"
:
{
"type"
:
"string"
},
"result"
:
{
"type"
:
"any"
}
},
"type"
:
"object"
},
"type"
:
"array"
},
"title"
:
{
"type"
:
"string"
},
"weight"
:
{
"type"
:
"integer"
},
"y_label"
:
{
"type"
:
"string"
}
},
"type"
:
"object"
},
"required"
:
[
"metrics"
,
"title"
,
"weight"
],
"type"
:
"array"
},
"priority"
:
{
"type"
:
"integer"
}
},
"type"
:
"object"
},
"required"
:
[
"group"
,
"priority"
,
"metrics"
],
"type"
:
"array"
}
\ No newline at end of file
spec/support/api/schema_matcher.rb
View file @
969b8124
def
schema_path
(
schema
)
schema_directory
=
"
#{
Dir
.
pwd
}
/spec/fixtures/api/schemas"
"
#{
schema_directory
}
/
#{
schema
}
.json"
end
RSpec
::
Matchers
.
define
:match_response_schema
do
|
schema
,
**
options
|
RSpec
::
Matchers
.
define
:match_response_schema
do
|
schema
,
**
options
|
match
do
|
response
|
match
do
|
response
|
schema_directory
=
"
#{
Dir
.
pwd
}
/spec/fixtures/api/schemas"
JSON
::
Validator
.
validate!
(
schema_path
(
schema
),
response
.
body
,
options
)
schema_path
=
"
#{
schema_directory
}
/
#{
schema
}
.json"
end
end
JSON
::
Validator
.
validate!
(
schema_path
,
response
.
body
,
options
)
RSpec
::
Matchers
.
define
:match_schema
do
|
schema
,
**
options
|
match
do
|
data
|
JSON
::
Validator
.
validate!
(
schema_path
(
schema
),
data
,
options
)
end
end
end
end
spec/support/prometheus/additional_metrics_shared_examples.rb
View file @
969b8124
...
@@ -34,7 +34,7 @@ RSpec.shared_examples 'additional metrics query' do
...
@@ -34,7 +34,7 @@ RSpec.shared_examples 'additional metrics query' do
priority:
1
,
priority:
1
,
metrics:
[
metrics:
[
{
{
title:
'title'
,
weight:
nil
,
y_label:
'Values'
,
queries:
[
title:
'title'
,
weight:
1
,
y_label:
'Values'
,
queries:
[
{
query_range:
'query_range_a'
,
result:
query_range_result
},
{
query_range:
'query_range_a'
,
result:
query_range_result
},
{
query_range:
'query_range_b'
,
label:
'label'
,
unit:
'unit'
,
result:
query_range_result
}
{
query_range:
'query_range_b'
,
label:
'label'
,
unit:
'unit'
,
result:
query_range_result
}
]
]
...
@@ -43,6 +43,7 @@ RSpec.shared_examples 'additional metrics query' do
...
@@ -43,6 +43,7 @@ RSpec.shared_examples 'additional metrics query' do
}
}
]
]
expect
(
query_result
).
to
match_schema
(
'prometheus/additional_metrics_query_result'
)
expect
(
query_result
).
to
eq
(
expected
)
expect
(
query_result
).
to
eq
(
expected
)
end
end
end
end
...
@@ -66,53 +67,16 @@ RSpec.shared_examples 'additional metrics query' do
...
@@ -66,53 +67,16 @@ RSpec.shared_examples 'additional metrics query' do
end
end
it
'return group data both queries'
do
it
'return group data both queries'
do
expected
=
[
queries_with_result_a
=
{
queries:
[{
query_range:
'query_range_a'
,
result:
query_range_result
}]
}
{
queries_with_result_b
=
{
queries:
[{
query_range:
'query_range_b'
,
result:
query_range_result
}]
}
group:
'group_a'
,
priority:
1
,
metrics:
[
{
title:
'title'
,
weight:
nil
,
y_label:
'Values'
,
queries:
[
{
query_range:
'query_range_a'
,
result:
[
{
metric:
{},
values:
[[
1488758662.506
,
'0.00002996364761904785'
],
[
1488758722.506
,
'0.00003090239047619091'
]]
}
]
}
]
}
]
},
{
group:
'group_b'
,
priority:
1
,
metrics:
[
{
title:
'title_b'
,
weight:
nil
,
y_label:
'Values'
,
queries:
[
{
query_range:
'query_range_b'
,
result:
[
{
metric:
{},
values:
[[
1488758662.506
,
'0.00002996364761904785'
],
[
1488758722.506
,
'0.00003090239047619091'
]]
}
]
}
]
}
]
}
]
expect
(
query_result
).
to
eq
(
expected
)
expect
(
query_result
).
to
match_schema
(
'prometheus/additional_metrics_query_result'
)
expect
(
query_result
.
count
).
to
eq
(
2
)
expect
(
query_result
).
to
all
(
satisfy
{
|
r
|
r
[
:metrics
].
count
==
1
})
expect
(
query_result
[
0
][
:metrics
].
first
).
to
include
(
queries_with_result_a
)
expect
(
query_result
[
1
][
:metrics
].
first
).
to
include
(
queries_with_result_b
)
end
end
end
end
...
@@ -123,27 +87,14 @@ RSpec.shared_examples 'additional metrics query' do
...
@@ -123,27 +87,14 @@ RSpec.shared_examples 'additional metrics query' do
end
end
it
'return group data only for query with results'
do
it
'return group data only for query with results'
do
expected
=
[
queries_with_result
=
{
queries:
[{
query_range:
'query_range_a'
,
result:
query_range_result
}]
}
{
group:
'group_a'
,
priority:
1
,
metrics:
[
{
title:
'title'
,
weight:
nil
,
y_label:
'Values'
,
queries:
[
{
query_range:
'query_range_a'
,
result:
query_range_result
}
]
}
]
}
]
expect
(
query_result
).
to
eq
(
expected
)
expect
(
query_result
).
to
match_schema
(
'prometheus/additional_metrics_query_result'
)
expect
(
query_result
.
count
).
to
eq
(
1
)
expect
(
query_result
).
to
all
(
satisfy
{
|
r
|
r
[
:metrics
].
count
==
1
})
expect
(
query_result
.
first
[
:metrics
].
first
).
to
include
(
queries_with_result
)
end
end
end
end
end
end
...
...
spec/support/prometheus/metric_builders.rb
View file @
969b8124
...
@@ -9,7 +9,7 @@ module Prometheus
...
@@ -9,7 +9,7 @@ module Prometheus
end
end
def
simple_metric
(
title:
'title'
,
required_metrics:
[],
queries:
[
simple_query
])
def
simple_metric
(
title:
'title'
,
required_metrics:
[],
queries:
[
simple_query
])
Gitlab
::
Prometheus
::
Metric
.
new
(
title
,
required_metrics
,
nil
,
nil
,
queries
)
Gitlab
::
Prometheus
::
Metric
.
new
(
title
,
required_metrics
,
1
,
nil
,
queries
)
end
end
def
simple_metrics
(
added_metric_name:
'metric_a'
)
def
simple_metrics
(
added_metric_name:
'metric_a'
)
...
...
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