Persist the Lite alert email cooldown across restarts (#981)#986
Merged
Conversation
EmailAlertService deduplicated alert emails with an in-memory
ConcurrentDictionary cooldown keyed {serverId}:{metricName}. It was
never persisted, so restarting Lite cleared every cooldown and an alert
email sent minutes before the restart could be sent again immediately.
The first time each alert key is evaluated, the cooldown is now seeded
from config_alert_log via GetLastEmailSentUtcAsync - the most recent
alert_time for that server/metric where an email actually succeeded
(notification_type IN ('email','email+webhook') AND send_error IS NULL,
mirroring exactly when _cooldowns is updated after SendEmailAsync). The
in-memory dictionary stays authoritative once seeded.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.
Problem
Split out from #976. The reporter saw the same alerts pop up several times, hours after the originating event.
EmailAlertServicededuplicated alert emails with an in-memoryConcurrentDictionary<string, DateTime>cooldown keyed{serverId}:{metricName}. It was never persisted, so restarting Lite cleared every cooldown — an alert email sent minutes before the restart could be sent again immediately after.Change
The first time each alert key is evaluated, the cooldown is seeded from
config_alert_logvia the newGetLastEmailSentUtcAsync— the most recentalert_timefor that server/metric where an email actually succeeded (notification_type IN ('email','email+webhook') AND send_error IS NULL, which is exactly when_cooldownsis updated afterSendEmailAsync). The in-memory dictionary stays authoritative once seeded, so it's one small read per key per app session.Test plan
dotnet build Lite/PerformanceMonitorLite.csproj -c Debug— full rebuild, 0 warnings, 0 errors.config_alert_logrows: it correctly returns the most recent successful email send, excluding a later row with asend_error(failed send) and atray-only row, and returns null when there's no history for the key.config_alert_logINSERT inLogAlertAsync.🤖 Generated with Claude Code