mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6768] [MERGED] feat(notifications): add a failed-check threshold for node.down alerts #6447
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6447
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6768
Author: @STRENCH0
Created: 10/8/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei
Base:
main← Head:feat/node-down-grace📝 Commits (3)
8e4ee39feat(notifications): add a failed-check threshold for node.down alerts40797bffix(notifications): stop re-alerting nodes that were already offline8a4db19fix(notifications): persist node.down announcements across restarts📊 Changes
34 files changed (+379 additions, -35 deletions)
View changed files
📝
docs/public/openapi.json(+12 -0)📝
frontend/public/openapi.json(+12 -0)📝
frontend/src/components/ui/notifications/EmailNotifications.tsx(+18 -1)📝
frontend/src/components/ui/notifications/NotificationGroup.tsx(+17 -7)📝
frontend/src/components/ui/notifications/TelegramNotifications.tsx(+18 -1)📝
frontend/src/components/ui/notifications/types.ts(+1 -0)📝
frontend/src/generated/examples.ts(+2 -0)📝
frontend/src/generated/schemas.ts(+12 -0)📝
frontend/src/generated/types.ts(+2 -0)📝
frontend/src/generated/zod.ts(+2 -0)📝
frontend/src/models/setting.ts(+5 -0)📝
frontend/src/schemas/setting.ts(+1 -0)📝
internal/database/db.go(+18 -1)📝
internal/database/model/model.go(+2 -0)➕
internal/database/node_down_notified_migration_test.go(+43 -0)📝
internal/web/entity/entity.go(+1 -0)➕
internal/web/job/node_down_threshold_test.go(+118 -0)📝
internal/web/job/node_heartbeat_job.go(+62 -25)📝
internal/web/job/node_transition_burst_test.go(+4 -0)📝
internal/web/service/node.go(+6 -0)...and 14 more files
📄 Description
Summary
Adds a
nodeDownThresholdsetting.node.downnow fires only after that many failed heartbeat checks in a row, andnode.uponly after anode.downwas actually sent. This works the same wayoutboundDownThresholdalready debounces outbound alerts.Why
One lost heartbeat on a lossy link flipped a node offline and sent
node.down. The next probe, 5 s later, sentnode.up. A flaky node flooded every channel (Telegram, email, Discord) with alert pairs, sometimes several pairs a minute for the same node.The heartbeat now keeps a per-node in-memory streak, as
XrayMetricsServicedoes for outbounds:node.downis published once the streak reaches the threshold, and only once per outage.node.upis published only if anode.downwas sent for that outage.publishNodeTransitions) still applies to the debounced events.Both threshold fields (outbound and node) also get a "failed checks in a row" hint. Before, the field was a bare number that did not say what it counts.
Type of change
Areas affected
How was this tested?
New test
TestHeartbeatHoldsNodeDownUntilThreshold(internal/web/job/node_down_threshold_test.go). It drives the real heartbeat job against anhttptestnode that can be switched up and down, with threshold = 3:node.downon the 3rd failed check,node.upon recovery;offlinein the DB before a restart: stays quiet while still down, sendsnode.upon recovery.All three cases fail on the previous code. The flapping case reproduces the reported spam exactly.
The existing burst tests (
node_transition_burst_test.go) pin the threshold to 1 and still pass.go test ./internal/web/...passes.golangci-lint run ./internal/web/...reports 0 issues.Frontend:
npm run typecheck,npm run lint,npm run format:check, unit tests (1349, includingi18n-dead-keys) andnpm run buildpass.Manual check: ran the panel locally. Opened Settings → Telegram → Notifications, ticked Nodes → Down; the threshold field appears with the hint (same in Email).
POST /panel/api/setting/allreturnsnodeDownThreshold: 1on a fresh DB.Screenshots / recordings
Breaking changes
None. No migration is needed: the setting defaults to
1, which keeps the current alerting. One minor behavior change: after a panel restart,node.upis no longer sent for a node that had nonode.downin the current process (for example, a freshly added node or one that wasofflinein the DB at startup).Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.