Add table for project alert http integrations
What does this MR do?
Adds a table & preliminary model for HTTP Integrations for alerts!
Related issue: #255511 (closed) from epic &4442 (closed)
Intended use:
- An HTTP Integration will allow an endpoint to be configured which can receive alert notifications from any source as long is it provides the appropriate token.
- New integrations will be have URLs formatted according to #223778 (closed). An expected url will look like:
https://gitlab.com/group/project/alerts/notify/<name>/<endpoint_identifier>.json
; We will lookup the active integration by the endpoint identifier, allowing thename
portion mostly to be used for user-readability and organization. - Existing integrations from
AlertsService
&AlertsServiceData
will eventually be migrated intoHTTP Integrations
. These are expected not to have aname
orendpoint_identifier
, and they will continue to accept alerts athttps://gitlab.com/group/project/alerts/notify.json
, as they do now. -
token
assignment is air-lifted fromAlertsService
&AlertsServiceData
----- Check out this keen supplemental database info! -----
Up migrations
$ rails db:migrate
== 20200928203531 CreateAlertManagementHttpIntegrations: migrating ============
-- create_table(:alert_management_http_integrations, {:if_not_exists=>true})
-> 0.0214s
-- transaction_open?()
-> 0.0000s
-- current_schema()
-> 0.0002s
-- execute("ALTER TABLE alert_management_http_integrations\nADD CONSTRAINT check_f68577c4af\nCHECK ( char_length(encrypted_token) <= 255 )\nNOT VALID;\n")
-> 0.0012s
-- current_schema()
-> 0.0002s
-- execute("SET statement_timeout TO 0")
-> 0.0001s
-- execute("ALTER TABLE alert_management_http_integrations VALIDATE CONSTRAINT check_f68577c4af;")
-> 0.0005s
-- execute("RESET ALL")
-> 0.0002s
-- transaction_open?()
-> 0.0000s
-- current_schema()
-> 0.0002s
-- execute("ALTER TABLE alert_management_http_integrations\nADD CONSTRAINT check_286943b636\nCHECK ( char_length(encrypted_token_iv) <= 255 )\nNOT VALID;\n")
-> 0.0008s
-- current_schema()
-> 0.0002s
-- execute("ALTER TABLE alert_management_http_integrations VALIDATE CONSTRAINT check_286943b636;")
-> 0.0004s
-- transaction_open?()
-> 0.0000s
-- current_schema()
-> 0.0002s
-- execute("ALTER TABLE alert_management_http_integrations\nADD CONSTRAINT check_e270820180\nCHECK ( char_length(endpoint_identifier) <= 255 )\nNOT VALID;\n")
-> 0.0004s
-- current_schema()
-> 0.0001s
-- execute("ALTER TABLE alert_management_http_integrations VALIDATE CONSTRAINT check_e270820180;")
-> 0.0008s
-- transaction_open?()
-> 0.0000s
-- current_schema()
-> 0.0002s
-- execute("ALTER TABLE alert_management_http_integrations\nADD CONSTRAINT check_392143ccf4\nCHECK ( char_length(name) <= 255 )\nNOT VALID;\n")
-> 0.0003s
-- current_schema()
-> 0.0001s
-- execute("ALTER TABLE alert_management_http_integrations VALIDATE CONSTRAINT check_392143ccf4;")
-> 0.0004s
-- add_index(:alert_management_http_integrations, [:active, :project_id, :endpoint_identifier], {:unique=>true, :name=>"index_http_integrations_on_active_and_project_and_endpoint", :where=>"active"})
-> 0.0082s
== 20200928203531 CreateAlertManagementHttpIntegrations: migrated (0.0587s) ===
== 20200928210524 AddHttpIntegrationsProjectForeignKey: migrating =============
-- add_foreign_key(:alert_management_http_integrations, :projects, {:column=>:project_id, :on_delete=>:cascade})
-> 0.0289s
== 20200928210524 AddHttpIntegrationsProjectForeignKey: migrated (0.0304s) ====
$ bin/rails dbconsole
psql (11.9)
Type "help" for help.
gitlabhq_development=# \d alert_management_http_integrations
Table "public.alert_management_http_integrations"
Column | Type | Collation | Nullable | Default
---------------------+--------------------------+-----------+----------+----------------------------------------------------------------
id | bigint | | not null | nextval('alert_management_http_integrations_id_seq'::regclass)
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
project_id | bigint | | not null |
active | boolean | | not null | false
encrypted_token | text | | not null |
encrypted_token_iv | text | | not null |
endpoint_identifier | text | | not null |
name | text | | not null |
Indexes:
"alert_management_http_integrations_pkey" PRIMARY KEY, btree (id)
"index_http_integrations_on_active_and_project_and_endpoint" UNIQUE, btree (active, project_id, endpoint_identifier) WHERE active
"index_alert_management_http_integrations_on_project_id" btree (project_id)
Check constraints:
"check_286943b636" CHECK (char_length(encrypted_token_iv) <= 255)
"check_392143ccf4" CHECK (char_length(name) <= 255)
"check_e270820180" CHECK (char_length(endpoint_identifier) <= 255)
"check_f68577c4af" CHECK (char_length(encrypted_token) <= 255)
Foreign-key constraints:
"fk_rails_bec49f52cc" FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
Down migration: add project foreign key
$ rails db:migrate:down VERSION=20200928210524
== 20200928210524 AddHttpIntegrationsProjectForeignKey: reverting =============
-- remove_foreign_key(:alert_management_http_integrations, {:column=>:project_id})
-> 0.0069s
== 20200928210524 AddHttpIntegrationsProjectForeignKey: reverted (0.0150s) ====
$ bin/rails dbconsole
psql (11.9)
Type "help" for help.
gitlabhq_development=# \d alert_management_http_integrations
Table "public.alert_management_http_integrations"
Column | Type | Collation | Nullable | Default
---------------------+--------------------------+-----------+----------+----------------------------------------------------------------
id | bigint | | not null | nextval('alert_management_http_integrations_id_seq'::regclass)
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
project_id | bigint | | not null |
active | boolean | | not null | false
encrypted_token | text | | not null |
encrypted_token_iv | text | | not null |
endpoint_identifier | text | | not null |
name | text | | not null |
Indexes:
"alert_management_http_integrations_pkey" PRIMARY KEY, btree (id)
"index_http_integrations_on_active_and_project_and_endpoint" UNIQUE, btree (active, project_id, endpoint_identifier) WHERE active
"index_alert_management_http_integrations_on_project_id" btree (project_id)
Check constraints:
"check_286943b636" CHECK (char_length(encrypted_token_iv) <= 255)
"check_392143ccf4" CHECK (char_length(name) <= 255)
"check_e270820180" CHECK (char_length(endpoint_identifier) <= 255)
"check_f68577c4af" CHECK (char_length(encrypted_token) <= 255)
Down migration: add integrations table
$ rails db:migrate:down VERSION=20200928203531
== 20200928203531 CreateAlertManagementHttpIntegrations: reverting ============
-- drop_table(:alert_management_http_integrations)
-> 0.0142s
== 20200928203531 CreateAlertManagementHttpIntegrations: reverted (0.0142s) ===
$ bin/rails dbconsole
psql (11.9)
Type "help" for help.
gitlabhq_development=# \d alert_management_http_integrations
Did not find any relation named "alert_management_http_integrations".
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 Peter Leitzen