-
Notifications
You must be signed in to change notification settings - Fork 0
fix(truvami-monitoring)!: make Alertmanager optional and default it off #70
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
base: main
Are you sure you want to change the base?
Changes from all commits
3b0d1c6
46904cf
57a8e8d
ba4ca4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| {{- if .Values.alertmanager.enabled }} | ||
| {{/* | ||
| Service fronting this release's Alertmanager pods. | ||
|
|
||
| The Prometheus CR's spec.alerting.alertmanagers[] entry addresses Alertmanager | ||
| by *Service* name - prometheus-operator resolves that Service's Endpoints to | ||
| build the alerting targets. Without this object the reference dangles and | ||
| Prometheus reports zero activeAlertmanagers, so every firing alert is silently | ||
| dropped. The operator's own `alertmanager-operated` Service is not a substitute: | ||
| it selects `app.kubernetes.io/name: alertmanager` across the whole namespace, so | ||
| where several Alertmanager CRs coexist it would fan alerts out to all of them. | ||
|
|
||
| The `alertmanager` label is set by prometheus-operator on the pods it creates | ||
| for an Alertmanager CR, and carries that CR's name - so this selector matches | ||
| only the Alertmanager owned by this release. | ||
| */}} | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: {{ include "truvami-monitoring.fullname" . }} | ||
| namespace: {{ .Release.Namespace | quote }} | ||
| labels: | ||
| {{- include "truvami-monitoring.labels" . | nindent 4 }} | ||
| app.kubernetes.io/component: alertmanager | ||
| spec: | ||
| type: ClusterIP | ||
| # Alertmanager gossips over the mesh ports; peers must be discoverable before | ||
| # they are Ready, and Prometheus should keep addressing a peer that is still | ||
| # settling rather than lose its only alerting target during a rollout. | ||
| publishNotReadyAddresses: true | ||
| selector: | ||
| alertmanager: {{ include "truvami-monitoring.fullname" . }} | ||
| app.kubernetes.io/name: alertmanager | ||
| ports: | ||
| - name: {{ .Values.alertmanager.portName | default "web" }} | ||
| port: 9093 | ||
| targetPort: {{ .Values.alertmanager.portName | default "web" }} | ||
| protocol: TCP | ||
| {{- end }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,11 +84,17 @@ spec: | |
| serviceMonitorNamespaceSelector: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: {{ .Release.Namespace }} | ||
| {{- if .Values.alertmanager.enabled }} | ||
| alerting: | ||
| alertmanagers: | ||
| # Addresses the Service created by templates/alertmanager-service.yaml. | ||
| # Only emitted when the Alertmanager is enabled - pointing Prometheus at a | ||
| # Service that is not rendered leaves it with zero activeAlertmanagers and | ||
| # silently discards every firing alert. | ||
| - namespace: {{ .Release.Namespace }} | ||
| name: "{{ include "truvami-monitoring.fullname" . }}" | ||
| port: web | ||
| port: {{ .Values.alertmanager.portName | default "web" }} | ||
| {{- end }} | ||
| enableRemoteWriteReceiver: {{ .Values.prometheus.enableRemoteWriteReceiver | default "false" }} | ||
| {{- if .Values.thanos.enabled }} | ||
| thanos: | ||
|
|
@@ -106,12 +112,48 @@ spec: | |
| {{- end }} | ||
| {{- end }} | ||
|
|
||
| {{- if .Values.alertmanager.enabled }} | ||
| --- | ||
| apiVersion: monitoring.coreos.com/v1 | ||
| kind: Alertmanager | ||
| metadata: | ||
| name: "{{ include "truvami-monitoring.fullname" . }}" | ||
| labels: | ||
| {{- include "truvami-monitoring.labels" . | nindent 4 }} | ||
| spec: | ||
| replicas: 2 | ||
| configSecret: "{{ include "truvami-monitoring.fullname" . }}-alertmanager-config" | ||
| replicas: {{ .Values.alertmanager.replicas | default 2 }} | ||
| portName: {{ .Values.alertmanager.portName | default "web" }} | ||
| {{- with .Values.alertmanager.retention }} | ||
| retention: {{ . | quote }} | ||
| {{- end }} | ||
| # Use the AlertmanagerConfig rendered by templates/alertmanager-config.yaml as | ||
| # this Alertmanager's top-level configuration. | ||
| # | ||
| # This replaces the previous `configSecret` reference, which named a Secret | ||
| # ("<fullname>-alertmanager-config") that no template in this chart has ever | ||
| # created. With that Secret absent, prometheus-operator fell back to its | ||
| # built-in default configuration, whose root route sends everything to the | ||
| # "null" receiver - so alerts were accepted and then discarded. | ||
| alertmanagerConfiguration: | ||
| name: {{ include "truvami-monitoring.fullname" . }}-config | ||
| # Additionally select any AlertmanagerConfig in this namespace that opts in, | ||
| # so teams can attach extra routes/receivers without editing this chart. | ||
| # Previously unset, which meant zero AlertmanagerConfigs were ever selected. | ||
| # | ||
| # An explicitly configured empty map is a meaningful value here - | ||
| # matchLabels: {} selects *every* AlertmanagerConfig in the namespace - so it | ||
| # must be distinguishable from "not configured". | ||
| # | ||
| # `default` cannot do that (it treats {} as empty), and neither can `hasKey`: | ||
| # the key is always present because values.yaml declares it. So the declared | ||
| # default is null, and only null means "not configured" - Helm lets a user | ||
| # map replace a null base wholesale, whereas a non-empty default map would be | ||
| # merged with the user's value and could never be reduced back to empty. | ||
| {{- $configSelector := .Values.alertmanager.configSelectorLabels }} | ||
| {{- if kindIs "invalid" $configSelector }} | ||
| {{- $configSelector = dict "truvami.com/alertmanager-config" "true" }} | ||
| {{- end }} | ||
| alertmanagerConfigSelector: | ||
| matchLabels: {{- toYaml $configSelector | nindent 6 }} | ||
|
Comment on lines
+152
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
values="$(mktemp)"
trap 'rm -f "$values"' EXIT
cat >"$values" <<'EOF'
alertmanager:
enabled: true
configSelectorLabels: invalid
EOF
if helm template review charts/truvami-monitoring -f "$values" >/dev/null 2>&1; then
echo "Non-map configSelectorLabels was accepted" >&2
exit 1
fiRepository: truvami/helm Length of output: 150 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
# Locate the relevant chart files and show the surrounding template code.
git ls-files charts/truvami-monitoring | sed -n '1,200p'
printf '\n--- template slice ---\n'
sed -n '130,190p' charts/truvami-monitoring/templates/prometheus.yaml
printf '\n--- values references ---\n'
rg -n "configSelectorLabels|alertmanager\.configSelectorLabels|alertmanager:" charts/truvami-monitoring -nRepository: truvami/helm Length of output: 6267 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
# Probe rendering behavior for several selector shapes to see what actually fails.
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
cases=(
"null|alertmanager:\n enabled: true\n configSelectorLabels: null\n"
"empty-map|alertmanager:\n enabled: true\n configSelectorLabels: {}\n"
"string|alertmanager:\n enabled: true\n configSelectorLabels: invalid\n"
"list|alertmanager:\n enabled: true\n configSelectorLabels:\n - a\n - b\n"
)
for item in "${cases[@]}"; do
name="${item%%|*}"
body="${item#*|}"
file="$tmpdir/$name.yaml"
printf '%b' "$body" >"$file"
printf '\n== %s ==\n' "$name"
if out="$(helm template review charts/truvami-monitoring -f "$file" 2>&1)"; then
echo "OK"
printf '%s\n' "$out" | sed -n '1,40p'
else
echo "FAIL"
printf '%s\n' "$out" | sed -n '1,80p'
fi
doneRepository: truvami/helm Length of output: 381 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
# Inspect docs/defaults to see whether the field is meant to be a map or string.
rg -n "configSelectorLabels|matchLabels|AlertmanagerConfig" README.md charts/truvami-monitoring -g '!**/Chart.lock'Repository: truvami/helm Length of output: 2954 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
# Show any chart schema or template-side validation relevant to this field.
for f in charts/truvami-monitoring/values.schema.json charts/truvami-monitoring/values.yaml charts/truvami-monitoring/templates/prometheus.yaml; do
if [ -f "$f" ]; then
echo "--- $f ---"
wc -l "$f"
sed -n '1,240p' "$f" | sed -n '/configSelectorLabels/,+40p'
fi
doneRepository: truvami/helm Length of output: 839 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
echo "--- values.schema.json ---"
cat -n charts/truvami-monitoring/values.schema.json
echo
echo "--- values.yaml around configSelectorLabels ---"
sed -n '404,428p' charts/truvami-monitoring/values.yaml
echo
echo "--- README table entry ---"
sed -n '14,26p' charts/truvami-monitoring/README.mdRepository: truvami/helm Length of output: 2105 Reject non-map
🤖 Prompt for AI Agents |
||
| resources: {{ toYaml .Values.alertmanager.resources | default "{}" | nindent 4 }} | ||
| {{- end }} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Document
configSelectorLabelsas a map, not a string.The value accepts
nil,{}, or a label map. Documenting it asstringconflicts withvalues.yamland can lead users to render an invalidmatchLabelsvalue.Proposed documentation fix
📝 Committable suggestion
🤖 Prompt for AI Agents