diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /app/models/metrics/dashboard/annotation.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'app/models/metrics/dashboard/annotation.rb')
-rw-r--r-- | app/models/metrics/dashboard/annotation.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/metrics/dashboard/annotation.rb b/app/models/metrics/dashboard/annotation.rb index 8166880f0c9..3383dda20c9 100644 --- a/app/models/metrics/dashboard/annotation.rb +++ b/app/models/metrics/dashboard/annotation.rb @@ -3,6 +3,8 @@ module Metrics module Dashboard class Annotation < ApplicationRecord + include DeleteWithLimit + self.table_name = 'metrics_dashboard_annotations' belongs_to :environment, inverse_of: :metrics_dashboard_annotations @@ -14,14 +16,25 @@ module Metrics validates :panel_xid, length: { maximum: 255 } validate :single_ownership validate :orphaned_annotation + validate :ending_at_after_starting_at scope :after, ->(after) { where('starting_at >= ?', after) } scope :before, ->(before) { where('starting_at <= ?', before) } scope :for_dashboard, ->(dashboard_path) { where(dashboard_path: dashboard_path) } + scope :ending_before, ->(timestamp) { where('COALESCE(ending_at, starting_at) < ?', timestamp) } private + # If annotation has NULL in ending_at column that indicates, that this annotation IS TIED TO SINGLE POINT + # IN TIME designated by starting_at timestamp. It does NOT mean that annotation is ever going starting from + # stating_at timestamp + def ending_at_after_starting_at + return if ending_at.blank? || starting_at.blank? || starting_at <= ending_at + + errors.add(:ending_at, s_("Metrics::Dashboard::Annotation|can't be before starting_at time")) + end + def single_ownership return if cluster.nil? ^ environment.nil? |