Commit a8ae9e0c authored by Ryan Cobb's avatar Ryan Cobb

Composite metric identifier index

Use project_id and identifier for composite prometheus_metric index.
parent 601a47f6
...@@ -11,6 +11,7 @@ class PrometheusMetric < ApplicationRecord ...@@ -11,6 +11,7 @@ class PrometheusMetric < ApplicationRecord
validates :group, presence: true validates :group, presence: true
validates :y_label, presence: true validates :y_label, presence: true
validates :unit, presence: true validates :unit, presence: true
validates :identifier, uniqueness: { scope: :project_id }, allow_nil: true
validates :project, presence: true, unless: :common? validates :project, presence: true, unless: :common?
validates :project, absence: true, if: :common? validates :project, absence: true, if: :common?
......
---
title: Enforce prometheus metric uniqueness across project scope
merge_request: 35566
author:
type: fixed
# frozen_string_literal: true
class AddUniqIndexOnMetricIdentifierAndProjectId < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :prometheus_metrics, [:identifier, :project_id], unique: true
end
def down
remove_concurrent_index :prometheus_metrics, [:identifier, :project_id]
end
end
...@@ -19931,6 +19931,8 @@ CREATE INDEX index_prometheus_metrics_on_group ON public.prometheus_metrics USIN ...@@ -19931,6 +19931,8 @@ CREATE INDEX index_prometheus_metrics_on_group ON public.prometheus_metrics USIN
CREATE UNIQUE INDEX index_prometheus_metrics_on_identifier ON public.prometheus_metrics USING btree (identifier); CREATE UNIQUE INDEX index_prometheus_metrics_on_identifier ON public.prometheus_metrics USING btree (identifier);
CREATE UNIQUE INDEX index_prometheus_metrics_on_identifier_and_project_id ON public.prometheus_metrics USING btree (identifier, project_id);
CREATE INDEX index_prometheus_metrics_on_project_id ON public.prometheus_metrics USING btree (project_id); CREATE INDEX index_prometheus_metrics_on_project_id ON public.prometheus_metrics USING btree (project_id);
CREATE INDEX index_protected_branch_merge_access ON public.protected_branch_merge_access_levels USING btree (protected_branch_id); CREATE INDEX index_protected_branch_merge_access ON public.protected_branch_merge_access_levels USING btree (protected_branch_id);
...@@ -23583,6 +23585,7 @@ COPY "schema_migrations" (version) FROM STDIN; ...@@ -23583,6 +23585,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200626130220 20200626130220
20200630110826 20200630110826
20200701093859 20200701093859
20200629192638
20200702123805 20200702123805
20200703154822 20200703154822
20200704143633 20200704143633
......
...@@ -11,6 +11,7 @@ RSpec.describe PrometheusMetric do ...@@ -11,6 +11,7 @@ RSpec.describe PrometheusMetric do
it { is_expected.to validate_presence_of(:title) } it { is_expected.to validate_presence_of(:title) }
it { is_expected.to validate_presence_of(:query) } it { is_expected.to validate_presence_of(:query) }
it { is_expected.to validate_presence_of(:group) } it { is_expected.to validate_presence_of(:group) }
it { is_expected.to validate_uniqueness_of(:identifier).scoped_to(:project_id).allow_nil }
describe 'common metrics' do describe 'common metrics' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
......
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