Swap to unique endpoint identifier for prometheus alert integrations
What does this MR do and why?
Related issue: #338838
In advance of migrating Integrations::Prometheus
records to AlertManagement::HttpIntegrations
, this sets up the HttpIntegration
class to expect an endpoint identifier of 'legacy-prometheus'
instead of the existing 'legacy'
. This allows future migrated records to adhere to the unique index on the table.
How to set up and validate locally
Testing/validation is through rails console only, as no legacy prometheus integrations have been migrated/created.
You can check output URLs like this:
[1] pry(main)> integration = AlertManagement::HttpIntegration.new(project: Project.last, name: 'Name', endpoint_identifier: 'legacy')
Project Load (2.3ms) SELECT "projects".* FROM "projects" ORDER BY "projects"."id" DESC LIMIT 1 /*application:console,db_config_name:main,console_hostname:macbook-pro.lan,console_username:syasonik,line:(pry):1:in `__pry__'*/
=> #<AlertManagement::HttpIntegration:0x000000011b605178
id: nil,
created_at: nil,
updated_at: nil,
project_id: 9,
active: false,
encrypted_token: nil,
encrypted_token_iv: nil,
endpoint_identifier: "legacy",
name: "Name",
payload_example: {},
payload_attribute_mapping: {},
type_identifier: "http",
token: nil>
[2] pry(main)> integration.url
Namespace Load (2.4ms) SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 47 LIMIT 1 /*application:console,db_config_name:main,console_hostname:macbook-pro.lan,console_username:syasonik,line:/config/routes.rb:311:in `block (4 levels) in <main>'*/
Feature::FlipperGate Load (0.5ms) SELECT "feature_gates".* FROM "feature_gates" WHERE "feature_gates"."feature_key" = 'cached_route_lookups' /*application:console,db_config_name:main,console_hostname:macbook-pro.lan,console_username:syasonik,line:/lib/feature.rb:237:in `block in current_feature_value'*/
Route Load (4.2ms) SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 47 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,db_config_name:main,console_hostname:macbook-pro.lan,console_username:syasonik,line:/app/models/concerns/routable.rb:141:in `block in full_attribute'*/
=> "http://gdk.test:3000/namespace1/project-1/alerts/notify.json"
[3] pry(main)> integration = AlertManagement::HttpIntegration.new(project: Project.last, name: 'Name', endpoint_identifier: 'legacy-prometheus')
Project Load (2.0ms) SELECT "projects".* FROM "projects" ORDER BY "projects"."id" DESC LIMIT 1 /*application:console,db_config_name:main,console_hostname:macbook-pro.lan,console_username:syasonik,line:(pry):3:in `__pry__'*/
=> #<AlertManagement::HttpIntegration:0x000000011cd86ae0
id: nil,
created_at: nil,
updated_at: nil,
project_id: 9,
active: false,
encrypted_token: nil,
encrypted_token_iv: nil,
endpoint_identifier: "legacy-prometheus",
name: "Name",
payload_example: {},
payload_attribute_mapping: {},
type_identifier: "http",
token: nil>
[4] pry(main)> integration.url
Namespace Load (1.2ms) SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."id" = 47 LIMIT 1 /*application:console,db_config_name:main,console_hostname:macbook-pro.lan,console_username:syasonik,line:/config/routes.rb:311:in `block (4 levels) in <main>'*/
Route Load (0.5ms) SELECT "routes".* FROM "routes" WHERE "routes"."source_id" = 47 AND "routes"."source_type" = 'Namespace' LIMIT 1 /*application:console,db_config_name:main,console_hostname:macbook-pro.lan,console_username:syasonik,line:/app/models/concerns/routable.rb:141:in `block in full_attribute'*/
=> "http://gdk.test:3000/namespace1/project-1/prometheus/alerts/notify.json"
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Vitali Tatarintev