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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
80d4c067
Commit
80d4c067
authored
Jan 04, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test checking if prometheus integration is enabled after prometheus is installed
parent
249c9a8c
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
65 additions
and
24 deletions
+65
-24
app/models/clusters/applications/prometheus.rb
app/models/clusters/applications/prometheus.rb
+9
-0
app/models/project_services/prometheus_service.rb
app/models/project_services/prometheus_service.rb
+13
-7
app/views/projects/services/prometheus/_help.html.haml
app/views/projects/services/prometheus/_help.html.haml
+10
-0
lib/gitlab/prometheus/queries/environment_query.rb
lib/gitlab/prometheus/queries/environment_query.rb
+12
-14
lib/gitlab/prometheus/queries/matched_metrics_query.rb
lib/gitlab/prometheus/queries/matched_metrics_query.rb
+1
-1
spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb
...theus/queries/additional_metrics_deployment_query_spec.rb
+1
-1
spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb
spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb
+1
-1
spec/models/clusters/applications/prometheus_spec.rb
spec/models/clusters/applications/prometheus_spec.rb
+18
-0
No files found.
app/models/clusters/applications/prometheus.rb
View file @
80d4c067
...
@@ -10,6 +10,15 @@ module Clusters
...
@@ -10,6 +10,15 @@ module Clusters
default_value_for
:version
,
VERSION
default_value_for
:version
,
VERSION
state_machine
:status
do
after_transition
any
=>
[
:installed
]
do
|
application
|
application
.
cluster
.
projects
.
each
do
|
project
|
# raise "exe"
project
.
prometheus_service
&
.
update
(
active:
true
)
end
end
end
def
chart
def
chart
'stable/prometheus'
'stable/prometheus'
end
end
...
...
app/models/project_services/prometheus_service.rb
View file @
80d4c067
module
Gitlab
PrometheusError
=
Class
.
new
(
StandardError
)
end
class
PrometheusService
<
MonitoringService
class
PrometheusService
<
MonitoringService
include
ReactiveService
include
ReactiveService
...
@@ -8,7 +12,6 @@ class PrometheusService < MonitoringService
...
@@ -8,7 +12,6 @@ class PrometheusService < MonitoringService
# Access to prometheus is directly through the API
# Access to prometheus is directly through the API
prop_accessor
:api_url
prop_accessor
:api_url
boolean_accessor
:manual_configuration
boolean_accessor
:manual_configuration
boolean_accessor
:prometheus_installed
with_options
presence:
true
,
if: :manual_configuration?
do
with_options
presence:
true
,
if: :manual_configuration?
do
validates
:api_url
,
url:
true
validates
:api_url
,
url:
true
...
@@ -18,10 +21,9 @@ class PrometheusService < MonitoringService
...
@@ -18,10 +21,9 @@ class PrometheusService < MonitoringService
after_save
:clear_reactive_cache!
after_save
:clear_reactive_cache!
def
initialize_properties
def
initialize_properties
if
properties
.
nil?
if
properties
.
nil?
self
.
properties
=
{
prometheus_installed:
false
}
self
.
properties
=
{
}
end
end
end
end
...
@@ -54,7 +56,6 @@ class PrometheusService < MonitoringService
...
@@ -54,7 +56,6 @@ class PrometheusService < MonitoringService
}
}
]
]
},
},
{
{
type:
'text'
,
type:
'text'
,
name:
'api_url'
,
name:
'api_url'
,
...
@@ -126,6 +127,10 @@ class PrometheusService < MonitoringService
...
@@ -126,6 +127,10 @@ class PrometheusService < MonitoringService
end
end
end
end
def
prometheus_installed?
cluster_with_prometheus
.
present?
end
private
private
def
cluster_with_prometheus
(
environment_id
=
nil
)
def
cluster_with_prometheus
(
environment_id
=
nil
)
...
@@ -135,7 +140,7 @@ class PrometheusService < MonitoringService
...
@@ -135,7 +140,7 @@ class PrometheusService < MonitoringService
project
.
clusters
.
enabled
.
select
{
|
c
|
c
.
environment_scope
==
'*'
||
c
.
environment_scope
==
''
}
project
.
clusters
.
enabled
.
select
{
|
c
|
c
.
environment_scope
==
'*'
||
c
.
environment_scope
==
''
}
end
end
clusters
.
detect
{
|
cluster
|
cluster
.
application_prometheus
.
installed?
}
clusters
.
detect
{
|
cluster
|
cluster
.
application_prometheus
&
.
installed?
}
end
end
def
rename_data_to_metrics
(
metrics
)
def
rename_data_to_metrics
(
metrics
)
...
@@ -144,7 +149,8 @@ class PrometheusService < MonitoringService
...
@@ -144,7 +149,8 @@ class PrometheusService < MonitoringService
end
end
def
synchronize_service_state!
def
synchronize_service_state!
self
.
active
=
prometheus_installed?
||
manual_configuration?
||
cluster_with_prometheus
.
present?
self
.
active
=
prometheus_installed?
||
self
.
manual_configuration?
self
.
prometheus_installed
=
!
manual_configuration?
&&
cluster_with_prometheus
.
present?
true
end
end
end
end
app/views/projects/services/prometheus/_help.html.haml
0 → 100644
View file @
80d4c067
.row.prepend-top-default.append-bottom-default
%p
-
unless
@service
.
manual_configuration?
-
if
@service
.
prometheus_installed?
=
link_to
'Manage installed Prometheus'
,
project_clusters_path
(
@project
),
class:
'btn btn-cancel'
-
else
=
link_to
'Install Prometheus'
,
project_clusters_path
(
@project
),
class:
'btn btn-cancel'
-
else
To automatically install prometheus disable manual configuration
lib/gitlab/prometheus/queries/environment_query.rb
View file @
80d4c067
...
@@ -2,8 +2,7 @@ module Gitlab
...
@@ -2,8 +2,7 @@ module Gitlab
module
Prometheus
module
Prometheus
module
Queries
module
Queries
class
EnvironmentQuery
<
BaseQuery
class
EnvironmentQuery
<
BaseQuery
def
query
(
environment_id
)
def
query
::
Environment
.
find_by
(
id:
environment_id
).
try
do
|
environment
|
environment_slug
=
environment
.
slug
environment_slug
=
environment
.
slug
timeframe_start
=
8
.
hours
.
ago
.
to_f
timeframe_start
=
8
.
hours
.
ago
.
to_f
timeframe_end
=
Time
.
now
.
to_f
timeframe_end
=
Time
.
now
.
to_f
...
@@ -21,5 +20,4 @@ module Gitlab
...
@@ -21,5 +20,4 @@ module Gitlab
end
end
end
end
end
end
end
end
end
lib/gitlab/prometheus/queries/matched_metrics_query.rb
View file @
80d4c067
...
@@ -4,7 +4,7 @@ module Gitlab
...
@@ -4,7 +4,7 @@ module Gitlab
class
MatchedMetricsQuery
<
BaseQuery
class
MatchedMetricsQuery
<
BaseQuery
MAX_QUERY_ITEMS
=
40
.
freeze
MAX_QUERY_ITEMS
=
40
.
freeze
def
query
def
query
(
_
=
nil
)
groups_data
.
map
do
|
group
,
data
|
groups_data
.
map
do
|
group
,
data
|
{
{
group:
group
.
name
,
group:
group
.
name
,
...
...
spec/lib/gitlab/prometheus/queries/additional_metrics_deployment_query_spec.rb
View file @
80d4c067
...
@@ -7,7 +7,7 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery do
...
@@ -7,7 +7,7 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery do
include_examples
'additional metrics query'
do
include_examples
'additional metrics query'
do
let
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
)
}
let
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
)
}
let
(
:query_params
)
{
[
deployment
.
id
]
}
let
(
:query_params
)
{
[
environment
.
id
,
deployment
.
id
]
}
it
'queries using specific time'
do
it
'queries using specific time'
do
expect
(
client
).
to
receive
(
:query_range
).
with
(
anything
,
expect
(
client
).
to
receive
(
:query_range
).
with
(
anything
,
...
...
spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb
View file @
80d4c067
...
@@ -31,7 +31,7 @@ describe Gitlab::Prometheus::Queries::DeploymentQuery do
...
@@ -31,7 +31,7 @@ describe Gitlab::Prometheus::Queries::DeploymentQuery do
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100'
,
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100'
,
time:
stop_time
)
time:
stop_time
)
expect
(
subject
.
query
(
deployment
.
id
)).
to
eq
(
memory_values:
nil
,
memory_before:
nil
,
memory_after:
nil
,
expect
(
subject
.
query
(
environment
.
id
,
deployment
.
id
)).
to
eq
(
memory_values:
nil
,
memory_before:
nil
,
memory_after:
nil
,
cpu_values:
nil
,
cpu_before:
nil
,
cpu_after:
nil
)
cpu_values:
nil
,
cpu_before:
nil
,
cpu_after:
nil
)
end
end
end
end
spec/models/clusters/applications/prometheus_spec.rb
View file @
80d4c067
...
@@ -6,6 +6,24 @@ describe Clusters::Applications::Prometheus do
...
@@ -6,6 +6,24 @@ describe Clusters::Applications::Prometheus do
include_examples
'cluster application specs'
,
described_class
include_examples
'cluster application specs'
,
described_class
describe
'transition to installed'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:cluster
)
{
create
(
:cluster
,
projects:
[
project
])
}
let
(
:prometheus_service
)
{
double
(
'prometheus_service'
)
}
subject
{
create
(
:clusters_applications_prometheus
,
:installing
,
cluster:
cluster
)
}
before
do
allow
(
project
).
to
receive
(
:prometheus_service
).
and_return
prometheus_service
end
it
'ensures Prometheus service is activated'
do
expect
(
prometheus_service
).
to
receive
(
:update
).
with
(
active:
true
)
subject
.
make_installed
end
end
describe
"#chart_values_file"
do
describe
"#chart_values_file"
do
subject
{
create
(
:clusters_applications_prometheus
).
chart_values_file
}
subject
{
create
(
:clusters_applications_prometheus
).
chart_values_file
}
...
...
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