Commit 7a1ec50d authored by Kirstie Cook's avatar Kirstie Cook Committed by Achilleas Pipinellis

Support more query variables in custom dashboards per project

parent 8a3788a2
---
title: Support more query variables in custom dashboards per project
merge_request: 25732
author:
type: added
...@@ -155,10 +155,17 @@ Multiple metrics can be displayed on the same chart if the fields **Name**, **Ty ...@@ -155,10 +155,17 @@ Multiple metrics can be displayed on the same chart if the fields **Name**, **Ty
#### Query Variables #### Query Variables
GitLab supports a limited set of [CI variables](../../../ci/variables/README.md) in the Prometheus query. This is particularly useful for identifying a specific environment, for example with `CI_ENVIRONMENT_SLUG`. The supported variables are: GitLab supports a limited set of [CI variables](../../../ci/variables/README.md) in the Prometheus query. This is particularly useful for identifying a specific environment, for example with `ci_environment_slug`. The supported variables are:
- CI_ENVIRONMENT_SLUG - `ci_environment_slug`
- KUBE_NAMESPACE - `kube_namespace`
- `ci_project_name`
- `ci_project_namespace`
- `ci_project_path`
- `ci_environment_name`
NOTE: **Note:**
Variables for Prometheus queries must be lowercase.
There are 2 methods to specify a variable in a query or dashboard: There are 2 methods to specify a variable in a query or dashboard:
......
...@@ -7,7 +7,11 @@ module Gitlab ...@@ -7,7 +7,11 @@ module Gitlab
{ {
ci_environment_slug: environment.slug, ci_environment_slug: environment.slug,
kube_namespace: environment.deployment_namespace || '', kube_namespace: environment.deployment_namespace || '',
environment_filter: %{container_name!="POD",environment="#{environment.slug}"} environment_filter: %{container_name!="POD",environment="#{environment.slug}"},
ci_project_name: environment.project.name,
ci_project_namespace: environment.project.namespace.name,
ci_project_path: environment.project.full_path,
ci_environment_name: environment.name
} }
end end
end end
......
...@@ -11,6 +11,10 @@ describe Gitlab::Prometheus::QueryVariables do ...@@ -11,6 +11,10 @@ describe Gitlab::Prometheus::QueryVariables do
subject { described_class.call(environment) } subject { described_class.call(environment) }
it { is_expected.to include(ci_environment_slug: slug) } it { is_expected.to include(ci_environment_slug: slug) }
it { is_expected.to include(ci_project_name: project.name) }
it { is_expected.to include(ci_project_namespace: project.namespace.name) }
it { is_expected.to include(ci_project_path: project.full_path) }
it { is_expected.to include(ci_environment_name: environment.name) }
it do it do
is_expected.to include(environment_filter: is_expected.to include(environment_filter:
......
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