Commit c9097f27 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'move-alerting-to-core-move-prometheus-metric' into 'master'

Move PrometheusMetric out of EE

Closes #199995

See merge request gitlab-org/gitlab!23864
parents a962650f 5d802ade
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
class PrometheusMetric < ApplicationRecord class PrometheusMetric < ApplicationRecord
belongs_to :project, validate: true, inverse_of: :prometheus_metrics belongs_to :project, validate: true, inverse_of: :prometheus_metrics
has_many :prometheus_alerts, inverse_of: :prometheus_metric
enum group: PrometheusMetricEnums.groups enum group: PrometheusMetricEnums.groups
...@@ -73,5 +74,3 @@ class PrometheusMetric < ApplicationRecord ...@@ -73,5 +74,3 @@ class PrometheusMetric < ApplicationRecord
PrometheusMetricEnums.group_details.fetch(group.to_sym) PrometheusMetricEnums.group_details.fetch(group.to_sym)
end end
end end
PrometheusMetric.prepend_if_ee('EE::PrometheusMetric')
...@@ -9,7 +9,8 @@ module PrometheusMetricEnums ...@@ -9,7 +9,8 @@ module PrometheusMetricEnums
aws_elb: -3, aws_elb: -3,
nginx: -4, nginx: -4,
kubernetes: -5, kubernetes: -5,
nginx_ingress: -6 nginx_ingress: -6,
cluster_health: -100
}.merge(custom_groups).freeze }.merge(custom_groups).freeze
end end
...@@ -54,6 +55,11 @@ module PrometheusMetricEnums ...@@ -54,6 +55,11 @@ module PrometheusMetricEnums
group_title: _('System metrics (Kubernetes)'), group_title: _('System metrics (Kubernetes)'),
required_metrics: %w(container_memory_usage_bytes container_cpu_usage_seconds_total), required_metrics: %w(container_memory_usage_bytes container_cpu_usage_seconds_total),
priority: 5 priority: 5
}.freeze,
cluster_health: {
group_title: _('Cluster Health'),
required_metrics: %w(container_memory_usage_bytes container_cpu_usage_seconds_total),
priority: 10
}.freeze }.freeze
}.merge(custom_group_details).freeze }.merge(custom_group_details).freeze
end end
...@@ -76,5 +82,3 @@ module PrometheusMetricEnums ...@@ -76,5 +82,3 @@ module PrometheusMetricEnums
}.freeze }.freeze
end end
end end
PrometheusMetricEnums.prepend_if_ee('EE::PrometheusMetricEnums')
# frozen_string_literal: true
module EE
module PrometheusMetric
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
prepended do
has_many :prometheus_alerts, inverse_of: :prometheus_metric
end
end
end
# frozen_string_literal: true
module EE
module PrometheusMetricEnums
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :groups
def groups
super.merge(
# Start at -100 to avoid collisions with CE values
# built-in groups
cluster_health: -100
)
end
override :group_details
def group_details
super.merge(
# keys can collide with CE values! please ensure you are not redefining a key that already exists in app/models/prometheus_metric_enums.rb#group_details
# built-in groups
cluster_health: {
group_title: _('Cluster Health'),
required_metrics: %w(container_memory_usage_bytes container_cpu_usage_seconds_total),
priority: 10
}
)
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module DatabaseImporters
module CommonMetrics
module PrometheusMetricEnums
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :groups
def groups
super.merge(
# Start at 100 to avoid collisions with CE values
cluster_health: -100
)
end
override :group_titles
def group_titles
super.merge(
# keys can collide with CE values! please ensure you are not redefining a key that already exists
cluster_health: _('Cluster Health')
)
end
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe PrometheusMetric do
subject { build(:prometheus_metric) }
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', :cluster_health, 'Cluster Health'
end
describe '#priority' do
using RSpec::Parameterized::TableSyntax
where(:group, :priority) do
:cluster_health | 10
end
with_them do
before do
subject.group = group
end
it { expect(subject.priority).to eq(priority) }
end
end
describe '#required_metrics' do
using RSpec::Parameterized::TableSyntax
where(:group, :required_metrics) do
:cluster_health | %w(container_memory_usage_bytes container_cpu_usage_seconds_total)
end
with_them do
before do
subject.group = group
end
it { expect(subject.required_metrics).to eq(required_metrics) }
end
end
end
...@@ -6,5 +6,3 @@ module Gitlab ...@@ -6,5 +6,3 @@ module Gitlab
end end
end end
end end
Gitlab::DatabaseImporters::CommonMetrics.prepend_if_ee('EE::Gitlab::DatabaseImporters::CommonMetrics')
...@@ -17,7 +17,9 @@ module Gitlab ...@@ -17,7 +17,9 @@ module Gitlab
# custom groups # custom groups
business: 0, business: 0,
response: 1, response: 1,
system: 2 system: 2,
cluster_health: -100
} }
end end
...@@ -31,12 +33,11 @@ module Gitlab ...@@ -31,12 +33,11 @@ module Gitlab
ha_proxy: _('Response metrics (HA Proxy)'), ha_proxy: _('Response metrics (HA Proxy)'),
aws_elb: _('Response metrics (AWS ELB)'), aws_elb: _('Response metrics (AWS ELB)'),
nginx: _('Response metrics (NGINX)'), nginx: _('Response metrics (NGINX)'),
kubernetes: _('System metrics (Kubernetes)') kubernetes: _('System metrics (Kubernetes)'),
cluster_health: _('Cluster Health')
} }
end end
end end
end end
end end
end end
::Gitlab::DatabaseImporters::CommonMetrics::PrometheusMetricEnums.prepend_if_ee('EE::Gitlab::DatabaseImporters::CommonMetrics::PrometheusMetricEnums')
...@@ -67,6 +67,7 @@ describe PrometheusMetric do ...@@ -67,6 +67,7 @@ describe PrometheusMetric do
it_behaves_like 'group_title', :business, 'Business metrics (Custom)' it_behaves_like 'group_title', :business, 'Business metrics (Custom)'
it_behaves_like 'group_title', :response, 'Response metrics (Custom)' it_behaves_like 'group_title', :response, 'Response metrics (Custom)'
it_behaves_like 'group_title', :system, 'System metrics (Custom)' it_behaves_like 'group_title', :system, 'System metrics (Custom)'
it_behaves_like 'group_title', :cluster_health, 'Cluster Health'
end end
describe '#priority' do describe '#priority' do
...@@ -82,6 +83,7 @@ describe PrometheusMetric do ...@@ -82,6 +83,7 @@ describe PrometheusMetric do
:business | 0 :business | 0
:response | -5 :response | -5
:system | -10 :system | -10
:cluster_health | 10
end end
with_them do with_them do
...@@ -106,6 +108,7 @@ describe PrometheusMetric do ...@@ -106,6 +108,7 @@ describe PrometheusMetric do
:business | %w() :business | %w()
:response | %w() :response | %w()
:system | %w() :system | %w()
:cluster_health | %w(container_memory_usage_bytes container_cpu_usage_seconds_total)
end end
with_them do with_them do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment