Warn and skip the notifier worker when alerts are disabled - #93
Merged
Conversation
With alerts.enabled=false but alerts.webhooks configured, the notifier was still built and its delivery worker started even though the disabled alert engine never produces events for it to deliver — the webhooks silently never fire, with no indication why. Gate wiring the notifier into the collector on AlertsEnabled, mirroring how the alert engine itself is already gated, so the idle worker is never started. Also log a startup warning when webhooks are configured alongside alerts.enabled=false, so the inert combination is visible.
Pull the alerts.enabled=false-but-webhooks-configured warning check out of run() into warnIfNotifierInert, and add TestWarnIfNotifierInert covering all three cases (no webhooks, webhooks with alerts enabled, webhooks with alerts disabled). run() itself has no test harness, so this keeps the new logic itself verifiable in isolation.
|
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.



📖 Description
With
alerts.enabled: falsebutalerts.webhookspopulated, the notifier was built and its delivery worker started (cmd/pimonitor/main.go,internal/collector/collector.go), but the disabled alert engine never produces transition events — the webhooks silently never fired, with no indication why.This is a fix, not a breaking change.
🎫 Issues
Closes #72
👩💻 Reviewer Notes
Two changes:
internal/collector/collector.go:Collector.Newnow only wirescfg.Notifierinto the collector whencfg.AlertsEnabledis true, mirroring how the alert engine itself is already gated. This meansRunnever callsnotifier.Startfor a disabled engine — the idle worker is no longer started at all (as opposed to running but never receiving events).cmd/pimonitor/main.go: logs a startup warning —"alert webhooks configured but alerts.enabled is false — no notifications will be sent"— when a notifier was built (i.e. webhooks are configured) butalerts.enabledis false, so the inert combination is visible instead of silent.internal/config/config.go'sAlerts.validate()is untouched: it still validates webhook config regardless ofenabled, which is correct (a typo in an inert config should still fail fast at startup).📑 Test Plan
Added
TestCollector_Notifier_NotWiredWhenAlertsDisabledininternal/collector/collector_test.go, which builds a real notifier from a configured webhook viaalert.NewNotifier, constructs aCollectorwithAlertsEnabled: false, and asserts the collector's internalnotifierfield staysnil— i.e. the worker is never wired in to be started.go build ./...— cleango vet ./...— cleango test ./... -race -cover— all packages passgolangci-lint run— 0 issuesThe startup warning log line itself is a simple
log.Warncall inmain.go'srun(), consistent with other untested log statements already in that function (e.g. the shutdown log); it is not independently unit-tested.✅ Checklist
General
go test ./... -race -coverpasses locally).go vet ./...andgolangci-lint runare clean.ARCHITECTURE.mdif this changes a documented design decision. (not applicable — no design decision changed)REST API / configuration / packaging
Not applicable — no REST API, config schema, or packaging change.
⏭ Next Steps
None.