diff options
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/prometheus/queries/query_additional_metrics.rb | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/gitlab/prometheus/queries/query_additional_metrics.rb b/lib/gitlab/prometheus/queries/query_additional_metrics.rb index 003e6aa6c87..5827c117556 100644 --- a/lib/gitlab/prometheus/queries/query_additional_metrics.rb +++ b/lib/gitlab/prometheus/queries/query_additional_metrics.rb @@ -42,15 +42,17 @@ module Gitlab end def process_query(context, query) - query_with_result = query.dup + query = query.dup result = if query.key?(:query_range) - client_query_range(query[:query_range] % context, start: context[:timeframe_start], stop: context[:timeframe_end]) + query[:query_range] %= context + client_query_range(query[:query_range], start: context[:timeframe_start], stop: context[:timeframe_end]) else - client_query(query[:query] % context, time: context[:timeframe_end]) + query[:query] %= context + client_query(query[:query], time: context[:timeframe_end]) end - query_with_result[:result] = result&.map(&:deep_symbolize_keys) - query_with_result + query[:result] = result&.map(&:deep_symbolize_keys) + query end def available_metrics @@ -69,15 +71,11 @@ module Gitlab 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 = { + kube_namespace: environment.project.kubernetes_service&.actual_namespace || '', environment_filter: %{container_name!="POD",environment="#{environment.slug}"} } - variables.merge(macros) end end end |