diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-07-31 13:29:00 +0200 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-07-31 16:32:26 +0200 |
commit | 6df5bd8b848322aa3e2ce5fd8cad0e2a20b06000 (patch) | |
tree | 9cce83ce235bf1982acd8bd9db6cdc8e8ab4ff48 /lib | |
parent | ce83e5635d1903cfadf4e2d9a7088b505f6c28ff (diff) | |
download | gitlab-ce-6df5bd8b848322aa3e2ce5fd8cad0e2a20b06000.tar.gz |
Context handling and tests cleanup + simple test kube_namespace context test
Diffstat (limited to 'lib')
-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 |