notifier

package
v1.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package maintenance windows, for the notifier: it answers "should this alert be sent now, and if not, when" using the rules in internal/maintenance.

The package is split in two on purpose. `internal/maintenance` decides, with no database and no clock of its own, so its boundaries are testable; this file reads the windows and answers the notifier's question. The notifier calls one function, so there is one place where the suppression decision is made rather than one per event type.

Index

Constants

View Source
const (
	// PingAlertMetricLatency 以平均延迟(毫秒)为判据。
	PingAlertMetricLatency = "ping_latency"
	// PingAlertMetricLoss 以丢包率(百分比)为判据。
	PingAlertMetricLoss = "ping_loss"
)

Variables

View Source
var LoadNotificationManager = &LoadNotificationService{
	tasks: make(map[int][]models.LoadNotification),
}

Functions

func ActiveFor added in v0.1.37

func ActiveFor(now time.Time, clientUUID string) corewindow.Status

ActiveFor reports whether a client is inside a window at `now`, for the UI.

func CheckExpire

func CheckExpire()

func CheckExpireScheduledWork

func CheckExpireScheduledWork()

func CheckTraffic

func CheckTraffic()

CheckTraffic 检查各客户端流量使用情况,并在达到阈值和每+5%时提醒一次;100%时额外提醒一次 由外部协程每分钟调用一次

func CheckTrafficForecast added in v0.1.39

func CheckTrafficForecast()

CheckTrafficForecast projects each node's cycle traffic and warns once per cycle when the projection reaches its limit. Called on the same one-minute schedule as CheckTraffic.

func ForecastThreshold added in v0.1.39

func ForecastThreshold() float64

configuredForecastThreshold reads the warning fraction, defaulting to the package's own.

The same setting as the used-percentage warning, so the panel has one answer to "when should I hear about traffic". A value outside (0, 1] is ignored rather than clamped, because a threshold of 0 would warn about every node every cycle and a threshold above 1 would warn about none.

func Invalidate added in v0.1.37

func Invalidate()

Invalidate drops the cache, so an edit takes effect on the next notification rather than up to cacheTTL later.

func InvalidateMaintenanceWindows added in v0.1.37

func InvalidateMaintenanceWindows()

InvalidateMaintenanceWindows drops the cache, so an edit takes effect on the next notification rather than up to cacheTTL later. Called by the admin handler after every write.

func IsPingAlertMetric added in v0.1.1

func IsPingAlertMetric(metric string) bool

IsPingAlertMetric 判断该规则是否走 ping 求值路径。

func OfflineNotification

func OfflineNotification(clientID string, endedConnectionID int64)

OfflineNotification 在启用通知且未在宽限期内发送的情况下,发送客户端离线通知。

func OnlineNotification

func OnlineNotification(clientID string, connectionID int64)

OnlineNotification records the connection state and, when enabled, sends a client online notification.

func ProjectClient added in v0.1.39

func ProjectClient(now time.Time, client models.Client, day int) (forecast.Forecast, error)

projectClient reads a node's cycle samples and forecasts them.

Returns the cycle start alongside the projection so the caller can use it as the once-per-cycle key without recomputing it, which would be a second place to get the boundary wrong.

func ReloadLoadNotificationSchedule

func ReloadLoadNotificationSchedule(loadNotifications []models.LoadNotification) error

ReloadLoadNotificationSchedule 加载或重载时间表

func ShouldSendLater added in v0.1.37

func ShouldSendLater(now, deliverAt time.Time) bool

ShouldSendLater reports whether an alert deferred to `deliverAt` is still worth sending.

The caller checks the condition as well — whether the node is still offline — because this only knows about time. The two together are the rule: an alert is sent after a window closes when the condition still holds and the deferral is not stale.

func SweepDeferredAlerts added in v0.1.37

func SweepDeferredAlerts()

SweepDeferredAlerts delivers alerts that maintenance windows deferred, and is called from the server's scheduler every minute.

On the existing scheduler rather than a goroutine of its own: there is then one place that owns periodic work and one place to look when something is not running.

func WindowsFor added in v1.6.18

func WindowsFor(clientUUID string, start, end time.Time) []corewindow.Window

WindowsFor returns the maintenance windows that cover clientUUID and intersect the half-open range [start, end), ordered by start and then by id.

It exists for readers that must discount maintenance time — the SLA report is the first — and deliberately reuses load(), the notifier's cached window list: an SLA report covers a fleet, and a per-node read path must not become a database query per node. A window edit is already visible to the notifier within the same 30 s cache, and the SLA report is a historical view, so sharing that freshness is the right trade (see cacheTTL).

An empty or inverted range intersects nothing, which is why it returns nil rather than every covering window: half-open ranges mean no time, no evidence to exclude.

Types

type Decision added in v0.1.37

type Decision struct {
	// Suppress is true when the alert must not be sent now.
	Suppress bool
	// Reason names the window, for the log line that records why an alert did not fire.
	Reason string
	// DeliverAt is when a suppressed alert becomes worth sending. Zero when dropping it.
	DeliverAt time.Time
	// StillWorthSending is set by ShouldSendLater below.
	StillWorthSending bool
}

Decision is what the notifier should do about an alert for one client.

func For added in v0.1.37

func For(now time.Time, clientUUID string) Decision

For returns what to do about an alert for clientUUID at `now`.

type LoadNotificationService

type LoadNotificationService struct {
	// contains filtered or unexported fields
}

LoadNotificationService 管理定时器和任务

func (*LoadNotificationService) Reload

func (m *LoadNotificationService) Reload(loadNotifications []models.LoadNotification) error

Reload 重载时间表

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL