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
5ceec83a
Commit
5ceec83a
authored
Mar 05, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemente Prometheus:AdapterService
parent
273e4142
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
23 deletions
+77
-23
metrics_controller.rb
app/controllers/projects/prometheus/metrics_controller.rb
+4
-2
environment.rb
app/models/environment.rb
+4
-2
adapter_service.rb
app/services/prometheus/adapter_service.rb
+29
-19
adapter_service_spec.rb
spec/services/prometheus/adapter_service_spec.rb
+40
-0
No files found.
app/controllers/projects/prometheus/metrics_controller.rb
View file @
5ceec83a
module
Projects
module
Prometheus
class
MetricsController
<
Projects
::
ApplicationController
include
PrometheusAdapterLocator
before_action
:authorize_admin_project!
before_action
:require_prometheus_metrics!
...
...
@@ -22,6 +20,10 @@ module Projects
private
def
prometheus_adapter
@prometheus_adapter
||=
Prometheus
::
AdapterService
.
new
(
project
).
prometheus_adapter
end
def
require_prometheus_metrics!
render_404
unless
prometheus_adapter
.
can_query?
end
...
...
app/models/environment.rb
View file @
5ceec83a
class
Environment
<
ActiveRecord
::
Base
include
PrometheusAdapterLocator
# Used to generate random suffixes for the slug
LETTERS
=
'a'
..
'z'
NUMBERS
=
'0'
..
'9'
...
...
@@ -159,6 +157,10 @@ class Environment < ActiveRecord::Base
prometheus_adapter
.
query
(
:additional_metrics_environment
,
self
)
if
has_metrics?
end
def
prometheus_adapter
@prometheus_adapter
||=
Prometheus
::
AdapterService
.
new
(
project
,
deployment_platform
).
prometheus_adapter
end
def
slug
super
.
presence
||
generate_slug
end
...
...
app/
models/concerns/prometheus_adapter_locator
.rb
→
app/
services/prometheus/adapter_service
.rb
View file @
5ceec83a
module
Prometheus
AdapterLocator
def
deployment_platform
project
.
deployment_platform
end
module
Prometheus
class
AdapterService
def
initialize
(
project
,
deployment_platform
=
nil
)
@project
=
project
def
prometheus_adapter
@prometheus_adapter
||=
if
service_prometheus_adapter
.
can_query?
service_prometheus_adapter
else
cluster_prometheus_adapter
end
end
@deployment_platform
=
if
deployment_platform
deployment_platform
else
project
.
deployment_platform
end
end
def
service_prometheus_adapter
project
.
find_or_initialize_service
(
'prometheus'
)
end
attr_reader
:deployment_platform
,
:project
def
prometheus_adapter
@prometheus_adapter
||=
if
service_prometheus_adapter
.
can_query?
service_prometheus_adapter
else
cluster_prometheus_adapter
end
end
def
service_prometheus_adapter
project
.
find_or_initialize_service
(
'prometheus'
)
end
def
cluster_prometheus_adapter
return
unless
deployment_platform
.
respond_to?
(
:cluster
)
def
cluster_prometheus_adapter
return
unless
deployment_platform
.
respond_to?
(
:cluster
)
cluster
=
deployment_platform
.
cluster
return
unless
cluster
.
application_prometheus
&
.
installed?
cluster
=
deployment_platform
.
cluster
return
unless
cluster
.
application_prometheus
&
.
installed?
cluster
.
application_prometheus
cluster
.
application_prometheus
end
end
end
spec/services/prometheus/adapter_service_spec.rb
0 → 100644
View file @
5ceec83a
require
'spec_helper'
describe
Prometheus
::
AdapterService
do
let
(
:project
)
{
create
(
:project
)
}
subject
{
described_class
.
new
(
project
)
}
describe
'#prometheus_adapter'
do
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
environment_scope:
'*'
,
projects:
[
project
])
}
context
'prometheus service can execute queries'
do
let
(
:prometheus_service
)
{
double
(
:prometheus_service
,
can_query?:
true
)
}
before
do
allow
(
project
).
to
receive
(
:find_or_initialize_service
).
with
(
'prometheus'
).
and_return
prometheus_service
end
it
'return prometheus service as prometheus adapter'
do
expect
(
subject
.
prometheus_adapter
).
to
eq
(
prometheus_service
)
end
end
context
"prometheus service can't execute queries"
do
let
(
:prometheus_service
)
{
double
(
:prometheus_service
,
can_query?:
false
)
}
context
'with cluster with prometheus installed'
do
let!
(
:prometheus
)
{
create
(
:clusters_applications_prometheus
,
:installed
,
cluster:
cluster
)
}
it
'returns application handling all environments'
do
expect
(
subject
.
prometheus_adapter
).
to
eq
(
prometheus
)
end
end
context
'with cluster without prometheus installed'
do
it
'returns nil'
do
expect
(
subject
.
prometheus_adapter
).
to
be_nil
end
end
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