Patch Prometheus services records
What does this MR do?
This MR provides database migration which will create missing PrometheusService
record for all projects which belongs to cluster with Prometheus Application installed.
Conformity
-
Changelog entry -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Database
Affected rows on gitlab.com 5621 (updated: 22 and inserted: 5599)
Plans
Migratable::Project.without_active_prometheus_services.group('projects.id').select('projects.id')
sql: SELECT projects.id FROM "projects" LEFT JOIN services ON services.project_id = projects.id AND services.type = 'PrometheusService' WHERE (services.id IS NULL OR (services.active = FALSE AND services.properties = '{}')) GROUP BY projects.id
plan: https://explain.depesz.com/s/vUiR
Migratable::Project.without_active_prometheus_services.with_application_on_group_clusters.group('projects.id').select('projects.id')
sql: SELECT projects.id FROM "projects" LEFT JOIN services ON services.project_id = projects.id AND services.type = 'PrometheusService' INNER JOIN namespaces ON namespaces.id = projects.namespace_id INNER JOIN cluster_groups ON cluster_groups.group_id = namespaces.id INNER JOIN clusters ON clusters.id = cluster_groups.cluster_id AND clusters.cluster_type = 2 INNER JOIN clusters_applications_prometheus ON clusters_applications_prometheus.cluster_id = clusters.id AND clusters_applications_prometheus.status IN (3, 5) WHERE (services.id IS NULL OR (services.active = FALSE AND services.properties = '{}')) GROUP BY projects.id
plan: https://explain.depesz.com/s/AuB5
Migratable::Cluster.instance_type.has_prometheus_application?
sql: SELECT 1 AS one FROM "clusters" INNER JOIN clusters_applications_prometheus ON clusters_applications_prometheus.cluster_id = clusters.id AND clusters_applications_prometheus.status IN (3, 5) WHERE "clusters"."cluster_type" = 1 LIMIT 1
plan: https://explain.depesz.com/s/LMeI
Migratable::PrometheusService.find_by(project_id: project_id)
sql: SELECT "services".* FROM "services" WHERE (services.type = 'PrometheusService') AND "services"."project_id" = 1 LIMIT 1
plan: https://explain.depesz.com/s/lCiY
Reports #14857 (closed)