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
eff03da6
Commit
eff03da6
authored
Feb 14, 2020
by
Mikolaj Wawrzyniak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid N+1 queries in PromethusService#available?
parent
3da7198b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
app/models/project_services/prometheus_service.rb
app/models/project_services/prometheus_service.rb
+3
-1
spec/models/project_services/prometheus_service_spec.rb
spec/models/project_services/prometheus_service_spec.rb
+9
-0
No files found.
app/models/project_services/prometheus_service.rb
View file @
eff03da6
...
...
@@ -88,7 +88,9 @@ class PrometheusService < MonitoringService
return
false
if
template?
return
false
unless
project
project
.
all_clusters
.
enabled
.
any?
{
|
cluster
|
cluster
.
application_prometheus_available?
}
project
.
all_clusters
.
enabled
.
eager_load
(
:application_prometheus
).
any?
do
|
cluster
|
cluster
.
application_prometheus
&
.
available?
end
end
def
allow_local_api_url?
...
...
spec/models/project_services/prometheus_service_spec.rb
View file @
eff03da6
...
...
@@ -176,6 +176,15 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
it
'returns true'
do
expect
(
service
.
prometheus_available?
).
to
be
(
true
)
end
it
'avoids N+1 queries'
do
service
5
.
times
do
|
i
|
other_cluster
=
create
(
:cluster_for_group
,
:with_installed_helm
,
groups:
[
group
],
environment_scope:
i
)
create
(
:clusters_applications_prometheus
,
:installing
,
cluster:
other_cluster
)
end
expect
{
service
.
prometheus_available?
}.
not_to
exceed_query_limit
(
1
)
end
end
context
'cluster belongs to gitlab instance'
do
...
...
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