fix(collector): roll pods when Prometheus config changes#387
Closed
musa-asad wants to merge 1 commit into
Closed
Conversation
The pod-template restart-trigger sha256 was computed from Spec.Config only, so a change to Spec.Prometheus (rendered into a separate ConfigMap) left the pod template byte-identical and the workload controller did not roll the pods. Fold the serialized Spec.Prometheus (PrometheusConfig.Yaml()) into the hash input when it is non-empty, so a Prometheus-only change bumps the pod-template annotation and triggers a rolling restart, matching agent-config behavior. When no Prometheus config is set the hash input is byte-identical to the agent config alone, leaving non-Prometheus agents unaffected.
Contributor
Author
|
Merged into PR #386 — single PR for all operator target allocator fixes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Roll agent pods when the Prometheus scrape config changes.
The pod-template restart-trigger
sha256was computed frominstance.Spec.Configonly. A change to
instance.Spec.Prometheusis rendered into a separateConfigMap, so the pod template stayed byte-identical and the workload controller
never rolled the pods. As a result, editing only the Prometheus scrape config did
not take effect until the pods were restarted by some other means — whereas an
agent-config (
Spec.Config) change correctly rolls them.This fixes that asymmetry so a Prometheus-only change triggers a rolling restart,
matching agent-config behavior, while leaving non-Prometheus agents unaffected.
Changes
internal/manifests/collector/annotations.go:Annotations()(line ~31): hash input changed fromgetConfigMapSHA(instance.Spec.Config)→getConfigMapSHA(configHashInput(instance)).PodAnnotations()(line ~54, the map applied to the pod template): same change.configHashInput()helper (lines ~58–72): returnsinstance.Spec.Config, andwhen
!instance.Spec.Prometheus.IsEmpty()appends the serializedinstance.Spec.Prometheus.Yaml()(the existingPrometheusConfig.Yaml()serializer).The
IsEmpty()guard keeps the hash input byte-identical to the agent config alonefor non-Prometheus agents, so they are unaffected: with no Prometheus config the hash
is still
sha256(Spec.Config)(sha256("test") = 9f86d081…, unchanged). Thepre-existing
TestDefaultAnnotations/TestUserAnnotations(which assert that same9f86d081…value) continue to pass.RELEASE_NOTES: added a Bug Fixes entry noting Prometheus-config changes now trigger arolling restart.
Test Output
Scenario reference — Test 2 (Prometheus-config tweak must roll pods)
From a DaemonSet doing Prometheus scraping, a small tweak to the Prometheus scrape
config (e.g. changing a relabel
replacementvalue) must cause the agent pods to rollso the new config takes effect. The
configuration-valuesfor this scenario:Before / after (live test EKS cluster, no-TA DaemonSet)
A Prometheus-only change (
value2 → value3) on the fixed operator image:BEFORE the fix, the same Prometheus-only tweak changed the Prometheus ConfigMap hash
but left
podTemplateShaand the pod uids unchanged (no restart). AFTER the fix thePrometheus ConfigMap hash changes and the pod-template hash changes and the pods
roll (all-new uids, generation bump).
No regression — a subsequent agent-config change (
agent.debug=true) still rolls thepods (generation
65→66,podTemplateShachanges, all-new uids), exactly as before.Unit tests
TestPrometheusConfigChangeBumpsHash— hash is stable when nothing changes andchanges when only
Spec.Prometheuschanges.TestEmptyPrometheusHashUnchanged— with no Prometheus config the hash isbyte-identical to
sha256(Spec.Config)(9f86d081…), proving non-Prometheus agentsare unaffected.
Test pass matrix (full Prometheus-on-EKS scenario suite)