diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
commit | db384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch) | |
tree | 34beaef37df5f47ccbcf5729d7583aae093cffa0 /lib/gitlab/metrics/dashboard/validator/post_schema_validator.rb | |
parent | 54fd7b1bad233e3944434da91d257fa7f63c3996 (diff) |
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'lib/gitlab/metrics/dashboard/validator/post_schema_validator.rb')
-rw-r--r-- | lib/gitlab/metrics/dashboard/validator/post_schema_validator.rb | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/lib/gitlab/metrics/dashboard/validator/post_schema_validator.rb b/lib/gitlab/metrics/dashboard/validator/post_schema_validator.rb deleted file mode 100644 index 73bfc5a6294..00000000000 --- a/lib/gitlab/metrics/dashboard/validator/post_schema_validator.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Metrics - module Dashboard - module Validator - class PostSchemaValidator - def initialize(metric_ids:, project: nil, dashboard_path: nil) - @metric_ids = metric_ids - @project = project - @dashboard_path = dashboard_path - end - - def validate - errors = [] - errors << uniq_metric_ids - errors.compact - end - - private - - attr_reader :project, :metric_ids, :dashboard_path - - def uniq_metric_ids - return Validator::Errors::DuplicateMetricIds.new if metric_ids.uniq! - - uniq_metric_ids_across_project if project.present? || dashboard_path.present? - end - - # rubocop: disable CodeReuse/ActiveRecord - def uniq_metric_ids_across_project - return ArgumentError.new(_('Both project and dashboard_path are required')) unless - dashboard_path.present? && project.present? - - # If PrometheusMetric identifier is not unique across project and dashboard_path, - # we need to error because we don't know if the user is trying to create a new metric - # or update an existing one. - identifier_on_other_dashboard = PrometheusMetric.where( - project: project, - identifier: metric_ids - ).where.not( - dashboard_path: dashboard_path - ).exists? - - Validator::Errors::DuplicateMetricIds.new if identifier_on_other_dashboard - end - # rubocop: enable CodeReuse/ActiveRecord - end - end - end - end -end |