Skip to content

Commit

Permalink
[net-7710] don't overwrite prometheus path annotation if it's already…
Browse files Browse the repository at this point in the history
… been specified (#3846)

don't overwrite prometheus path annotation if it's already been specified
  • Loading branch information
ndhanushkodi authored Apr 5, 2024
1 parent 8285624 commit fc7a832
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 0 deletions.
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 @@ -93,7 +93,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 @@ -132,7 +132,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 @@ -78,7 +78,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 @@ -134,7 +134,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 @@ -101,7 +101,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 @@ -588,6 +588,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

0 comments on commit fc7a832

Please sign in to comment.