Skip to content

feat(log): allow disabling the zap duplicate-message sampler - #292

Merged
mnencia merged 4 commits into
mainfrom
feat/configurable-log-sampling
Jul 28, 2026
Merged

mnencia merged 4 commits into
mainfrom
feat/configurable-log-sampling

Conversation

@armru

@armru armru commented Jul 6, 2026 •

Copy link
Copy Markdown
Member

The controller-runtime zap builder installs a duplicate-message sampler on every production-mode logger, letting through only the first 100 messages sharing a (level, message) pair each second and roughly 1 in 100 afterwards. That's the right default for an operator reconciliation loop, but it silently drops most records for a process whose output must be complete, such as the CloudNativePG instance manager forwarding the PostgreSQL log stream under a burst of pgaudit activity.

This adds an optional WithDisabledSampling() argument to Flags.ConfigureLogging. It passes a fully-verbose level to the controller-runtime builder so it skips installing the sampler, then restores the caller's requested level with zap.IncreaseLevel. Callers that don't pass the option are unaffected.

This adds the capability only; none of machinery's existing callers pass the option yet. The instance manager still needs a follow-up PR to opt in, and that follow-up will need to be subcommand-aware since cmd/manager's ConfigureLogging() call is shared by every subcommand (controller, instance, walarchive, pgbouncer, …) — passing the option there unconditionally would also silence the operator's own reconcile-loop sampling.

Refs cloudnative-pg/cloudnative-pg#10815

@armru
armru requested a review from a team July 6, 2026 10:09
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 <[email protected]>
@armru

armru commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

/test

@armru armru changed the title feat(log): allow disabling the zap duplicate-message sampler fix(log): allow disabling the zap duplicate-message sampler Jul 6, 2026
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 <[email protected]>
@NiccoloFei
NiccoloFei force-pushed the feat/configurable-log-sampling branch from 1f63480 to 12f2c0c Compare July 24, 2026 13:59
@NiccoloFei
NiccoloFei force-pushed the feat/configurable-log-sampling branch from 785522e to 61daa1c Compare July 24, 2026 14:55
@mnencia mnencia changed the title fix(log): allow disabling the zap duplicate-message sampler feat(log): allow disabling the zap duplicate-message sampler Jul 28, 2026
mnencia added 2 commits July 28, 2026 17:25
Assert only that the sampler deduped some messages, rather than
pinning the exact worst-case window split, which occasionally failed
under a scheduler stall spreading the burst across three or more
sampler windows.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia
mnencia merged commit 4d1e611 into main Jul 28, 2026
8 checks passed
@mnencia
mnencia deleted the feat/configurable-log-sampling branch July 28, 2026 15:52
mnencia pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 28, 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 <[email protected]>
mnencia pushed a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 28, 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 <[email protected]>
mnencia added a commit to cloudnative-pg/cloudnative-pg that referenced this pull request Jul 28, 2026
The previous pin pointed at the pre-merge commit of
cloudnative-pg/machinery#292, which is not an ancestor of machinery's
main once that PR was squash-merged. Point both modules at the actual
merge commit instead.

Signed-off-by: Marco Nenciarini <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants