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.
This commit is contained in:
1 parent
f9c6c1d826
commit
2d73661dd1
127 files changed
+8117
-2876
No files matched your search
@@ -194,6 +194,7 @@ extraVolumeMounts:
|
||||
// 取代 helm 安装 —— 后端无需安装 helm 二进制。
|
||||
// relabel 体系与主流 helm chart 对齐:namespace/pod/container/node_name + __path__ 按 pod uid 精确匹配。
|
||||
func PromtailDaemonsetYAML(ns, lokiURL, clusterName, labelsJSON string) string {
|
||||
promtailImage := ResolveImage("docker.io/grafana/promtail:3.4.0")
|
||||
extLabels := promtailExternalLabels(clusterName, labelsJSON)
|
||||
return fmt.Sprintf(`apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
@@ -292,7 +293,7 @@ spec:
|
||||
operator: Exists
|
||||
containers:
|
||||
- name: promtail
|
||||
image: grafana/promtail:3.4.0
|
||||
image: %s
|
||||
imagePullPolicy: IfNotPresent
|
||||
args: ["-config.file=/etc/promtail/promtail.yaml"]
|
||||
env:
|
||||
@@ -340,11 +341,11 @@ spec:
|
||||
- name: containers
|
||||
hostPath:
|
||||
path: /var/lib/docker/containers
|
||||
`, ns, ns, ns, lokiURL, extLabels, ns)
|
||||
`, ns, ns, ns, lokiURL, extLabels, ns, promtailImage)
|
||||
}
|
||||
|
||||
// FluentbitConfig Sidecar 模式 Fluent Bit 配置(采集 logPath,推送至 lokiHost:lokiPort)
|
||||
// 生产级配置:kubernetes过滤器、内存缓冲、健康检查
|
||||
// Sidecar 已明确知道应用与命名空间,无需 Kubernetes 元数据过滤器。
|
||||
func FluentbitConfig(lokiHost, lokiPort, logPath, app, namespace string) string {
|
||||
return fmt.Sprintf(`[SERVICE]
|
||||
Flush 1
|
||||
@@ -352,11 +353,9 @@ func FluentbitConfig(lokiHost, lokiPort, logPath, app, namespace string) string
|
||||
HTTP_Server On
|
||||
HTTP_Listen 0.0.0.0
|
||||
HTTP_Port 2020
|
||||
Parsers_File parsers.conf
|
||||
storage.path /tmp/flb-storage/
|
||||
storage.sync normal
|
||||
storage.checksum off
|
||||
storage.max_chunks_pause On
|
||||
storage.backlog.mem_limit 5M
|
||||
Health_Check On
|
||||
HC_Errors_Count 5
|
||||
@@ -383,70 +382,69 @@ func FluentbitConfig(lokiHost, lokiPort, logPath, app, namespace string) string
|
||||
Add app %s
|
||||
Add source fluent-bit
|
||||
|
||||
[FILTER]
|
||||
Name kubernetes
|
||||
Match app.*
|
||||
Kube_URL https://kubernetes.default.svc:443
|
||||
Kube_CA_File /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
|
||||
Kube_Token_File /var/run/secrets/kubernetes.io/serviceaccount/token
|
||||
Merge_Log On
|
||||
Keep_Log Off
|
||||
K8S-Logging.Parser On
|
||||
K8S-Logging.Exclude On
|
||||
Labels On
|
||||
Annotations Off
|
||||
|
||||
[OUTPUT]
|
||||
Name loki
|
||||
Match *
|
||||
Host %s
|
||||
Port %s
|
||||
Labels job=fluent-bit, app=%s, namespace=%s
|
||||
Drop_Records_Without_Labels On
|
||||
Line_Format json
|
||||
Auto_Kubernetes_Labels On
|
||||
Retry_Limit 10
|
||||
`, logPath, app, namespace, app, lokiHost, lokiPort, app, namespace)
|
||||
}
|
||||
|
||||
// FluentbitConfigMapYAML 包装 fluent-bit.conf 为 ConfigMap YAML(部署到 namespace)
|
||||
func FluentbitConfigMapYAML(conf, namespace string) string {
|
||||
// FluentbitConfigMapYAML 为每个采集策略生成独立 ConfigMap,避免同命名空间的 Sidecar 相互覆盖。
|
||||
func FluentbitConfigMapYAML(conf, namespace, name string) string {
|
||||
return fmt.Sprintf(`apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: fluent-bit-config
|
||||
name: %s
|
||||
namespace: %s
|
||||
data:
|
||||
fluent-bit.conf: |
|
||||
%s
|
||||
`, namespace, indentBlock(conf, " "))
|
||||
`, name, namespace, indentBlock(conf, " "))
|
||||
}
|
||||
|
||||
// SidecarPatchYAML strategic merge patch:为 Deployment 注入 Fluent Bit sidecar 容器
|
||||
// 生产级配置:资源限制、健康检查、安全上下文
|
||||
const SidecarPatchYAML = `spec:
|
||||
// SidecarPatchYAML 将业务容器与 Fluent Bit 挂到同一日志卷和目录。
|
||||
func SidecarPatchYAML(configMapName string, mount sidecarLogMount) string {
|
||||
volume := ""
|
||||
if mount.createVolume {
|
||||
volume = fmt.Sprintf(" - name: %s\n emptyDir: {}\n", mount.volumeName)
|
||||
}
|
||||
appMount := ""
|
||||
if mount.mountApplication {
|
||||
appMount = fmt.Sprintf(" - name: %s\n volumeMounts:\n - name: %s\n mountPath: %q\n", mount.containerName, mount.volumeName, mount.mountPath)
|
||||
}
|
||||
subPath := ""
|
||||
if mount.subPath != "" {
|
||||
subPath = fmt.Sprintf(" subPath: %q\n", mount.subPath)
|
||||
}
|
||||
return fmt.Sprintf(`spec:
|
||||
template:
|
||||
spec:
|
||||
volumes:
|
||||
- name: app-logs
|
||||
emptyDir: {}
|
||||
- name: fluent-bit-config
|
||||
%s - name: fluent-bit-config
|
||||
configMap:
|
||||
name: fluent-bit-config
|
||||
name: %s
|
||||
- name: fluent-bit-state
|
||||
emptyDir: {}
|
||||
containers:
|
||||
- name: fluent-bit
|
||||
image: cr.fluentbit.io/fluent/fluent-bit:3.1.1
|
||||
%s - name: fluent-bit
|
||||
image: %s
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- name: http
|
||||
- name: fluent-bit-http
|
||||
containerPort: 2020
|
||||
protocol: TCP
|
||||
volumeMounts:
|
||||
- name: app-logs
|
||||
mountPath: /var/log/app
|
||||
readOnly: true
|
||||
- name: %s
|
||||
mountPath: %q
|
||||
%s readOnly: true
|
||||
- name: fluent-bit-config
|
||||
mountPath: /fluent-bit/etc/
|
||||
- name: fluent-bit-state
|
||||
mountPath: /tmp
|
||||
resources:
|
||||
limits:
|
||||
cpu: 200m
|
||||
@@ -463,30 +461,17 @@ const SidecarPatchYAML = `spec:
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: http
|
||||
port: fluent-bit-http
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: http
|
||||
port: fluent-bit-http
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
`
|
||||
|
||||
// SidecarRemovePatchYAML strategic merge patch:从 Deployment 移除 Fluent Bit sidecar(卸载)
|
||||
const SidecarRemovePatchYAML = `spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: fluent-bit
|
||||
$patch: delete
|
||||
volumes:
|
||||
- name: app-logs
|
||||
$patch: delete
|
||||
- name: fluent-bit-config
|
||||
$patch: delete
|
||||
`
|
||||
`, volume, configMapName, appMount, ResolveImage("docker.io/fluent/fluent-bit:5.1.5"), mount.volumeName, mount.mountPath, subPath)
|
||||
}
|
||||
|
||||
// indentBlock 给每行加前缀(ConfigMap 嵌入配置需缩进)
|
||||
func indentBlock(s, pad string) string {
|
||||
|
||||
Reference in new issue
Block a user