Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of [net-7710] don't overwrite prometheus path annotation if it's already been specified into release/1.2.x #3886

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changelog/3846.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```release-note:improvement
helm: only create the default Prometheus path annotation when it's not already specified within the component-specific
annotations. For example if the `client.annotations` value sets prometheus.io/path annotation, don't overwrite it with
the default value.
```
2 changes: 2 additions & 0 deletions charts/consul/templates/client-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ spec:
{{- end }}
{{- if (and .Values.global.metrics.enabled .Values.global.metrics.enableAgentMetrics) }}
"prometheus.io/scrape": "true"
{{- if not (hasKey (default "" .Values.client.annotations | fromYaml) "prometheus.io/path")}}
"prometheus.io/path": "/v1/agent/metrics"
{{- end }}
"prometheus.io/port": "8500"
{{- end }}
spec:
Expand Down
2 changes: 2 additions & 0 deletions charts/consul/templates/ingress-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ spec:
{{- end }}
{{- if (and $root.Values.global.metrics.enabled $root.Values.global.metrics.enableGatewayMetrics) }}
"prometheus.io/scrape": "true"
{{- if not (hasKey (default "" $defaults.annotations | fromYaml) "prometheus.io/path")}}
"prometheus.io/path": "/metrics"
{{- end }}
"prometheus.io/port": "20200"
{{- end }}
{{- if $defaults.annotations }}
Expand Down
2 changes: 2 additions & 0 deletions charts/consul/templates/mesh-gateway-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ spec:
{{- end }}
{{- if (and .Values.global.metrics.enabled .Values.global.metrics.enableGatewayMetrics) }}
"prometheus.io/scrape": "true"
{{- if not (hasKey (default "" .Values.meshGateway.annotations | fromYaml) "prometheus.io/path")}}
"prometheus.io/path": "/metrics"
{{- end }}
"prometheus.io/port": "20200"
{{- end }}
{{- if .Values.meshGateway.annotations }}
Expand Down
2 changes: 2 additions & 0 deletions charts/consul/templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ spec:
{{- if (and .Values.global.metrics.enabled .Values.global.metrics.enableAgentMetrics) }}
{{- if not .Values.global.metrics.datadog.openMetricsPrometheus.enabled }}
"prometheus.io/scrape": "true"
{{- if not (hasKey (default "" .Values.server.annotations | fromYaml) "prometheus.io/path")}}
"prometheus.io/path": "/v1/agent/metrics"
{{- end }}
{{- if .Values.global.tls.enabled }}
"prometheus.io/port": "8501"
"prometheus.io/scheme": "https"
Expand Down
2 changes: 2 additions & 0 deletions charts/consul/templates/terminating-gateways-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ spec:
{{- end }}
{{- if (and $root.Values.global.metrics.enabled $root.Values.global.metrics.enableGatewayMetrics) }}
"prometheus.io/scrape": "true"
{{- if not (hasKey (default "" $defaults.annotations | fromYaml) "prometheus.io/path")}}
"prometheus.io/path": "/metrics"
{{- end }}
"prometheus.io/port": "20200"
{{- end }}
{{- if $defaults.annotations }}
Expand Down
13 changes: 13 additions & 0 deletions charts/consul/test/unit/client-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,19 @@ load _helpers
[ "${actual}" = "/v1/agent/metrics" ]
}

@test "client/DaemonSet: when global.metrics.enableAgentMetrics=true, and client annotation for prometheus path is specified, it uses the client annotation rather than default." {
cd `chart_dir`
local actual=$(helm template \
-s templates/client-daemonset.yaml \
--set 'client.enabled=true' \
--set 'global.metrics.enabled=true' \
--set 'global.metrics.enableAgentMetrics=true' \
--set 'client.annotations=prometheus.io/path: /anew/path' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."prometheus.io/path"' | tee /dev/stderr)
[ "${actual}" = "/anew/path" ]
}

@test "client/DaemonSet: when global.metrics.enableAgentMetrics=true, sets telemetry flag" {
cd `chart_dir`
local actual=$(helm template \
Expand Down
13 changes: 13 additions & 0 deletions charts/consul/test/unit/ingress-gateways-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,19 @@ load _helpers
[ "${actual}" = "/metrics" ]
}

@test "ingressGateways/Deployment: when global.metrics.enabled=true, and ingress gateways annotation for prometheus path is specified, it uses the specified annotation rather than default." {
cd `chart_dir`
local actual=$(helm template \
-s templates/ingress-gateways-deployment.yaml \
--set 'ingressGateways.enabled=true' \
--set 'connectInject.enabled=true' \
--set 'global.metrics.enabled=true' \
--set 'ingressGateways.defaults.annotations=prometheus.io/path: /anew/path' \
. | tee /dev/stderr |
yq -s -r '.[0].spec.template.metadata.annotations."prometheus.io/path"' | tee /dev/stderr)
[ "${actual}" = "/anew/path" ]
}

@test "ingressGateways/Deployment: when global.metrics.enableGatewayMetrics=false, does not set proxy setting" {
cd `chart_dir`
local object=$(helm template \
Expand Down
13 changes: 13 additions & 0 deletions charts/consul/test/unit/mesh-gateway-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ key2: value2' \
[ "${actual}" = "/metrics" ]
}

@test "meshGateway/Deployment: when global.metrics.enabled=true, and mesh gateways annotation for prometheus path is specified, it uses the specified annotation rather than default." {
cd `chart_dir`
local actual=$(helm template \
-s templates/mesh-gateway-deployment.yaml \
--set 'meshGateway.enabled=true' \
--set 'connectInject.enabled=true' \
--set 'global.metrics.enabled=true' \
--set 'meshGateway.annotations=prometheus.io/path: /anew/path' \
. | tee /dev/stderr |
yq -s -r '.[0].spec.template.metadata.annotations."prometheus.io/path"' | tee /dev/stderr)
[ "${actual}" = "/anew/path" ]
}

@test "meshGateway/Deployment: when global.metrics.enableGatewayMetrics=false, does not set annotations" {
cd `chart_dir`
local object=$(helm template \
Expand Down
13 changes: 13 additions & 0 deletions charts/consul/test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,19 @@ load _helpers
[ "${actual}" = "/v1/agent/metrics" ]
}

@test "server/Statefulset: when global.metrics.enabled=true, and server annotation for prometheus path is specified, it uses the specified annotation rather than default." {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--set 'global.metrics.enabled=true' \
--set 'global.metrics.enableAgentMetrics=true' \
--set 'server.annotations=prometheus.io/path: /anew/path' \
. | tee /dev/stderr |
yq -s -r '.[0].spec.template.metadata.annotations."prometheus.io/path"' | tee /dev/stderr)
[ "${actual}" = "/anew/path" ]
}


@test "server/StatefulSet: when global.metrics.enableAgentMetrics=true, adds prometheus scheme=http annotation" {
cd `chart_dir`
local actual=$(helm template \
Expand Down
13 changes: 13 additions & 0 deletions charts/consul/test/unit/terminating-gateways-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,19 @@ load _helpers
[ "${actual}" = "/metrics" ]
}

@test "terminatingGateways/Deployment: when global.metrics.enabled=true, and terminating gateways annotation for prometheus path is specified, it uses the specified annotation rather than default." {
cd `chart_dir`
local actual=$(helm template \
-s templates/terminating-gateways-deployment.yaml \
--set 'terminatingGateways.enabled=true' \
--set 'connectInject.enabled=true' \
--set 'global.metrics.enabled=true' \
--set 'terminatingGateways.defaults.annotations=prometheus.io/path: /anew/path' \
. | tee /dev/stderr |
yq -s -r '.[0].spec.template.metadata.annotations."prometheus.io/path"' | tee /dev/stderr)
[ "${actual}" = "/anew/path" ]
}

@test "terminatingGateways/Deployment: when global.metrics.enableGatewayMetrics=false, does not set prometheus annotations" {
cd `chart_dir`
local object=$(helm template \
Expand Down
Loading