Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a8ae9e0c
Commit
a8ae9e0c
authored
Jun 29, 2020
by
Ryan Cobb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Composite metric identifier index
Use project_id and identifier for composite prometheus_metric index.
parent
601a47f6
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
0 deletions
+27
-0
app/models/prometheus_metric.rb
app/models/prometheus_metric.rb
+1
-0
changelogs/unreleased/rc-enforce_unique_metrics_id_across_project.yml
...nreleased/rc-enforce_unique_metrics_id_across_project.yml
+5
-0
db/migrate/20200629192638_add_uniq_index_on_metric_identifier_and_project_id.rb
...638_add_uniq_index_on_metric_identifier_and_project_id.rb
+17
-0
db/structure.sql
db/structure.sql
+3
-0
spec/models/prometheus_metric_spec.rb
spec/models/prometheus_metric_spec.rb
+1
-0
No files found.
app/models/prometheus_metric.rb
View file @
a8ae9e0c
...
...
@@ -11,6 +11,7 @@ class PrometheusMetric < ApplicationRecord
validates
:group
,
presence:
true
validates
:y_label
,
presence:
true
validates
:unit
,
presence:
true
validates
:identifier
,
uniqueness:
{
scope: :project_id
},
allow_nil:
true
validates
:project
,
presence:
true
,
unless: :common?
validates
:project
,
absence:
true
,
if: :common?
...
...
changelogs/unreleased/rc-enforce_unique_metrics_id_across_project.yml
0 → 100644
View file @
a8ae9e0c
---
title
:
Enforce prometheus metric uniqueness across project scope
merge_request
:
35566
author
:
type
:
fixed
db/migrate/20200629192638_add_uniq_index_on_metric_identifier_and_project_id.rb
0 → 100644
View file @
a8ae9e0c
# 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
db/structure.sql
View file @
a8ae9e0c
...
...
@@ -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_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_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;
20200626130220
20200630110826
20200701093859
20200629192638
20200702123805
20200703154822
20200704143633
...
...
spec/models/prometheus_metric_spec.rb
View file @
a8ae9e0c
...
...
@@ -11,6 +11,7 @@ RSpec.describe PrometheusMetric do
it
{
is_expected
.
to
validate_presence_of
(
:title
)
}
it
{
is_expected
.
to
validate_presence_of
(
:query
)
}
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
using
RSpec
::
Parameterized
::
TableSyntax
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment