Commit 841dae37 authored by James Fargher's avatar James Fargher

Merge branch 'sy-validate-prometheus-alerts' into 'master'

Validate Prometheus alert rules at model level

See merge request gitlab-org/gitlab!39497
parents 2b0356c9 0a283367
......@@ -22,7 +22,7 @@ class PrometheusAlert < ApplicationRecord
after_save :clear_prometheus_adapter_cache!
after_destroy :clear_prometheus_adapter_cache!
validates :environment, :project, :prometheus_metric, presence: true
validates :environment, :project, :prometheus_metric, :threshold, :operator, presence: true
validates :runbook_url, length: { maximum: 255 }, allow_blank: true,
addressable_url: { enforce_sanitization: true, ascii_only: true }
validate :require_valid_environment_project!
......
......@@ -50,6 +50,8 @@ RSpec.describe PrometheusAlert do
it { is_expected.to validate_presence_of(:environment) }
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:prometheus_metric) }
it { is_expected.to validate_presence_of(:operator) }
it { is_expected.to validate_presence_of(:threshold) }
context 'when environment and metric belongs same project' do
it { is_expected.to be_valid }
......
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