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
9ccda901
Commit
9ccda901
authored
7 years ago
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Prometheus client tests
parent
aaeda829
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
spec/lib/gitlab/prometheus_client_spec.rb
spec/lib/gitlab/prometheus_client_spec.rb
+30
-0
spec/support/prometheus_helpers.rb
spec/support/prometheus_helpers.rb
+46
-0
No files found.
spec/lib/gitlab/prometheus_client_spec.rb
View file @
9ccda901
...
...
@@ -119,6 +119,36 @@ describe Gitlab::PrometheusClient, lib: true do
end
end
describe
'#series'
do
let
(
:query_url
)
{
prometheus_series_url
(
'series_name'
,
'other_service'
)
}
around
do
|
example
|
Timecop
.
freeze
{
example
.
run
}
end
it
'calls endpoint and returns list of series'
do
req_stub
=
stub_prometheus_request
(
query_url
,
body:
prometheus_series
(
'series_name'
))
expected
=
prometheus_series
(
'series_name'
).
deep_stringify_keys
[
'data'
]
expect
(
subject
.
series
(
'series_name'
,
'other_service'
)).
to
eq
(
expected
)
expect
(
req_stub
).
to
have_been_requested
end
end
describe
'#label_values'
do
let
(
:query_url
)
{
prometheus_label_values_url
(
'__name__'
)
}
it
'calls endpoint and returns label values'
do
req_stub
=
stub_prometheus_request
(
query_url
,
body:
prometheus_label_values
)
expected
=
prometheus_label_values
.
deep_stringify_keys
[
'data'
]
expect
(
subject
.
label_values
(
'__name__'
)).
to
eq
(
expected
)
expect
(
req_stub
).
to
have_been_requested
end
end
describe
'#query_range'
do
let
(
:prometheus_query
)
{
prometheus_memory_query
(
'env-slug'
)
}
let
(
:query_url
)
{
prometheus_query_range_url
(
prometheus_query
)
}
...
...
This diff is collapsed.
Click to expand it.
spec/support/prometheus_helpers.rb
View file @
9ccda901
...
...
@@ -36,6 +36,19 @@ module PrometheusHelpers
"https://prometheus.example.com/api/v1/query_range?
#{
query
}
"
end
def
prometheus_label_values_url
(
name
)
"https://prometheus.example.com/api/v1/label/
#{
name
}
/values"
end
def
prometheus_series_url
(
*
matches
,
start:
8
.
hours
.
ago
,
stop:
Time
.
now
)
query
=
{
match:
matches
,
start:
start
.
to_f
,
end:
stop
.
to_f
}.
to_query
"https://prometheus.example.com/api/v1/series?
#{
query
}
"
end
def
stub_prometheus_request
(
url
,
body:
{},
status:
200
)
WebMock
.
stub_request
(
:get
,
url
)
.
to_return
({
...
...
@@ -140,4 +153,37 @@ module PrometheusHelpers
}
}
end
def
prometheus_label_values
{
'status'
:
'success'
,
'data'
:
%w(job_adds job_controller_rate_limiter_use job_depth job_queue_latency job_work_duration_sum up)
}
end
def
prometheus_series
(
name
)
{
'status'
:
'success'
,
'data'
:
[
{
'__name__'
:
name
,
'container_name'
:
'gitlab'
,
'environment'
:
'mattermost'
,
'id'
:
'/docker/9953982f95cf5010dfc59d7864564d5f188aaecddeda343699783009f89db667'
,
'image'
:
'gitlab/gitlab-ce:8.15.4-ce.1'
,
'instance'
:
'minikube'
,
'job'
:
'kubernetes-nodes'
,
'name'
:
'k8s_gitlab.e6611886_mattermost-4210310111-77z8r_gitlab_2298ae6b-da24-11e6-baee-8e7f67d0eb3a_43536cb6'
,
'namespace'
:
'gitlab'
,
'pod_name'
:
'mattermost-4210310111-77z8r'
},
{
'__name__'
:
name
,
'id'
:
'/docker'
,
'instance'
:
'minikube'
,
'job'
:
'kubernetes-nodes'
}
]
}
end
end
This diff is collapsed.
Click to expand it.
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