Commit ce83e563 authored by Pawel Chojnacki's avatar Pawel Chojnacki

add kube_namespace and standardize common variables for additional metrics queries

parent 0d52e59d
...@@ -6,12 +6,12 @@ module Gitlab ...@@ -6,12 +6,12 @@ module Gitlab
def query(deployment_id) def query(deployment_id)
Deployment.find_by(id: deployment_id).try do |deployment| Deployment.find_by(id: deployment_id).try do |deployment|
query_context = { query_context = common_query_context(deployment.environment).merge(
environment_slug: deployment.environment.slug, {
environment_filter: %{container_name!="POD",environment="#{deployment.environment.slug}"},
timeframe_start: (deployment.created_at - 30.minutes).to_f, timeframe_start: (deployment.created_at - 30.minutes).to_f,
timeframe_end: (deployment.created_at + 30.minutes).to_f timeframe_end: (deployment.created_at + 30.minutes).to_f
} }
)
query_metrics(query_context) query_metrics(query_context)
end end
......
...@@ -6,12 +6,12 @@ module Gitlab ...@@ -6,12 +6,12 @@ module Gitlab
def query(environment_id) def query(environment_id)
Environment.find_by(id: environment_id).try do |environment| Environment.find_by(id: environment_id).try do |environment|
query_context = { query_context = common_query_context(environment).merge(
environment_slug: environment.slug, {
environment_filter: %{container_name!="POD",environment="#{environment.slug}"},
timeframe_start: 8.hours.ago.to_f, timeframe_start: 8.hours.ago.to_f,
timeframe_end: Time.now.to_f timeframe_end: Time.now.to_f
} }
)
query_metrics(query_context) query_metrics(query_context)
end end
......
...@@ -67,6 +67,18 @@ module Gitlab ...@@ -67,6 +67,18 @@ module Gitlab
result.select { |group| group.metrics.any? } result.select { |group| group.metrics.any? }
end 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 end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment