summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2019-07-04 17:26:37 +1200
committerThong Kuah <tkuah@gitlab.com>2019-07-08 09:14:37 +1200
commitc85d6b0c744e9a971fafdf58328f907dfa0de127 (patch)
tree5d65b622c5bc40ec0cc0deb66be33edb660383a7
parent25ba11a2aad9571e4759cdc711199634e3392c5b (diff)
downloadgitlab-ce-c85d6b0c744e9a971fafdf58328f907dfa0de127.tar.gz
Restore fallback to deployment_platform_cluster
In 12.2 we will remove this fallback.
-rw-r--r--app/models/deployment_metrics.rb13
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb7
-rw-r--r--spec/models/deployment_metrics_spec.rb12
3 files changed, 28 insertions, 4 deletions
diff --git a/app/models/deployment_metrics.rb b/app/models/deployment_metrics.rb
index 2056c8bc59c..cfe762ca25e 100644
--- a/app/models/deployment_metrics.rb
+++ b/app/models/deployment_metrics.rb
@@ -44,7 +44,18 @@ class DeploymentMetrics
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
+ #
+ # Removal issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/64105
def cluster_prometheus
- cluster.application_prometheus if cluster&.application_prometheus_available?
+ cluster_with_fallback = cluster || deployment_platform_cluster
+
+ cluster_with_fallback.application_prometheus if cluster_with_fallback&.application_prometheus_available?
+ end
+
+ def deployment_platform_cluster
+ deployment.environment.deployment_platform&.cluster
end
end
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index ea160a21955..2a6736018ea 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -887,9 +887,10 @@ describe Projects::MergeRequestsController do
environment2 = create(:environment, project: forked)
create(:deployment, :succeed, environment: environment2, sha: sha, ref: 'master', deployable: build)
- # TODO address the last 5 queries
- # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63952
- leeway = 5
+ # TODO address the last 11 queries
+ # See https://gitlab.com/gitlab-org/gitlab-ce/issues/63952 (5 queries)
+ # And https://gitlab.com/gitlab-org/gitlab-ce/issues/64105 (6 queries)
+ leeway = 11
expect { get_ci_environments_status }.not_to exceed_all_query_limit(control_count + leeway)
end
diff --git a/spec/models/deployment_metrics_spec.rb b/spec/models/deployment_metrics_spec.rb
index 7c574a8b6c8..0aadb1f3a5e 100644
--- a/spec/models/deployment_metrics_spec.rb
+++ b/spec/models/deployment_metrics_spec.rb
@@ -49,6 +49,18 @@ describe DeploymentMetrics 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