Skip to content

Commit

Permalink
correct prometheus port and scheme annotations if tls is enabled (#2782)
Browse files Browse the repository at this point in the history
* correct prometheus port and scheme annotations if tls is enabled
  • Loading branch information
rigalGit committed Aug 31, 2023
1 parent 37cafef commit d6223e6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2782.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
helm: Update prometheus port and scheme annotations if tls is enabled
```
6 changes: 6 additions & 0 deletions charts/consul/templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ spec:
{{- if (and .Values.global.metrics.enabled .Values.global.metrics.enableAgentMetrics) }}
"prometheus.io/scrape": "true"
"prometheus.io/path": "/v1/agent/metrics"
{{- if .Values.global.tls.enabled }}
"prometheus.io/port": "8501"
"prometheus.io/scheme": "https"
{{- else }}
"prometheus.io/port": "8500"
"prometheus.io/scheme": "http"
{{- end }}
{{- end }}
spec:
{{- if .Values.server.affinity }}
Expand Down
35 changes: 35 additions & 0 deletions charts/consul/test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,41 @@ load _helpers
[ "${actual}" = "/v1/agent/metrics" ]
}

@test "server/StatefulSet: when global.metrics.enableAgentMetrics=true, adds prometheus scheme=http annotation" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--set 'global.metrics.enabled=true' \
--set 'global.metrics.enableAgentMetrics=true' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."prometheus.io/scheme"' | tee /dev/stderr)
[ "${actual}" = "http" ]
}

@test "server/StatefulSet: when global.metrics.enableAgentMetrics=true and global.tls.enabled=true, adds prometheus port=8501 annotation" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--set 'global.metrics.enabled=true' \
--set 'global.metrics.enableAgentMetrics=true' \
--set 'global.tls.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."prometheus.io/port"' | tee /dev/stderr)
[ "${actual}" = "8501" ]
}

@test "server/StatefulSet: when global.metrics.enableAgentMetrics=true and global.tls.enabled=true, adds prometheus scheme=https annotation" {
cd `chart_dir`
local actual=$(helm template \
-s templates/server-statefulset.yaml \
--set 'global.metrics.enabled=true' \
--set 'global.metrics.enableAgentMetrics=true' \
--set 'global.tls.enabled=true' \
. | tee /dev/stderr |
yq -r '.spec.template.metadata.annotations."prometheus.io/scheme"' | tee /dev/stderr)
[ "${actual}" = "https" ]
}

#--------------------------------------------------------------------
# config-configmap

Expand Down

0 comments on commit d6223e6

Please sign in to comment.