summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb12
-rw-r--r--lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb12
-rw-r--r--lib/gitlab/prometheus/queries/query_additional_metrics.rb12
3 files changed, 24 insertions, 12 deletions
diff --git a/lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb b/lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
index 67c69d9ccf3..51d934b9ae2 100644
--- a/lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
+++ b/lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb
@@ -6,12 +6,12 @@ module Gitlab
def query(deployment_id)
Deployment.find_by(id: deployment_id).try do |deployment|
- query_context = {
- environment_slug: deployment.environment.slug,
- environment_filter: %{container_name!="POD",environment="#{deployment.environment.slug}"},
- timeframe_start: (deployment.created_at - 30.minutes).to_f,
- timeframe_end: (deployment.created_at + 30.minutes).to_f
- }
+ query_context = common_query_context(deployment.environment).merge(
+ {
+ timeframe_start: (deployment.created_at - 30.minutes).to_f,
+ timeframe_end: (deployment.created_at + 30.minutes).to_f
+ }
+ )
query_metrics(query_context)
end
diff --git a/lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb b/lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
index b5a679ddd79..9f798f5b892 100644
--- a/lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
+++ b/lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
@@ -6,12 +6,12 @@ module Gitlab
def query(environment_id)
Environment.find_by(id: environment_id).try do |environment|
- query_context = {
- environment_slug: environment.slug,
- environment_filter: %{container_name!="POD",environment="#{environment.slug}"},
- timeframe_start: 8.hours.ago.to_f,
- timeframe_end: Time.now.to_f
- }
+ query_context = common_query_context(environment).merge(
+ {
+ timeframe_start: 8.hours.ago.to_f,
+ timeframe_end: Time.now.to_f
+ }
+ )
query_metrics(query_context)
end
diff --git a/lib/gitlab/prometheus/queries/query_additional_metrics.rb b/lib/gitlab/prometheus/queries/query_additional_metrics.rb
index e44be770544..003e6aa6c87 100644
--- a/lib/gitlab/prometheus/queries/query_additional_metrics.rb
+++ b/lib/gitlab/prometheus/queries/query_additional_metrics.rb
@@ -67,6 +67,18 @@ module Gitlab
result.select { |group| group.metrics.any? }
end
+
+ def common_query_context(environment)
+ variables = {
+ ci_environment_slug: environment.slug,
+ kube_namespace: environment.project.kubernetes_service.actual_namespace,
+ }.flat_map { |k, v| [[k, v], [k.upcase, v]] }.to_h
+
+ macros = {
+ environment_filter: %{container_name!="POD",environment="#{environment.slug}"}
+ }
+ variables.merge(macros)
+ end
end
end
end