Skip to content

Optimise reverted post deployment migration: PatchPrometheusServicesForSharedClusterApplications

What does this MR do?

This MR optimize reverted due to timeout on staging !22935 (merged) migration so it could be merged again.

Conformity

Database

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

gitlab.com plan: https://explain.depesz.com/s/vUiR

  • planning: 6.377 ms
  • execution: 12304.816 ms

staging.gitlab.com plan: https://explain.depesz.com/s/bKow

  • planning: 2.892 ms
  • execution: 54.493 s
  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

gitlab.com plan: https://explain.depesz.com/s/AuB5

  • planning: 6.714 ms
  • execution: 696.457 ms

staging.gitlab.com plan: https://explain.depesz.com/s/0AyA

  • planning: 7.191 ms
  • execution: 15.006 s
  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

gitlab.com plan: https://explain.depesz.com/s/LMeI

  • planning: 0.228 ms
  • execution: 12.504 ms

staging.gitlab.com plan: https://explain.depesz.com/s/RsIm

  • planning: 1.167 ms
  • execution: 568.066 ms
  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

gitlab.com plan: https://explain.depesz.com/s/lCiY

  • planning: 0.423 ms
  • execution: 0.037 ms

staging.gitlab.com plan: https://explain.depesz.com/s/f497

  • planning: 1.694 ms
  • execution: 0.068 ms
Edited by 🤖 GitLab Bot 🤖

Merge request reports