fix(log): allow disabling the zap duplicate-message sampler#292
Open
armru wants to merge 2 commits into
Open
Conversation
armru
added a commit
to cloudnative-pg/cloudnative-pg
that referenced
this pull request
Jul 6, 2026
Track the latest commit of cloudnative-pg/machinery#292 in both modules, and promote klog to a direct dependency now that the manager tests import it. Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Member
Author
|
/test |
The controller-runtime zap builder installs a sampler on production-mode loggers that passes only the first 100 messages sharing the same (level, message) pair each second, and roughly 1 in 100 afterwards. That is fine for a controller's reconcile noise, but it silently drops records from processes whose output must be complete, such as the instance manager forwarding the PostgreSQL log stream, where every record is logged with the same message. Add a WithDisabledSampling option to Flags.ConfigureLogging. The builder only installs the sampler when the configured level does not enable zapcore.Level(-2), so the option passes a fully-verbose level to make the builder skip it and then restores the requested level by filtering the core. Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
NiccoloFei
force-pushed
the
feat/configurable-log-sampling
branch
from
July 24, 2026 13:59
1f63480 to
12f2c0c
Compare
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
NiccoloFei
force-pushed
the
feat/configurable-log-sampling
branch
from
July 24, 2026 14:55
785522e to
61daa1c
Compare
NiccoloFei
approved these changes
Jul 24, 2026
NiccoloFei
pushed a commit
to cloudnative-pg/cloudnative-pg
that referenced
this pull request
Jul 24, 2026
Replace the local machinery checkout with the pseudo-version of the commit opened as cloudnative-pg/machinery#292, so CI builds against the same code. To be bumped to the tagged machinery release once available. Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
NiccoloFei
pushed a commit
to cloudnative-pg/cloudnative-pg
that referenced
this pull request
Jul 24, 2026
Track the latest commit of cloudnative-pg/machinery#292 in both modules, and promote klog to a direct dependency now that the manager tests import it. Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
NiccoloFei
pushed a commit
to cloudnative-pg/cloudnative-pg
that referenced
this pull request
Jul 24, 2026
Replace the local machinery checkout with the pseudo-version of the commit opened as cloudnative-pg/machinery#292, so CI builds against the same code. To be bumped to the tagged machinery release once available. Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
NiccoloFei
pushed a commit
to cloudnative-pg/cloudnative-pg
that referenced
this pull request
Jul 24, 2026
Track the latest commit of cloudnative-pg/machinery#292 in both modules, and promote klog to a direct dependency now that the manager tests import it. Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
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.
The controller-runtime zap builder installs a sampler on every production-mode logger: only the first 100 messages sharing the same (level, message) pair each second get through, and roughly 1 in 100 afterwards. That is the right default for an operator, where a reconciliation storm can repeat the same message beyond any useful rate, but it is wrong for processes whose output must be complete. The CloudNativePG instance manager forwards every PostgreSQL log record with a constant message, so a burst of database activity (for example pgaudit under load) is silently collapsed by the sampler and most records never reach the pod's log stream (see cloudnative-pg/cloudnative-pg#10815).
This adds an optional
WithDisabledSampling()argument toFlags.ConfigureLogging. The builder only installs the sampler when the configured level does not enablezapcore.Level(-2), so the option passes a fully-verbose level to make the builder skip it and then restores the level the user asked for by filtering the core withzap.IncreaseLevel. Everything else stays in the controller-runtime builder's hands (encoder,--zap-*flags, destination), so the unsampled logger's output is identical to the default one. Callers that don't pass the option keep the sampler exactly as before.The new specs in
pkg/log/flags_test.goexercise the real path, from flag parsing throughConfigureLoggingto the--log-destinationfile: the default stays sampled, a 300-message burst is fully emitted with the option,--log-levelfiltering still applies, the trace level (where the builder never installs a sampler) keeps working, and the field-remapping flags are honored. The burst spec doubles as a tripwire if a future controller-runtime bump changes how the sampler is installed.