Files
logan 2d73661dd1 feat: complete Loki query, insights, settings and deployment workflows
Add the Loki query UI, access policies, ingress insights, alert and registry settings, and their backend APIs. Include the related Kubernetes deployment and collector updates required by the integrated application.

Validated with go test ./..., npm run build, and npm run lint.
2026-10-25 21:28:32 +08:00

43 lines
1.8 KiB
Go

package models
import "time"
// AlertRule 日志告警规则:对选定数据源周期执行 LogQL 计数,超过阈值即通知。
// 参照运维侧 app-alert.py 的两类模式:
//
// critical(出现即报,threshold=1)/ surge(突增才报,自定义阈值),统一收敛为「N 条 / 窗口 > 阈值」。
type AlertRule struct {
ID uint `json:"id"`
Name string `json:"name"`
SourceID uint `json:"sourceId"` // LogSource
ChannelIDs []uint `json:"channelIds"` // NotifyChannel 列表(告警扇出到多个群)
Query string `json:"query"` // 完整 LogQL({app="x"} |= "FATAL")
WindowMin int `json:"windowMin"` // 统计窗口(分钟)
Threshold int `json:"threshold"` // 窗口内条数 > 阈值触发
Enabled bool `json:"enabled"`
CooldownMin int `json:"cooldownMin"` // 同规则告警冷却(分钟,默认 60)
LastFiredAt time.Time `json:"lastFiredAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (r *AlertRule) Sanitized() map[string]interface{} {
return map[string]interface{}{
"id": r.ID, "name": r.Name, "sourceId": r.SourceID, "channelIds": r.ChannelIDs,
"query": r.Query, "windowMin": r.WindowMin, "threshold": r.Threshold,
"enabled": r.Enabled, "cooldownMin": r.CooldownMin,
"lastFiredAt": r.LastFiredAt, "createdAt": r.CreatedAt, "updatedAt": r.UpdatedAt,
}
}
// AlertDelivery 告警发送历史(飞书 webhook 投递记录)
type AlertDelivery struct {
ID uint `json:"id"`
RuleID uint `json:"ruleId"`
RuleName string `json:"ruleName"`
Count int `json:"count"` // 窗口内命中条数
Status string `json:"status"` // sent | failed | cooldown-skipped
Reason string `json:"reason"`
CreatedAt time.Time `json:"createdAt"`
}