Commit b47a3a40 authored by Peter Leitzen's avatar Peter Leitzen

Extract query variables into own module

parent fbbe5ccd
---
title: Extract into Gitlab::Prometheus::QueryVariables
merge_request: 23335
author:
type: other
......@@ -83,11 +83,8 @@ module Gitlab
end
def common_query_context(environment, timeframe_start:, timeframe_end:)
base_query_context(timeframe_start, timeframe_end).merge({
ci_environment_slug: environment.slug,
kube_namespace: environment.deployment_platform&.actual_namespace || '',
environment_filter: %{container_name!="POD",environment="#{environment.slug}"}
})
base_query_context(timeframe_start, timeframe_end)
.merge(QueryVariables.call(environment))
end
def base_query_context(timeframe_start, timeframe_end)
......
# frozen_string_literal: true
module Gitlab
module Prometheus
module QueryVariables
def self.call(environment)
{
ci_environment_slug: environment.slug,
kube_namespace: environment.deployment_platform&.actual_namespace || '',
environment_filter: %{container_name!="POD",environment="#{environment.slug}"}
}
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Prometheus::QueryVariables do
describe '.call' do
set(:environment) { create(:environment) }
let(:slug) { environment.slug }
subject { described_class.call(environment) }
it { is_expected.to include(ci_environment_slug: slug) }
it do
is_expected.to include(environment_filter:
%{container_name!="POD",environment="#{slug}"})
end
context 'without deployment platform' do
it { is_expected.to include(kube_namespace: '') }
end
context 'with deplyoment platform' do
let(:kube_namespace) { environment.deployment_platform.actual_namespace }
before do
create(:cluster, :provided_by_user, projects: [environment.project])
end
it { is_expected.to include(kube_namespace: kube_namespace) }
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