Commit 0a283367 authored by syasonik's avatar syasonik

Validate alert rules at model level

parent d7239da8
......@@ -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