From feb94e8ea3b003938f5df963d3c61757ffe27bcb Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki <pawel@chojnacki.ws> Date: Tue, 1 Aug 2017 21:51:53 +0200 Subject: [PATCH] Move timeframe_start and timeframe_end to common query context --- .../queries/additional_metrics_deployment_query.rb | 9 ++++----- .../queries/additional_metrics_environment_query.rb | 9 +-------- .../prometheus/queries/query_additional_metrics.rb | 4 +++- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb b/lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb index 51d934b9ae2..69d055c901c 100644 --- a/lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb +++ b/lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb @@ -6,14 +6,13 @@ module Gitlab def query(deployment_id) Deployment.find_by(id: deployment_id).try do |deployment| - query_context = common_query_context(deployment.environment).merge( - { + query_metrics( + common_query_context( + deployment.environment, timeframe_start: (deployment.created_at - 30.minutes).to_f, timeframe_end: (deployment.created_at + 30.minutes).to_f - } + ) ) - - query_metrics(query_context) end end end diff --git a/lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb b/lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb index 9f798f5b892..580153556ea 100644 --- a/lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb +++ b/lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb @@ -6,14 +6,7 @@ module Gitlab def query(environment_id) Environment.find_by(id: environment_id).try do |environment| - query_context = common_query_context(environment).merge( - { - timeframe_start: 8.hours.ago.to_f, - timeframe_end: Time.now.to_f - } - ) - - query_metrics(query_context) + query_metrics(common_query_context(environment)) end end end diff --git a/lib/gitlab/prometheus/queries/query_additional_metrics.rb b/lib/gitlab/prometheus/queries/query_additional_metrics.rb index d96921a9ee7..d5f219ce6f9 100644 --- a/lib/gitlab/prometheus/queries/query_additional_metrics.rb +++ b/lib/gitlab/prometheus/queries/query_additional_metrics.rb @@ -71,8 +71,10 @@ module Gitlab result.select { |group| group.metrics.any? } end - def common_query_context(environment) + def common_query_context(environment, timeframe_start: 8.hours.ago.to_f, timeframe_end: Time.now.to_f) { + timeframe_start: timeframe_start, + timeframe_end: timeframe_end, ci_environment_slug: environment.slug, kube_namespace: environment.project.kubernetes_service&.actual_namespace || '', environment_filter: %{container_name!="POD",environment="#{environment.slug}"} -- GitLab