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
277f7fef
Commit
277f7fef
authored
Feb 07, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make prometheus service querying approach much nicer wrt to arity and default function params
parent
eac8ad6a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
4 deletions
+30
-4
app/models/project_services/prometheus_service.rb
app/models/project_services/prometheus_service.rb
+4
-3
lib/gitlab/prometheus/queries/matched_metrics_query.rb
lib/gitlab/prometheus/queries/matched_metrics_query.rb
+1
-1
spec/models/project_services/prometheus_service_spec.rb
spec/models/project_services/prometheus_service_spec.rb
+19
-0
spec/support/reactive_caching_helpers.rb
spec/support/reactive_caching_helpers.rb
+6
-0
No files found.
app/models/project_services/prometheus_service.rb
View file @
277f7fef
...
...
@@ -91,16 +91,17 @@ class PrometheusService < MonitoringService
end
def
matched_metrics
with_reactive_cache
(
Gitlab
::
Prometheus
::
Queries
::
MatchedMetricsQuery
.
name
,
nil
,
&
:itself
)
with_reactive_cache
(
Gitlab
::
Prometheus
::
Queries
::
MatchedMetricsQuery
.
name
,
&
:itself
)
end
# Cache metrics for specific environment
def
calculate_reactive_cache
(
query_class_name
,
environment_id
,
*
args
)
def
calculate_reactive_cache
(
query_class_name
,
*
args
)
return
unless
active?
&&
project
&&
!
project
.
pending_delete?
environment_id
=
args
.
first
client
=
client
(
environment_id
)
data
=
Kernel
.
const_get
(
query_class_name
).
new
(
client
).
query
(
environment_id
,
*
args
)
data
=
Kernel
.
const_get
(
query_class_name
).
new
(
client
).
query
(
*
args
)
{
success:
true
,
data:
data
,
...
...
lib/gitlab/prometheus/queries/matched_metrics_query.rb
View file @
277f7fef
...
...
@@ -4,7 +4,7 @@ module Gitlab
class
MatchedMetricsQuery
<
BaseQuery
MAX_QUERY_ITEMS
=
40
.
freeze
def
query
(
_
=
nil
)
def
query
groups_data
.
map
do
|
group
,
data
|
{
group:
group
.
name
,
...
...
spec/models/project_services/prometheus_service_spec.rb
View file @
277f7fef
...
...
@@ -75,6 +75,25 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
end
end
describe
'#matched_metrics'
do
let
(
:matched_metrics_query
)
{
Gitlab
::
Prometheus
::
Queries
::
MatchedMetricsQuery
}
let
(
:client
)
{
double
(
:client
,
label_values:
nil
)
}
context
'with valid data'
do
subject
{
service
.
matched_metrics
}
before
do
allow
(
service
).
to
receive
(
:client
).
and_return
(
client
)
synchronous_reactive_cache
(
service
)
end
it
'returns reactive data'
do
expect
(
subject
[
:success
]).
to
be_truthy
expect
(
subject
[
:data
]).
to
eq
([])
end
end
end
describe
'#deployment_metrics'
do
let
(
:deployment
)
{
build_stubbed
(
:deployment
)
}
let
(
:deployment_query
)
{
Gitlab
::
Prometheus
::
Queries
::
DeploymentQuery
}
...
...
spec/support/reactive_caching_helpers.rb
View file @
277f7fef
...
...
@@ -13,6 +13,12 @@ module ReactiveCachingHelpers
write_reactive_cache
(
subject
,
data
,
*
qualifiers
)
if
data
end
def
synchronous_reactive_cache
(
subject
)
allow
(
service
).
to
receive
(
:with_reactive_cache
)
do
|*
args
,
&
block
|
block
.
call
(
service
.
calculate_reactive_cache
(
*
args
))
end
end
def
read_reactive_cache
(
subject
,
*
qualifiers
)
Rails
.
cache
.
read
(
reactive_cache_key
(
subject
,
*
qualifiers
))
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