Commit 8587e09e authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '7527-ci-variables-are-not-parameterized-for-alerting-rules-ce' into 'master'

CE Backport: Extract Gitlab::Prometheus::QueryVariables

See merge request gitlab-org/gitlab-ce!23335
parents 4aa61105 af798427
No related merge requests found
...@@ -83,11 +83,8 @@ module Gitlab ...@@ -83,11 +83,8 @@ module Gitlab
end end
def common_query_context(environment, timeframe_start:, timeframe_end:) def common_query_context(environment, timeframe_start:, timeframe_end:)
base_query_context(timeframe_start, timeframe_end).merge({ base_query_context(timeframe_start, timeframe_end)
ci_environment_slug: environment.slug, .merge(QueryVariables.call(environment))
kube_namespace: environment.deployment_platform&.actual_namespace || '',
environment_filter: %{container_name!="POD",environment="#{environment.slug}"}
})
end end
def base_query_context(timeframe_start, timeframe_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