Modify identifier index for PrometheusMetrics
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
-
Changelog entry - [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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