From 1668f40f430c656ed9c20898605db21a66cb5937 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 1 Jul 2019 20:24:20 +1200 Subject: [PATCH] Remove fallback to project.deployment_platform This improves query performance of MergeRequestsController#ci_environments_status a lot. However this means old deployments that deployed to kubernetes clusters with prometheus installations will no longer show performance metrics as we cannot backfill cluster_id from deployment_platform with certainty (clusters may be edited/added/deleted, which changes the results of deployment_platform). --- app/models/deployment.rb | 7 +------ changelogs/unreleased/63475-fix-n-1.yml | 5 +++++ spec/models/deployment_spec.rb | 12 ------------ 3 files changed, 6 insertions(+), 18 deletions(-) create mode 100644 changelogs/unreleased/63475-fix-n-1.yml diff --git a/app/models/deployment.rb b/app/models/deployment.rb index a8f5642f726..3b31e7b1333 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -206,13 +206,8 @@ class Deployment < ApplicationRecord end end - # TODO remove fallback case to deployment_platform_cluster. - # Otherwise we will continue to pay the performance penalty described in - # https://gitlab.com/gitlab-org/gitlab-ce/issues/63475 def cluster_prometheus - cluster_with_fallback = cluster || deployment_platform_cluster - - cluster_with_fallback.application_prometheus if cluster_with_fallback&.application_prometheus_available? + cluster.application_prometheus if cluster&.application_prometheus_available? end def ref_path diff --git a/changelogs/unreleased/63475-fix-n-1.yml b/changelogs/unreleased/63475-fix-n-1.yml new file mode 100644 index 00000000000..3ed825290fd --- /dev/null +++ b/changelogs/unreleased/63475-fix-n-1.yml @@ -0,0 +1,5 @@ +--- +title: Improve performance of MergeRequestsController#ci_environment_status endpoint +merge_request: 30224 +author: +type: performance diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index 713fb647708..a926e1913a7 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -341,18 +341,6 @@ describe Deployment do it { is_expected.to be_truthy } end - - context 'fallback deployment platform' do - let(:cluster) { create(:cluster, :provided_by_user, environment_scope: '*', projects: [deployment.project]) } - let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) } - - before do - expect(deployment.project).to receive(:deployment_platform).and_return(cluster.platform) - expect(cluster.application_prometheus).to receive(:can_query?).and_return(true) - end - - it { is_expected.to be_truthy } - end end end