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
2b92cf29
Commit
2b92cf29
authored
Aug 31, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend prometheus metrics for EE
parent
ec870aca
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
87 additions
and
137 deletions
+87
-137
ee/app/controllers/projects/prometheus/alerts_controller.rb
ee/app/controllers/projects/prometheus/alerts_controller.rb
+1
-1
ee/app/models/ee/prometheus_metric.rb
ee/app/models/ee/prometheus_metric.rb
+10
-0
ee/app/models/prometheus_alert.rb
ee/app/models/prometheus_alert.rb
+17
-1
ee/app/models/prometheus_metric.rb
ee/app/models/prometheus_metric.rb
+0
-39
ee/app/services/projects/prometheus/metrics/base_service.rb
ee/app/services/projects/prometheus/metrics/base_service.rb
+15
-3
ee/db/migrate/20180101160629_create_prometheus_metrics.rb
ee/db/migrate/20180101160629_create_prometheus_metrics.rb
+0
-16
ee/db/migrate/20180831134049_allow_many_prometheus_alerts.rb
ee/db/migrate/20180831134049_allow_many_prometheus_alerts.rb
+17
-0
ee/lib/gitlab/prometheus/metric_group.rb
ee/lib/gitlab/prometheus/metric_group.rb
+23
-0
ee/spec/factories/prometheus_metrics.rb
ee/spec/factories/prometheus_metrics.rb
+0
-11
ee/spec/models/prometheus_metric_spec.rb
ee/spec/models/prometheus_metric_spec.rb
+0
-58
lib/gitlab/prometheus/metric_group.rb
lib/gitlab/prometheus/metric_group.rb
+4
-8
No files found.
ee/app/controllers/projects/prometheus/alerts_controller.rb
View file @
2b92cf29
...
...
@@ -82,7 +82,7 @@ module Projects
end
def
alert
@alert
||=
project
.
prometheus_alerts
.
find_by
(
prometheus_metric:
params
[
:id
])
||
render_404
@alert
||=
project
.
prometheus_alerts
.
find_by
(
prometheus_metric
_id
:
params
[
:id
])
||
render_404
end
def
application
...
...
ee/app/models/ee/prometheus_metric.rb
0 → 100644
View file @
2b92cf29
module
EE
module
PrometheusMetric
extend
ActiveSupport
::
Concern
extend
::
Gitlab
::
Utils
::
Override
prepended
do
has_many
:prometheus_alerts
,
inverse_of: :prometheus_metric
end
end
end
ee/app/models/prometheus_alert.rb
View file @
2b92cf29
...
...
@@ -7,11 +7,14 @@ class PrometheusAlert < ActiveRecord::Base
belongs_to
:environment
,
required:
true
,
validate:
true
,
inverse_of: :prometheus_alerts
belongs_to
:project
,
required:
true
,
validate:
true
,
inverse_of: :prometheus_alerts
belongs_to
:prometheus_metric
,
required:
true
,
validate:
true
,
inverse_of: :prometheus_alert
belongs_to
:prometheus_metric
,
required:
true
,
validate:
true
,
inverse_of: :prometheus_alert
s
after_save
:clear_prometheus_adapter_cache!
after_destroy
:clear_prometheus_adapter_cache!
validate
:require_valid_environment_project!
validate
:require_valid_metric_project!
enum
operator:
[
:lt
,
:eq
,
:gt
]
delegate
:title
,
:query
,
to: :prometheus_metric
...
...
@@ -45,4 +48,17 @@ class PrometheusAlert < ActiveRecord::Base
def
clear_prometheus_adapter_cache!
environment
.
clear_prometheus_reactive_cache!
(
:additional_metrics_environment
)
end
def
require_valid_environment_project!
return
if
project
==
environment
.
project
errors
.
add
(
:environment
,
"invalid project"
)
end
def
require_valid_metric_project!
return
if
prometheus_metric
.
default?
return
if
project
==
prometheus_metric
.
project
errors
.
add
(
:prometheus_metric
,
"invalid project"
)
end
end
ee/app/models/prometheus_metric.rb
deleted
100644 → 0
View file @
ec870aca
class
PrometheusMetric
<
ActiveRecord
::
Base
belongs_to
:project
,
required:
true
,
validate:
true
,
inverse_of: :prometheus_metrics
has_one
:prometheus_alert
,
inverse_of: :prometheus_metric
enum
group:
[
:business
,
:response
,
:system
]
validates
:title
,
presence:
true
validates
:query
,
presence:
true
validates
:group
,
presence:
true
validates
:y_label
,
presence:
true
validates
:unit
,
presence:
true
GROUP_TITLES
=
{
business:
_
(
'Business metrics (Custom)'
),
response:
_
(
'Response metrics (Custom)'
),
system:
_
(
'System metrics (Custom)'
)
}.
freeze
def
group_title
GROUP_TITLES
[
group
.
to_sym
]
end
def
to_query_metric
Gitlab
::
Prometheus
::
Metric
.
new
(
id:
id
,
title:
title
,
required_metrics:
[],
weight:
0
,
y_label:
y_label
,
queries:
build_queries
)
end
private
def
build_queries
[
{
query_range:
query
,
unit:
unit
,
label:
legend
}
]
end
end
ee/app/services/projects/prometheus/metrics/base_service.rb
View file @
2b92cf29
...
...
@@ -2,6 +2,8 @@ module Projects
module
Prometheus
module
Metrics
class
BaseService
include
StrongMemoize
def
initialize
(
metric
,
params
=
{})
@metric
=
metric
@project
=
metric
.
project
...
...
@@ -13,15 +15,25 @@ module Projects
attr_reader
:metric
,
:project
,
:params
def
application
metric
.
prometheus_
alert
.
environment
.
cluster_prometheus_adapter
alert
.
environment
.
cluster_prometheus_adapter
end
def
schedule_alert_update
::
Clusters
::
Applications
::
ScheduleUpdateService
.
new
(
application
,
project
).
execute
return
unless
alert
return
unless
alert
.
environment
::
Clusters
::
Applications
::
ScheduleUpdateService
.
new
(
alert
.
environment
.
cluster_prometheus_adapter
,
project
).
execute
end
def
alert
strong_memoize
(
:alert
)
do
metric
.
prometheus_alerts
.
find_by
(
project:
project
)
end
end
def
has_alert?
metric
.
prometheus_
alert
.
present?
alert
.
present?
end
end
end
...
...
ee/db/migrate/20180101160629_create_prometheus_metrics.rb
deleted
100644 → 0
View file @
ec870aca
class
CreatePrometheusMetrics
<
ActiveRecord
::
Migration
DOWNTIME
=
false
def
change
create_table
:prometheus_metrics
do
|
t
|
t
.
references
:project
,
index:
true
,
foreign_key:
{
on_delete: :cascade
},
null:
false
t
.
string
:title
,
null:
false
t
.
string
:query
,
null:
false
t
.
string
:y_label
t
.
string
:unit
t
.
string
:legend
t
.
integer
:group
,
null:
false
,
index:
true
t
.
timestamps_with_timezone
null:
false
end
end
end
ee/db/migrate/20180831134049_allow_many_prometheus_alerts.rb
0 → 100644
View file @
2b92cf29
class
AllowManyPrometheusAlerts
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:prometheus_alerts
,
[
:project_id
,
:prometheus_metric_id
],
unique:
true
remove_concurrent_index
:prometheus_alerts
,
:prometheus_metric_id
,
unique:
true
end
def
down
add_concurrent_index
:prometheus_alerts
,
:prometheus_metric_id
,
unique:
true
remove_concurrent_index
:prometheus_alerts
,
[
:project_id
,
:prometheus_metric_id
],
unique:
true
end
end
ee/lib/gitlab/prometheus/metric_group.rb
0 → 100644
View file @
2b92cf29
module
EE
module
Gitlab
module
Prometheus
module
MetricGroup
extend
ActiveSupport
::
Concern
extend
::
Gitlab
::
Utils
::
Override
prepended
do
def
self
.
custom_metrics
(
project
)
project
.
prometheus_metrics
.
all
.
group_by
(
&
:group_title
).
map
do
|
name
,
metrics
|
MetricGroup
.
new
(
name:
name
,
priority:
0
,
metrics:
metrics
.
map
(
&
:to_query_metric
))
end
end
override
:for_project
def
self
.
for_project
(
project
)
super
+
custom_metrics
(
project
)
end
end
end
end
end
end
ee/spec/factories/prometheus_metrics.rb
deleted
100644 → 0
View file @
ec870aca
FactoryBot
.
define
do
factory
:prometheus_metric
,
class:
PrometheusMetric
do
title
'title'
query
'avg(metric)'
y_label
'y_label'
unit
'm/s'
group
:business
project
legend
'legend'
end
end
ee/spec/models/prometheus_metric_spec.rb
deleted
100644 → 0
View file @
ec870aca
require
'spec_helper'
describe
PrometheusMetric
do
subject
{
build
(
:prometheus_metric
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:title
)
}
it
{
is_expected
.
to
validate_presence_of
(
:query
)
}
it
{
is_expected
.
to
validate_presence_of
(
:group
)
}
describe
'#group_title'
do
shared_examples
'group_title'
do
|
group
,
title
|
subject
{
build
(
:prometheus_metric
,
group:
group
).
group_title
}
it
"returns text
#{
title
}
for group
#{
group
}
"
do
expect
(
subject
).
to
eq
(
title
)
end
end
it_behaves_like
'group_title'
,
:business
,
'Business metrics (Custom)'
it_behaves_like
'group_title'
,
:response
,
'Response metrics (Custom)'
it_behaves_like
'group_title'
,
:system
,
'System metrics (Custom)'
end
describe
'#to_query_metric'
do
it
'converts to queryable metric object'
do
expect
(
subject
.
to_query_metric
).
to
be_instance_of
(
Gitlab
::
Prometheus
::
Metric
)
end
it
'queryable metric object has title'
do
expect
(
subject
.
to_query_metric
.
title
).
to
eq
(
subject
.
title
)
end
it
'queryable metric object has y_label'
do
expect
(
subject
.
to_query_metric
.
y_label
).
to
eq
(
subject
.
y_label
)
end
it
'queryable metric has no required_metric'
do
expect
(
subject
.
to_query_metric
.
required_metrics
).
to
eq
([])
end
it
'queryable metric has weight 0'
do
expect
(
subject
.
to_query_metric
.
weight
).
to
eq
(
0
)
end
it
'queryable metrics has query description'
do
queries
=
[
{
query_range:
subject
.
query
,
unit:
subject
.
unit
,
label:
subject
.
legend
}
]
expect
(
subject
.
to_query_metric
.
queries
).
to
eq
(
queries
)
end
end
end
lib/gitlab/prometheus/metric_group.rb
View file @
2b92cf29
module
Gitlab
module
Prometheus
class
MetricGroup
prepend
EE
::
Gitlab
::
Prometheus
::
MetricGroup
include
ActiveModel
::
Model
attr_accessor
:name
,
:priority
,
:metrics
...
...
@@ -13,14 +14,9 @@ module Gitlab
end
end
def
self
.
for_project
(
project
)
common_metrics
+
custom_metrics
(
project
)
end
def
self
.
custom_metrics
(
project
)
project
.
prometheus_metrics
.
all
.
group_by
(
&
:group_title
).
map
do
|
name
,
metrics
|
MetricGroup
.
new
(
name:
name
,
priority:
0
,
metrics:
metrics
.
map
(
&
:to_query_metric
))
end
# EE only
def
self
.
for_project
(
_
)
common_metrics
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