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
Hide 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
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
'stable/prometheus'
end
...
...
app/models/project_services/prometheus_service.rb
View file @
80d4c067
module
Gitlab
PrometheusError
=
Class
.
new
(
StandardError
)
end
class
PrometheusService
<
MonitoringService
include
ReactiveService
...
...
@@ -8,7 +12,6 @@ class PrometheusService < MonitoringService
# Access to prometheus is directly through the API
prop_accessor
:api_url
boolean_accessor
:manual_configuration
boolean_accessor
:prometheus_installed
with_options
presence:
true
,
if: :manual_configuration?
do
validates
:api_url
,
url:
true
...
...
@@ -18,10 +21,9 @@ class PrometheusService < MonitoringService
after_save
:clear_reactive_cache!
def
initialize_properties
if
properties
.
nil?
self
.
properties
=
{
prometheus_installed:
false
}
self
.
properties
=
{
}
end
end
...
...
@@ -54,7 +56,6 @@ class PrometheusService < MonitoringService
}
]
},
{
type:
'text'
,
name:
'api_url'
,
...
...
@@ -126,6 +127,10 @@ class PrometheusService < MonitoringService
end
end
def
prometheus_installed?
cluster_with_prometheus
.
present?
end
private
def
cluster_with_prometheus
(
environment_id
=
nil
)
...
...
@@ -135,7 +140,7 @@ class PrometheusService < MonitoringService
project
.
clusters
.
enabled
.
select
{
|
c
|
c
.
environment_scope
==
'*'
||
c
.
environment_scope
==
''
}
end
clusters
.
detect
{
|
cluster
|
cluster
.
application_prometheus
.
installed?
}
clusters
.
detect
{
|
cluster
|
cluster
.
application_prometheus
&
.
installed?
}
end
def
rename_data_to_metrics
(
metrics
)
...
...
@@ -144,7 +149,8 @@ class PrometheusService < MonitoringService
end
def
synchronize_service_state!
self
.
active
=
prometheus_installed?
||
manual_configuration?
||
cluster_with_prometheus
.
present?
self
.
prometheus_installed
=
!
manual_configuration?
&&
cluster_with_prometheus
.
present?
self
.
active
=
prometheus_installed?
||
self
.
manual_configuration?
true
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,22 +2,20 @@ module Gitlab
module
Prometheus
module
Queries
class
EnvironmentQuery
<
BaseQuery
def
query
(
environment_id
)
::
Environment
.
find_by
(
id:
environment_id
).
try
do
|
environment
|
environment_slug
=
environment
.
slug
timeframe_start
=
8
.
hours
.
ago
.
to_f
timeframe_end
=
Time
.
now
.
to_f
def
query
environment_slug
=
environment
.
slug
timeframe_start
=
8
.
hours
.
ago
.
to_f
timeframe_end
=
Time
.
now
.
to_f
memory_query
=
raw_memory_usage_query
(
environment_slug
)
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
memory_query
=
raw_memory_usage_query
(
environment_slug
)
cpu_query
=
raw_cpu_usage_query
(
environment_slug
)
{
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_current:
client_query
(
memory_query
,
time:
timeframe_end
),
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_current:
client_query
(
cpu_query
,
time:
timeframe_end
)
}
end
{
memory_values:
client_query_range
(
memory_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
memory_current:
client_query
(
memory_query
,
time:
timeframe_end
),
cpu_values:
client_query_range
(
cpu_query
,
start:
timeframe_start
,
stop:
timeframe_end
),
cpu_current:
client_query
(
cpu_query
,
time:
timeframe_end
)
}
end
end
end
...
...
lib/gitlab/prometheus/queries/matched_metrics_query.rb
View file @
80d4c067
...
...
@@ -4,7 +4,7 @@ module Gitlab
class
MatchedMetricsQuery
<
BaseQuery
MAX_QUERY_ITEMS
=
40
.
freeze
def
query
def
query
(
_
=
nil
)
groups_data
.
map
do
|
group
,
data
|
{
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
include_examples
'additional metrics query'
do
let
(
:deployment
)
{
create
(
:deployment
,
environment:
environment
)
}
let
(
:query_params
)
{
[
deployment
.
id
]
}
let
(
:query_params
)
{
[
environment
.
id
,
deployment
.
id
]
}
it
'queries using specific time'
do
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
expect
(
client
).
to
receive
(
:query
).
with
(
'avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100'
,
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
)
end
end
spec/models/clusters/applications/prometheus_spec.rb
View file @
80d4c067
...
...
@@ -6,6 +6,24 @@ describe Clusters::Applications::Prometheus do
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
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