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
7cc35451
Commit
7cc35451
authored
Jun 26, 2020
by
Sean Arnold
Committed by
Mayra Cabrera
Jun 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add prometheus_alert_id to Alert management alerts
- Add model relations and database migrations
parent
61903a35
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
78 additions
and
3 deletions
+78
-3
app/models/alert_management/alert.rb
app/models/alert_management/alert.rb
+2
-0
app/models/environment.rb
app/models/environment.rb
+1
-0
app/models/prometheus_alert.rb
app/models/prometheus_alert.rb
+1
-0
changelogs/unreleased/222253-add-prometheus-columns-to-alert-management-alert.yml
...2253-add-prometheus-columns-to-alert-management-alert.yml
+5
-0
db/migrate/20200622040750_add_prometheus_alert_id_to_alert_management_alerts.rb
...750_add_prometheus_alert_id_to_alert_management_alerts.rb
+16
-0
db/migrate/20200625045442_add_idx_and_fk_for_prometheus_and_environment_to_alert_management_alerts.rb
..._prometheus_and_environment_to_alert_management_alerts.rb
+25
-0
db/structure.sql
db/structure.sql
+14
-0
spec/models/alert_management/alert_spec.rb
spec/models/alert_management/alert_spec.rb
+3
-1
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+1
-0
spec/models/prometheus_alert_spec.rb
spec/models/prometheus_alert_spec.rb
+4
-0
spec/services/projects/alerting/notify_service_spec.rb
spec/services/projects/alerting/notify_service_spec.rb
+6
-2
No files found.
app/models/alert_management/alert.rb
View file @
7cc35451
...
@@ -30,6 +30,8 @@ module AlertManagement
...
@@ -30,6 +30,8 @@ module AlertManagement
belongs_to
:project
belongs_to
:project
belongs_to
:issue
,
optional:
true
belongs_to
:issue
,
optional:
true
belongs_to
:prometheus_alert
,
optional:
true
belongs_to
:environment
,
optional:
true
has_many
:alert_assignees
,
inverse_of: :alert
has_many
:alert_assignees
,
inverse_of: :alert
has_many
:assignees
,
through: :alert_assignees
has_many
:assignees
,
through: :alert_assignees
...
...
app/models/environment.rb
View file @
7cc35451
...
@@ -21,6 +21,7 @@ class Environment < ApplicationRecord
...
@@ -21,6 +21,7 @@ class Environment < ApplicationRecord
has_many
:prometheus_alerts
,
inverse_of: :environment
has_many
:prometheus_alerts
,
inverse_of: :environment
has_many
:metrics_dashboard_annotations
,
class_name:
'Metrics::Dashboard::Annotation'
,
inverse_of: :environment
has_many
:metrics_dashboard_annotations
,
class_name:
'Metrics::Dashboard::Annotation'
,
inverse_of: :environment
has_many
:self_managed_prometheus_alert_events
,
inverse_of: :environment
has_many
:self_managed_prometheus_alert_events
,
inverse_of: :environment
has_many
:alert_management_alerts
,
class_name:
'AlertManagement::Alert'
,
inverse_of: :environment
has_one
:last_deployment
,
->
{
success
.
order
(
'deployments.id DESC'
)
},
class_name:
'Deployment'
has_one
:last_deployment
,
->
{
success
.
order
(
'deployments.id DESC'
)
},
class_name:
'Deployment'
has_one
:last_deployable
,
through: :last_deployment
,
source:
'deployable'
,
source_type:
'CommitStatus'
has_one
:last_deployable
,
through: :last_deployment
,
source:
'deployable'
,
source_type:
'CommitStatus'
...
...
app/models/prometheus_alert.rb
View file @
7cc35451
...
@@ -16,6 +16,7 @@ class PrometheusAlert < ApplicationRecord
...
@@ -16,6 +16,7 @@ class PrometheusAlert < ApplicationRecord
has_many
:prometheus_alert_events
,
inverse_of: :prometheus_alert
has_many
:prometheus_alert_events
,
inverse_of: :prometheus_alert
has_many
:related_issues
,
through: :prometheus_alert_events
has_many
:related_issues
,
through: :prometheus_alert_events
has_many
:alert_management_alerts
,
class_name:
'AlertManagement::Alert'
,
inverse_of: :prometheus_alert
after_save
:clear_prometheus_adapter_cache!
after_save
:clear_prometheus_adapter_cache!
after_destroy
:clear_prometheus_adapter_cache!
after_destroy
:clear_prometheus_adapter_cache!
...
...
changelogs/unreleased/222253-add-prometheus-columns-to-alert-management-alert.yml
0 → 100644
View file @
7cc35451
---
title
:
Add prometheus_alert_id and environment_id to Alert management alerts
merge_request
:
34995
author
:
type
:
added
db/migrate/20200622040750_add_prometheus_alert_id_to_alert_management_alerts.rb
0 → 100644
View file @
7cc35451
# frozen_string_literal: true
class
AddPrometheusAlertIdToAlertManagementAlerts
<
ActiveRecord
::
Migration
[
6.0
]
DOWNTIME
=
false
def
up
add_column
:alert_management_alerts
,
:prometheus_alert_id
,
:integer
add_column
:alert_management_alerts
,
:environment_id
,
:integer
end
def
down
remove_column
:alert_management_alerts
,
:prometheus_alert_id
remove_column
:alert_management_alerts
,
:environment_id
end
end
db/migrate/20200625045442_add_idx_and_fk_for_prometheus_and_environment_to_alert_management_alerts.rb
0 → 100644
View file @
7cc35451
# frozen_string_literal: true
class
AddIdxAndFkForPrometheusAndEnvironmentToAlertManagementAlerts
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:alert_management_alerts
,
:prometheus_alert_id
,
where:
'prometheus_alert_id is not null'
add_concurrent_foreign_key
:alert_management_alerts
,
:prometheus_alerts
,
column: :prometheus_alert_id
,
on_delete: :cascade
add_concurrent_index
:alert_management_alerts
,
:environment_id
,
where:
'environment_id is not null'
add_concurrent_foreign_key
:alert_management_alerts
,
:environments
,
column: :environment_id
,
on_delete: :nullify
end
def
down
remove_concurrent_index
:alert_management_alerts
,
:prometheus_alert_id
remove_foreign_key_without_error
:alert_management_alerts
,
column: :prometheus_alert_id
remove_concurrent_index
:alert_management_alerts
,
:environment_id
remove_foreign_key_without_error
:alert_management_alerts
,
column: :environment_id
end
end
db/structure.sql
View file @
7cc35451
...
@@ -78,6 +78,8 @@ CREATE TABLE public.alert_management_alerts (
...
@@ -78,6 +78,8 @@ CREATE TABLE public.alert_management_alerts (
monitoring_tool
text
,
monitoring_tool
text
,
hosts
text
[]
DEFAULT
'{}'
::
text
[]
NOT
NULL
,
hosts
text
[]
DEFAULT
'{}'
::
text
[]
NOT
NULL
,
payload
jsonb
DEFAULT
'{}'
::
jsonb
NOT
NULL
,
payload
jsonb
DEFAULT
'{}'
::
jsonb
NOT
NULL
,
prometheus_alert_id
integer
,
environment_id
integer
,
CONSTRAINT
check_2df3e2fdc1
CHECK
((
char_length
(
monitoring_tool
)
<=
100
)),
CONSTRAINT
check_2df3e2fdc1
CHECK
((
char_length
(
monitoring_tool
)
<=
100
)),
CONSTRAINT
check_5e9e57cadb
CHECK
((
char_length
(
description
)
<=
1000
)),
CONSTRAINT
check_5e9e57cadb
CHECK
((
char_length
(
description
)
<=
1000
)),
CONSTRAINT
check_bac14dddde
CHECK
((
char_length
(
service
)
<=
100
)),
CONSTRAINT
check_bac14dddde
CHECK
((
char_length
(
service
)
<=
100
)),
...
@@ -9352,12 +9354,16 @@ CREATE INDEX index_alert_assignees_on_alert_id ON public.alert_management_alert_
...
@@ -9352,12 +9354,16 @@ CREATE INDEX index_alert_assignees_on_alert_id ON public.alert_management_alert_
CREATE
UNIQUE
INDEX
index_alert_assignees_on_user_id_and_alert_id
ON
public
.
alert_management_alert_assignees
USING
btree
(
user_id
,
alert_id
);
CREATE
UNIQUE
INDEX
index_alert_assignees_on_user_id_and_alert_id
ON
public
.
alert_management_alert_assignees
USING
btree
(
user_id
,
alert_id
);
CREATE
INDEX
index_alert_management_alerts_on_environment_id
ON
public
.
alert_management_alerts
USING
btree
(
environment_id
)
WHERE
(
environment_id
IS
NOT
NULL
);
CREATE
INDEX
index_alert_management_alerts_on_issue_id
ON
public
.
alert_management_alerts
USING
btree
(
issue_id
);
CREATE
INDEX
index_alert_management_alerts_on_issue_id
ON
public
.
alert_management_alerts
USING
btree
(
issue_id
);
CREATE
UNIQUE
INDEX
index_alert_management_alerts_on_project_id_and_fingerprint
ON
public
.
alert_management_alerts
USING
btree
(
project_id
,
fingerprint
);
CREATE
UNIQUE
INDEX
index_alert_management_alerts_on_project_id_and_fingerprint
ON
public
.
alert_management_alerts
USING
btree
(
project_id
,
fingerprint
);
CREATE
UNIQUE
INDEX
index_alert_management_alerts_on_project_id_and_iid
ON
public
.
alert_management_alerts
USING
btree
(
project_id
,
iid
);
CREATE
UNIQUE
INDEX
index_alert_management_alerts_on_project_id_and_iid
ON
public
.
alert_management_alerts
USING
btree
(
project_id
,
iid
);
CREATE
INDEX
index_alert_management_alerts_on_prometheus_alert_id
ON
public
.
alert_management_alerts
USING
btree
(
prometheus_alert_id
)
WHERE
(
prometheus_alert_id
IS
NOT
NULL
);
CREATE
UNIQUE
INDEX
index_alert_user_mentions_on_alert_id
ON
public
.
alert_management_alert_user_mentions
USING
btree
(
alert_management_alert_id
)
WHERE
(
note_id
IS
NULL
);
CREATE
UNIQUE
INDEX
index_alert_user_mentions_on_alert_id
ON
public
.
alert_management_alert_user_mentions
USING
btree
(
alert_management_alert_id
)
WHERE
(
note_id
IS
NULL
);
CREATE
UNIQUE
INDEX
index_alert_user_mentions_on_alert_id_and_note_id
ON
public
.
alert_management_alert_user_mentions
USING
btree
(
alert_management_alert_id
,
note_id
);
CREATE
UNIQUE
INDEX
index_alert_user_mentions_on_alert_id_and_note_id
ON
public
.
alert_management_alert_user_mentions
USING
btree
(
alert_management_alert_id
,
note_id
);
...
@@ -11538,6 +11544,9 @@ ALTER TABLE ONLY public.geo_event_log
...
@@ -11538,6 +11544,9 @@ ALTER TABLE ONLY public.geo_event_log
ALTER
TABLE
ONLY
public
.
ci_build_trace_sections
ALTER
TABLE
ONLY
public
.
ci_build_trace_sections
ADD
CONSTRAINT
fk_4ebe41f502
FOREIGN
KEY
(
build_id
)
REFERENCES
public
.
ci_builds
(
id
)
ON
DELETE
CASCADE
;
ADD
CONSTRAINT
fk_4ebe41f502
FOREIGN
KEY
(
build_id
)
REFERENCES
public
.
ci_builds
(
id
)
ON
DELETE
CASCADE
;
ALTER
TABLE
ONLY
public
.
alert_management_alerts
ADD
CONSTRAINT
fk_51ab4b6089
FOREIGN
KEY
(
prometheus_alert_id
)
REFERENCES
public
.
prometheus_alerts
(
id
)
ON
DELETE
CASCADE
;
ALTER
TABLE
ONLY
public
.
path_locks
ALTER
TABLE
ONLY
public
.
path_locks
ADD
CONSTRAINT
fk_5265c98f24
FOREIGN
KEY
(
project_id
)
REFERENCES
public
.
projects
(
id
)
ON
DELETE
CASCADE
;
ADD
CONSTRAINT
fk_5265c98f24
FOREIGN
KEY
(
project_id
)
REFERENCES
public
.
projects
(
id
)
ON
DELETE
CASCADE
;
...
@@ -11745,6 +11754,9 @@ ALTER TABLE ONLY public.merge_requests
...
@@ -11745,6 +11754,9 @@ ALTER TABLE ONLY public.merge_requests
ALTER
TABLE
ONLY
public
.
epics
ALTER
TABLE
ONLY
public
.
epics
ADD
CONSTRAINT
fk_aa5798e761
FOREIGN
KEY
(
closed_by_id
)
REFERENCES
public
.
users
(
id
)
ON
DELETE
SET
NULL
;
ADD
CONSTRAINT
fk_aa5798e761
FOREIGN
KEY
(
closed_by_id
)
REFERENCES
public
.
users
(
id
)
ON
DELETE
SET
NULL
;
ALTER
TABLE
ONLY
public
.
alert_management_alerts
ADD
CONSTRAINT
fk_aad61aedca
FOREIGN
KEY
(
environment_id
)
REFERENCES
public
.
environments
(
id
)
ON
DELETE
SET
NULL
;
ALTER
TABLE
ONLY
public
.
identities
ALTER
TABLE
ONLY
public
.
identities
ADD
CONSTRAINT
fk_aade90f0fc
FOREIGN
KEY
(
saml_provider_id
)
REFERENCES
public
.
saml_providers
(
id
)
ON
DELETE
CASCADE
;
ADD
CONSTRAINT
fk_aade90f0fc
FOREIGN
KEY
(
saml_provider_id
)
REFERENCES
public
.
saml_providers
(
id
)
ON
DELETE
CASCADE
;
...
@@ -14156,6 +14168,7 @@ COPY "schema_migrations" (version) FROM STDIN;
...
@@ -14156,6 +14168,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200618134723
20200618134723
20200619154527
20200619154527
20200619154528
20200619154528
20200622040750
20200622070606
20200622070606
20200622070620
20200622070620
20200622095419
20200622095419
...
@@ -14165,5 +14178,6 @@ COPY "schema_migrations" (version) FROM STDIN;
...
@@ -14165,5 +14178,6 @@ COPY "schema_migrations" (version) FROM STDIN;
20200623000320
20200623000320
20200623121135
20200623121135
20200624075411
20200624075411
20200625045442
\
.
\
.
spec/models/alert_management/alert_spec.rb
View file @
7cc35451
...
@@ -5,7 +5,9 @@ require 'spec_helper'
...
@@ -5,7 +5,9 @@ require 'spec_helper'
RSpec
.
describe
AlertManagement
::
Alert
do
RSpec
.
describe
AlertManagement
::
Alert
do
describe
'associations'
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:issue
)
}
it
{
is_expected
.
to
belong_to
(
:issue
).
optional
}
it
{
is_expected
.
to
belong_to
(
:prometheus_alert
).
optional
}
it
{
is_expected
.
to
belong_to
(
:environment
).
optional
}
it
{
is_expected
.
to
have_many
(
:assignees
).
through
(
:alert_assignees
)
}
it
{
is_expected
.
to
have_many
(
:assignees
).
through
(
:alert_assignees
)
}
it
{
is_expected
.
to
have_many
(
:notes
)
}
it
{
is_expected
.
to
have_many
(
:notes
)
}
it
{
is_expected
.
to
have_many
(
:ordered_notes
)
}
it
{
is_expected
.
to
have_many
(
:ordered_notes
)
}
...
...
spec/models/environment_spec.rb
View file @
7cc35451
...
@@ -18,6 +18,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
...
@@ -18,6 +18,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
it
{
is_expected
.
to
belong_to
(
:project
).
required
}
it
{
is_expected
.
to
belong_to
(
:project
).
required
}
it
{
is_expected
.
to
have_many
(
:deployments
)
}
it
{
is_expected
.
to
have_many
(
:deployments
)
}
it
{
is_expected
.
to
have_many
(
:metrics_dashboard_annotations
)
}
it
{
is_expected
.
to
have_many
(
:metrics_dashboard_annotations
)
}
it
{
is_expected
.
to
have_many
(
:alert_management_alerts
)
}
it
{
is_expected
.
to
delegate_method
(
:stop_action
).
to
(
:last_deployment
)
}
it
{
is_expected
.
to
delegate_method
(
:stop_action
).
to
(
:last_deployment
)
}
it
{
is_expected
.
to
delegate_method
(
:manual_actions
).
to
(
:last_deployment
)
}
it
{
is_expected
.
to
delegate_method
(
:manual_actions
).
to
(
:last_deployment
)
}
...
...
spec/models/prometheus_alert_spec.rb
View file @
7cc35451
...
@@ -33,6 +33,10 @@ RSpec.describe PrometheusAlert do
...
@@ -33,6 +33,10 @@ RSpec.describe PrometheusAlert do
describe
'associations'
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:environment
)
}
it
{
is_expected
.
to
belong_to
(
:environment
)
}
it
{
is_expected
.
to
belong_to
(
:prometheus_metric
)
}
it
{
is_expected
.
to
have_many
(
:prometheus_alert_events
)
}
it
{
is_expected
.
to
have_many
(
:related_issues
)
}
it
{
is_expected
.
to
have_many
(
:alert_management_alerts
)
}
end
end
describe
'project validations'
do
describe
'project validations'
do
...
...
spec/services/projects/alerting/notify_service_spec.rb
View file @
7cc35451
...
@@ -134,7 +134,9 @@ RSpec.describe Projects::Alerting::NotifyService do
...
@@ -134,7 +134,9 @@ RSpec.describe Projects::Alerting::NotifyService do
monitoring_tool:
payload_raw
.
fetch
(
:monitoring_tool
),
monitoring_tool:
payload_raw
.
fetch
(
:monitoring_tool
),
service:
payload_raw
.
fetch
(
:service
),
service:
payload_raw
.
fetch
(
:service
),
fingerprint:
Digest
::
SHA1
.
hexdigest
(
fingerprint
),
fingerprint:
Digest
::
SHA1
.
hexdigest
(
fingerprint
),
ended_at:
nil
ended_at:
nil
,
prometheus_alert_id:
nil
,
environment_id:
nil
)
)
end
end
...
@@ -193,7 +195,9 @@ RSpec.describe Projects::Alerting::NotifyService do
...
@@ -193,7 +195,9 @@ RSpec.describe Projects::Alerting::NotifyService do
monitoring_tool:
nil
,
monitoring_tool:
nil
,
service:
nil
,
service:
nil
,
fingerprint:
nil
,
fingerprint:
nil
,
ended_at:
nil
ended_at:
nil
,
prometheus_alert_id:
nil
,
environment_id:
nil
)
)
end
end
end
end
...
...
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