=== 1. 告警窗口 15m → 5m(阈值同比例 1/3)===
背景:检查间隔已改 5 分钟,但规则窗口仍是 15 分钟 ——
同一个 15 分钟窗口每 5 分钟被完整重扫一遍,等于 3 倍重复扫描。
在 370GB/天、全命名空间 selector 下,这是 Loki CPU 的最大稳态来源。
FATAL 10 → 4 窗口 5m
Go panic 10 → 4 窗口 5m
JVM OOM 5 → 2 窗口 5m
StackOverflow 5 → 2 窗口 5m
应用错误激增 100000 → 35000 窗口 5m(改名 error > 3.5万)
ingress 5xx 2000 → 700 窗口 5m
ingress 4xx 20000 → 7000 窗口 5m
DB 连接失败 1000 → 350 窗口 5m
阈值按 1/3 缩放是必须的:窗口缩短 3 倍后,同样的流量在 5 分钟内只有
1/3 的条数,阈值不动就永远打不到了。
迁移 v10→v11 只改"窗口仍是 15 且名字匹配内置规则"的项,用户手调的不动。
=== 2. 数据源支持编辑/删除(含托管源)===
原来前后端都把托管源锁死:
- 前端 `!managed &&` 直接不渲染编辑/删除按钮
- 后端 DeleteSource 返回「平台部署的数据源随部署管理,请先删除对应部署」
用户的诉求是"数据源必须能编辑和删除",且确实有场景(不想让某个源出现在
查询下拉里、想改认证头)。
=== 3. 修「删了又回来」的真 bug ===
EnsureLogSourcesForRunningDeployments() 在 **每次打开数据源列表和启动时**
都会给 running 部署补齐数据源 —— 所以删掉托管源后,刷新页面它又回来了,
用户看到的现象就是"删不掉"。
新增 LokiDeployment.AutoSourceDisabled:
- 删除托管源时置位(DisableAutoSourceFor)
- EnsureLogSourceForDeployment 见到该开关直接 return
- 部署被编辑/重新部署时重置(EnableAutoSourceFor),即"你要用它了就恢复"
前端配套文案:
- 编辑托管源弹窗提示"重新部署会覆盖集群/Service/端口,认证与请求头保留"
- 删除确认明确"删除后不会再自动重建,重新部署该 Loki 才恢复"
=== 实测(20300eef92d2)===
v11 迁移后 8 条规则全部 窗口=5m,阈值 4/4/2/2/35000/700/7000/350
go test ./... 全绿
100 lines
3.7 KiB
Go
100 lines
3.7 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type LokiDeployment struct {
|
|
ID uint `json:"id"`
|
|
UUID string `json:"uuid"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Version string `json:"version"`
|
|
Mode string `json:"mode"`
|
|
ClusterID *uint `json:"clusterID,omitempty"`
|
|
Cluster *Cluster `json:"cluster,omitempty"`
|
|
HostID *uint `json:"hostID,omitempty"`
|
|
Host *Host `json:"host,omitempty"`
|
|
ListenIP string `json:"listenIP,omitempty"`
|
|
ListenPort int `json:"listenPort,omitempty"`
|
|
Namespace string `json:"namespace"`
|
|
StorageConfigID uint `json:"storageConfigID"`
|
|
StorageConfig *StorageConfig `json:"storageConfig,omitempty"`
|
|
AuthEnabled bool `json:"authEnabled"`
|
|
RetentionDays int `json:"retentionDays"`
|
|
Replicas int `json:"replicas"`
|
|
ResourcesCPU string `json:"resourcesCPU"`
|
|
ResourcesMem string `json:"resourcesMem"`
|
|
// AutoSourceDisabled 用户手动删除了"自动注册的数据源"后置为 true,
|
|
// 平台不再自动重建,直到用户重新部署/编辑该部署。
|
|
// 没有这个开关的话:删了数据源 → 下次打开查询页又被 EnsureLogSources 补回来,
|
|
// 用户看到的现象就是"删不掉"。
|
|
AutoSourceDisabled bool `json:"autoSourceDisabled"`
|
|
StorageSize string `json:"storageSize"`
|
|
GrafanaEnabled bool `json:"grafanaEnabled"`
|
|
GrafanaVersion string `json:"grafanaVersion"`
|
|
GrafanaPort int `json:"grafanaPort"`
|
|
GrafanaEndpoint string `json:"grafanaEndpoint"`
|
|
Status string `json:"status"`
|
|
StatusMessage string `json:"statusMessage"`
|
|
Endpoint string `json:"endpoint"`
|
|
AdminUser string `json:"adminUser"`
|
|
AdminPassword string `json:"adminPassword"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
}
|
|
|
|
func (d *LokiDeployment) BeforeCreate() {
|
|
if d.UUID == "" {
|
|
d.UUID = uuid.New().String()
|
|
}
|
|
}
|
|
|
|
// Sanitized 返回去除敏感字段(AdminPassword)的部署视图,并对嵌套的
|
|
// Cluster/Host/StorageConfig 一并做脱敏,避免经部署接口泄漏各自凭证。
|
|
func (d *LokiDeployment) Sanitized() map[string]interface{} {
|
|
out := map[string]interface{}{
|
|
"id": d.ID,
|
|
"uuid": d.UUID,
|
|
"name": d.Name,
|
|
"description": d.Description,
|
|
"version": d.Version,
|
|
"mode": d.Mode,
|
|
"clusterID": d.ClusterID,
|
|
"hostID": d.HostID,
|
|
"listenIP": d.ListenIP,
|
|
"listenPort": d.ListenPort,
|
|
"namespace": d.Namespace,
|
|
"storageConfigID": d.StorageConfigID,
|
|
"authEnabled": d.AuthEnabled,
|
|
"retentionDays": d.RetentionDays,
|
|
"replicas": d.Replicas,
|
|
"resourcesCPU": d.ResourcesCPU,
|
|
"resourcesMem": d.ResourcesMem,
|
|
"storageSize": d.StorageSize,
|
|
"grafanaEnabled": d.GrafanaEnabled,
|
|
"grafanaVersion": d.GrafanaVersion,
|
|
"grafanaPort": d.GrafanaPort,
|
|
"grafanaEndpoint": d.GrafanaEndpoint,
|
|
"status": d.Status,
|
|
"statusMessage": d.StatusMessage,
|
|
"endpoint": d.Endpoint,
|
|
"adminUser": d.AdminUser,
|
|
// AdminPassword 故意省略
|
|
"createdAt": d.CreatedAt,
|
|
"updatedAt": d.UpdatedAt,
|
|
}
|
|
if d.Cluster != nil {
|
|
out["cluster"] = d.Cluster.Sanitized()
|
|
}
|
|
if d.Host != nil {
|
|
out["host"] = d.Host.Sanitized()
|
|
}
|
|
if d.StorageConfig != nil {
|
|
out["storageConfig"] = d.StorageConfig.Sanitized()
|
|
}
|
|
return out
|
|
}
|