fix(alerts,db): 清理历史误种的 K8s 基础设施告警规则 + 数据迁移不留档
- seed 启动时一次性删除早期版本种入的「Kubernetes 节点 NotReady」「容器 OOMKilled」 (日志平台只关注应用日志,节点/容器状态告警归 Prometheus;源码早已移除该模板,但幂等只跳过不清理,旧库存量一直在) - 数据文件迁移为 lokistack.json 后直接删除旧文件,不再留 .migrated-*.bak(测试同步)
This commit is contained in:
1 parent
231fa8e774
commit
c08190458f
3 files changed
+26
-18
No files matched your search
@@ -6,6 +6,7 @@ package seed
|
||||
// 绑定数据源:部署成功自动注册的 LogSource(managed)。
|
||||
// 规则默认不启用(通知通道由管理员后期在设置页配置后再开启),ChannelIDs 留空。
|
||||
import (
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"lokistack/models"
|
||||
@@ -89,9 +90,27 @@ var builtinRules = []builtinRule{
|
||||
|
||||
// seedBuiltinAlertRules 为每个平台管理的 LogSource(managed=true)补齐内置规则:
|
||||
// 首次部署 Loki 后即有一套可直接启用的告警模板;通知通道留空,管理员配置后启用。
|
||||
// legacyInfraRules 早期版本误种的 Kubernetes 基础设施类规则 —— 日志平台只关注应用日志,
|
||||
// 这类节点/容器状态告警属 Prometheus + Alertmanager 职责,升级时一次性清理存量。
|
||||
var legacyInfraRules = []string{"Kubernetes 节点 NotReady", "容器 OOMKilled"}
|
||||
|
||||
// SeedAlertRules 补齐内置告警规则(幂等;公开给启动与部署成功两处调用)
|
||||
func SeedAlertRules() {
|
||||
// 先清掉历史遗留的基础设施类规则(只删名字精确匹配的这两条)
|
||||
db := repository.GetDB()
|
||||
db.Lock()
|
||||
kept := db.AlertRules[:0]
|
||||
for _, rule := range db.AlertRules {
|
||||
if !slices.Contains(legacyInfraRules, rule.Name) {
|
||||
kept = append(kept, rule)
|
||||
}
|
||||
}
|
||||
if len(kept) != len(db.AlertRules) {
|
||||
db.AlertRules = kept
|
||||
db.RequestSave()
|
||||
}
|
||||
db.Unlock()
|
||||
|
||||
db.RLock()
|
||||
type srcRef struct {
|
||||
id uint
|
||||
|
||||
Reference in new issue
Block a user