feat(collector): 采集命名空间多选 + app 标签来源可自定义 + app 白名单
=== 一、采集命名空间改为多选(原来只有文本输入)===
- CollectorEditDialog 重写:勾选式多选面板,从
GET /clusters/:id/namespaces 拉取真实命名空间列表
- "所有命名空间(全集群采集)"一键全选(targetNamespaces 置空即全集群)
- 支持搜索过滤命名空间;已选数量实时显示
- 保存时为空数组 → Promtail 不加 namespaces 白名单
=== 二、app 标签取值来源可配置 ===
新增 Collector.AppLabelSource:
留空(默认)= app.kubernetes.io/name → app → controller 名(去hash) → pod 名 四级回退
可填任意 Pod 标签,如 app.kubernetes.io/name / app / k8s.kuboard.cn/name
也可直接写 __meta_kubernetes_pod_label_xxx
→ 作为最高优先级插到回退链最前,其余仍兜底
模板侧新增:
sanitizePromLabel() 标签名 → Prometheus meta label(. / 等转 _)
promtailAppSourceLabel() 解析用户配置
promtailAppIncludeFilter() 生成白名单 keep 规则
=== 三、app 白名单(控制采集量)===
新增 Collector.AppInclude []string:
填了之后生成
- source_labels: [app]
regex: ^(app1|app2)$
action: keep
只保留匹配的日志流 —— 这是收敛日志量最直接的手段
service.Update 同步支持 appLabelSource / appInclude(兼容 []string 与逗号分隔字符串)。
前端 CollectorEditDialog:
采集命名空间 = 勾选多选 + 全选
app 标签取值来源 = 输入框 + 5 个常用值 datalist 提示
只采集这些 app = 逗号分隔输入
镜像:lghost/lokistack:latest + v0.1 = sha256:43369d06cb28
This commit is contained in:
1 parent
e006fc1a0e
commit
41633f0b38
7 files changed
+280
-33
No files matched your search
@@ -248,6 +248,43 @@ func (s *CollectorService) Update(id uint, updates map[string]interface{}) error
|
||||
}
|
||||
db.Collectors[i].TargetNamespaces = nss
|
||||
}
|
||||
// appLabelSource:app 标签取值来源(空=默认 controller_name 回退链)
|
||||
if v, ok := updates["appLabelSource"].(string); ok {
|
||||
if strings.TrimSpace(v) != db.Collectors[i].AppLabelSource {
|
||||
db.Collectors[i].StatusMessage = "app 标签来源已保存,点击部署以应用新配置"
|
||||
}
|
||||
db.Collectors[i].AppLabelSource = strings.TrimSpace(v)
|
||||
}
|
||||
// appInclude:只采集这些 app(白名单,空=不限)
|
||||
if v, ok := updates["appInclude"]; ok {
|
||||
var apps []string
|
||||
switch t := v.(type) {
|
||||
case []interface{}:
|
||||
for _, item := range t {
|
||||
if s, ok := item.(string); ok {
|
||||
if s = strings.TrimSpace(s); s != "" {
|
||||
apps = append(apps, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
case []string:
|
||||
for _, s := range t {
|
||||
if s = strings.TrimSpace(s); s != "" {
|
||||
apps = append(apps, s)
|
||||
}
|
||||
}
|
||||
case string:
|
||||
for _, s := range strings.Split(t, ",") {
|
||||
if s = strings.TrimSpace(s); s != "" {
|
||||
apps = append(apps, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(apps) != len(db.Collectors[i].AppInclude) {
|
||||
db.Collectors[i].StatusMessage = "采集 app 白名单已保存,点击部署以应用新配置"
|
||||
}
|
||||
db.Collectors[i].AppInclude = apps
|
||||
}
|
||||
db.Collectors[i].UpdatedAt = time.Now()
|
||||
db.RequestSave()
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user