Skip to content

Patch Prometheus services records

What does this MR do?

This MR provides database migration which will create missing PrometheusServicerecord for all projects which belongs to cluster with Prometheus Application installed.

Conformity

Database

Affected rows on gitlab.com 5621 (updated: 22 and inserted: 5599)

Plans

  1. 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

  1. 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

  1. 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

  1. 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)

Edited by 🤖 GitLab Bot 🤖

Merge request reports