summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:19 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:19 +0000
commit3290d46655f07d7ae3dca788d6df9f326972ffd8 (patch)
tree0d24713e1592cdd3583257f14a52d46a22539ed1 /app/models
parentc6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf (diff)
downloadgitlab-ce-3290d46655f07d7ae3dca788d6df9f326972ffd8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r--app/models/clusters/cluster.rb1
-rw-r--r--app/models/environment.rb1
-rw-r--r--app/models/metrics/dashboard/annotation.rb33
3 files changed, 35 insertions, 0 deletions
diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb
index 78efe2b4337..42771eaa82a 100644
--- a/app/models/clusters/cluster.rb
+++ b/app/models/clusters/cluster.rb
@@ -59,6 +59,7 @@ module Clusters
has_one_cluster_application :elastic_stack
has_many :kubernetes_namespaces
+ has_many :metrics_dashboard_annotations, class_name: 'Metrics::Dashboard::Annotation', inverse_of: :cluster
accepts_nested_attributes_for :provider_gcp, update_only: true
accepts_nested_attributes_for :provider_aws, update_only: true
diff --git a/app/models/environment.rb b/app/models/environment.rb
index fecf13f349e..23c2296688d 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -18,6 +18,7 @@ class Environment < ApplicationRecord
has_many :successful_deployments, -> { success }, class_name: 'Deployment'
has_many :active_deployments, -> { active }, class_name: 'Deployment'
has_many :prometheus_alerts, inverse_of: :environment
+ has_many :metrics_dashboard_annotations, class_name: 'Metrics::Dashboard::Annotation', inverse_of: :environment
has_many :self_managed_prometheus_alert_events, inverse_of: :environment
has_one :last_deployment, -> { success.order('deployments.id DESC') }, class_name: 'Deployment'
diff --git a/app/models/metrics/dashboard/annotation.rb b/app/models/metrics/dashboard/annotation.rb
new file mode 100644
index 00000000000..2f1b6527742
--- /dev/null
+++ b/app/models/metrics/dashboard/annotation.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Metrics
+ module Dashboard
+ class Annotation < ApplicationRecord
+ self.table_name = 'metrics_dashboard_annotations'
+
+ belongs_to :environment, inverse_of: :metrics_dashboard_annotations
+ belongs_to :cluster, class_name: 'Clusters::Cluster', inverse_of: :metrics_dashboard_annotations
+
+ validates :starting_at, presence: true
+ validates :description, presence: true, length: { maximum: 255 }
+ validates :dashboard_path, presence: true, length: { maximum: 255 }
+ validates :panel_xid, length: { maximum: 255 }
+ validate :single_ownership
+ validate :orphaned_annotation
+
+ private
+
+ def single_ownership
+ return if cluster.nil? ^ environment.nil?
+
+ errors.add(:base, s_("Metrics::Dashboard::Annotation|Annotation can't belong to both a cluster and an environment at the same time"))
+ end
+
+ def orphaned_annotation
+ return if cluster.present? || environment.present?
+
+ errors.add(:base, s_("Metrics::Dashboard::Annotation|Annotation must belong to a cluster or an environment"))
+ end
+ end
+ end
+end