fix(promtail): 修 Sprintf 缺参导致清单非法 + Ingress 模板固定命名空间 + 资源名去 opsxloki
=== 一、致命 bug:Promtail 清单第 10 个 %s 缺参数(导致日志采集中断)=== go vet 报:"format %s reads arg #10, but call has 9 args"。 模板里 DaemonSet 的 `namespace: %s`(第 9 个)和 `image: %s`(第 10 个) 是两个独立占位符,但 Sprintf 只传了 9 个参数,第 10 个变成 %!s(MISSING), 整个多文档 YAML 解析失败: "解析 Kubernetes YAML: yaml: line 23: found character that cannot start any token" 而 installDaemonset 是「先删 daemonset/configmap/serviceaccount 再 apply」, 所以每次失败都会把上一份 Promtail 删掉却不重建 → 日志采集中断。 修复: 1) Sprintf 补上 DaemonSet 命名空间参数(第 9 位) 2) 新增 validateManifest():在删旧资源之前先本地解析校验清单, 校验不过直接中止、不碰任何现有资源 —— 让模板错误永远不会再打断采集 3) 新增回归测试 promtail_manifest_test.go:用平台同一套 YAMLOrJSONDecoder 解析 3 种参数组合,断言各解析出 5 个对象且无 TAB === 二、快捷 LogQL:Ingress 访问日志不再跟随所选命名空间 === 原实现:next = applyLabelFilter(next,'namespace', namespace.trim() || 'ingress-nginx') → 选了 monitor 就生成 {namespace="monitor"} |= "HTTP/",查不到任何日志 (ingress controller 的 Pod 只在 ingress-nginx 命名空间里) 修复:ingress 模板独立处理 - 固定用 ingress controller 命名空间(ingress-nginx,缺失则回退 ingress) - 不叠加当前选中的 app / pod 过滤(那些属于业务服务) - 结果是 {namespace="ingress-nginx"} |= "HTTP/" === 三、K8s 资源名去掉 opsxloki === ClusterRole / ClusterRoleBinding:opsxloki-promtail → loki-promtail - PromtailDaemonsetYAML 里 3 处 name 全部改名 - uninstallDaemonset 同步改名,并保留对旧名 opsxloki-promtail 的兼容清理, 避免升级后留下孤儿 ClusterRole - 集群侧已实测:新建 loki-promtail,旧的 opsxloki-promtail 已删除 保留的 opsxloki(有兼容性约束,改动会丢数据/掉登录): - Go module 导入路径 opsxloki/xxx(149 处,纯内部包名) - 数据文件 opsxloki.json(改了读不到历史数据) - 前端 localStorage key opsxloki.auth.* / opsxloki.theme.* 等(改了在线用户掉登录) - Dockerfile 里的 opsxloki 系统用户/二进制名 镜像:lghost/lokistack:latest + v0.1 = sha256:4a5590580cbb
This commit is contained in:
1 parent
41633f0b38
commit
02d1bd87a7
5 files changed
+137
-10
No files matched your search
@@ -287,7 +287,7 @@ metadata:
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: opsxloki-promtail
|
||||
name: loki-promtail
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["pods", "nodes"]
|
||||
@@ -296,11 +296,11 @@ rules:
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: opsxloki-promtail
|
||||
name: loki-promtail
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: opsxloki-promtail
|
||||
name: loki-promtail
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: promtail
|
||||
@@ -482,7 +482,7 @@ spec:
|
||||
- name: containers
|
||||
hostPath:
|
||||
path: /var/lib/docker/containers
|
||||
`, ns, ns, ns, lokiURL, extLabels, nsFilter, appSourceLine, promtailImage, appIncludeFilter)
|
||||
`, ns, ns, ns, lokiURL, extLabels, nsFilter, appSourceLine, appIncludeFilter, ns, promtailImage)
|
||||
}
|
||||
|
||||
// FluentbitConfig Sidecar 模式 Fluent Bit 配置(采集 logPath,推送至 lokiHost:lokiPort)
|
||||
|
||||
Reference in new issue
Block a user