Skip to content

Modify identifier index for PrometheusMetrics

Ryan Cobb requested to merge rc/remove_metric_identifier_index into master

What does this MR do?

In support of: #28241 (closed)
Second part of: !35566 (merged)

!35566 (merged) added a new composite index of identifier and project_id on PrometheusMetrics but we still need to handle the case when project_id is null as postgres does not enforce uniqueness on null values unless explicitly told to do so.

This MR adds a unique index on identifier when project_id is null. This enforces identifier uniqueness in the case of "Common Metrics" which do not have a project_id.

up

== 20200702201039 ChangePrometheusMetricsIdentifierIndex: migrating ===========
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:prometheus_metrics, :identifier, {:name=>:index_prometheus_metrics_on_identifier_and_null_project, :unique=>true, :where=>"project_id IS NULL", :algorithm=>:concurrently})
   -> 0.0043s
-- add_index(:prometheus_metrics, :identifier, {:name=>:index_prometheus_metrics_on_identifier_and_null_project, :unique=>true, :where=>"project_id IS NULL", :algorithm=>:concurrently})
   -> 0.0039s
-- transaction_open?()
   -> 0.0000s
-- indexes(:prometheus_metrics)
   -> 0.0044s
-- remove_index(:prometheus_metrics, {:algorithm=>:concurrently, :name=>:index_prometheus_metrics_on_identifier})
   -> 0.0020s
== 20200702201039 ChangePrometheusMetricsIdentifierIndex: migrated (0.0157s) ==

down

== 20200702201039 ChangePrometheusMetricsIdentifierIndex: reverting ===========
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:prometheus_metrics, :identifier, {:name=>:index_prometheus_metrics_on_identifier, :unique=>true, :algorithm=>:concurrently})
   -> 0.0033s
-- add_index(:prometheus_metrics, :identifier, {:name=>:index_prometheus_metrics_on_identifier, :unique=>true, :algorithm=>:concurrently})
   -> 0.0042s
-- transaction_open?()
   -> 0.0000s
-- indexes(:prometheus_metrics)
   -> 0.0040s
-- remove_index(:prometheus_metrics, {:algorithm=>:concurrently, :name=>:index_prometheus_metrics_on_identifier_and_null_project})
   -> 0.0013s
== 20200702201039 ChangePrometheusMetricsIdentifierIndex: reverted (0.0138s) ==

#database-lab

exec DROP INDEX CONCURRENTLY "index_prometheus_metrics_on_identifier"


The query has been executed. Duration: 93.000 ms
exec CREATE UNIQUE INDEX CONCURRENTLY "index_prometheus_metrics_on_identifier" ON "prometheus_metrics" ("identifier") WHERE project_id IS NULL

The query has been executed. Duration: 88.000 ms

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Mayra Cabrera

Merge request reports

Loading