chore: add imagePullPolicy and migrate WaitGroup to wg.Go
- add imagePullPolicy: IfNotPresent to all k8s Deployments, DaemonSet
(grafana, jaeger, loki, rabbitmq, redis, promtail)
- migrate wg.Add(1)/go/defer wg.Done() pattern to wg.Go() (Go 1.25+)
in logger/loki_syncer.go and task/worker.go
- simplify redundant map existence check before delete in diagram/graph.go
- update deploy.md to reflect pg PVC size (6Gi) and resource limits
This commit is contained in:
parent
c4e892f1c7
commit
05c64dda14
|
|
@ -32,6 +32,7 @@ go.work
|
||||||
# ai config
|
# ai config
|
||||||
.cursor/
|
.cursor/
|
||||||
.claude/
|
.claude/
|
||||||
|
.codewhale/
|
||||||
.cursorrules
|
.cursorrules
|
||||||
.copilot/
|
.copilot/
|
||||||
.chatgpt/
|
.chatgpt/
|
||||||
|
|
|
||||||
|
|
@ -695,7 +695,11 @@ kubectl apply -f deploy/k8s/pg-service.yaml
|
||||||
| **数据库** | `demo` | ConfigMap 中 `POSTGRES_DB` |
|
| **数据库** | `demo` | ConfigMap 中 `POSTGRES_DB` |
|
||||||
| **用户名** | `postgres` | ConfigMap 中 `POSTGRES_USER` |
|
| **用户名** | `postgres` | ConfigMap 中 `POSTGRES_USER` |
|
||||||
| **密码** | `coslight` | ConfigMap `postgres-config` 中配置,生产环境迁移至 Secret |
|
| **密码** | `coslight` | ConfigMap `postgres-config` 中配置,生产环境迁移至 Secret |
|
||||||
| **存储** | `2Gi` | PVC `postgres-data` |
|
| **存储** | `6Gi` | PVC `postgres-data` |
|
||||||
|
| **CPU** | `100m` 请求 / `500m` 上限 | StatefulSet `resources` 字段 |
|
||||||
|
| **内存** | `256Mi` 请求 / `512Mi` 上限 | StatefulSet `resources` 字段 |
|
||||||
|
|
||||||
|
> **注意:** 密码当前以明文形式存储在 `pg-configmap.yaml` 中,生产环境应将其迁移至 K8s Secret,并通过环境变量注入容器,避免将明文密码提交至版本库。
|
||||||
|
|
||||||
##### 4.4.1 等待 Pod 就绪
|
##### 4.4.1 等待 Pod 就绪
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ spec:
|
||||||
containers:
|
containers:
|
||||||
- name: grafana
|
- name: grafana
|
||||||
image: grafana/grafana:10.4.2
|
image: grafana/grafana:10.4.2
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 3000
|
- containerPort: 3000
|
||||||
env:
|
env:
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ spec:
|
||||||
containers:
|
containers:
|
||||||
- name: jaeger
|
- name: jaeger
|
||||||
image: jaegertracing/all-in-one:1.56
|
image: jaegertracing/all-in-one:1.56
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
env:
|
env:
|
||||||
- name: COLLECTOR_OTLP_ENABLED
|
- name: COLLECTOR_OTLP_ENABLED
|
||||||
value: "true"
|
value: "true"
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ spec:
|
||||||
containers:
|
containers:
|
||||||
- name: loki
|
- name: loki
|
||||||
image: grafana/loki:2.9.4
|
image: grafana/loki:2.9.4
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
args:
|
args:
|
||||||
- -config.file=/etc/loki/loki.yaml
|
- -config.file=/etc/loki/loki.yaml
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ spec:
|
||||||
- mongosh
|
- mongosh
|
||||||
- --eval
|
- --eval
|
||||||
- "db.adminCommand('ping')"
|
- "db.adminCommand('ping')"
|
||||||
initialDelaySeconds: 10
|
initialDelaySeconds: 30
|
||||||
periodSeconds: 5
|
periodSeconds: 10
|
||||||
timeoutSeconds: 3
|
timeoutSeconds: 10
|
||||||
failureThreshold: 12
|
failureThreshold: 12
|
||||||
livenessProbe:
|
livenessProbe:
|
||||||
exec:
|
exec:
|
||||||
|
|
@ -44,10 +44,10 @@ spec:
|
||||||
- mongosh
|
- mongosh
|
||||||
- --eval
|
- --eval
|
||||||
- "db.adminCommand('ping')"
|
- "db.adminCommand('ping')"
|
||||||
initialDelaySeconds: 30
|
initialDelaySeconds: 120
|
||||||
periodSeconds: 20
|
periodSeconds: 10
|
||||||
timeoutSeconds: 3
|
timeoutSeconds: 30
|
||||||
failureThreshold: 3
|
failureThreshold: 5
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
cpu: 100m
|
cpu: 100m
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ spec:
|
||||||
containers:
|
containers:
|
||||||
- name: promtail
|
- name: promtail
|
||||||
image: grafana/promtail:2.9.4
|
image: grafana/promtail:2.9.4
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
args:
|
args:
|
||||||
- -config.file=/etc/promtail/promtail.yaml
|
- -config.file=/etc/promtail/promtail.yaml
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ spec:
|
||||||
containers:
|
containers:
|
||||||
- name: rabbitmq
|
- name: rabbitmq
|
||||||
image: rabbitmq:4.1.1-management-alpine
|
image: rabbitmq:4.1.1-management-alpine
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 4369
|
- containerPort: 4369
|
||||||
- containerPort: 5671
|
- containerPort: 5671
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ spec:
|
||||||
containers:
|
containers:
|
||||||
- name: redis
|
- name: redis
|
||||||
image: redis/redis-stack-server:latest
|
image: redis/redis-stack-server:latest
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
memory: "128Mi"
|
memory: "128Mi"
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,7 @@ func (g *Graph) AddEdge(from, to uuid.UUID) {
|
||||||
|
|
||||||
// 创建新的拓扑信息时,如果被链接的点已经存在于游离节点中
|
// 创建新的拓扑信息时,如果被链接的点已经存在于游离节点中
|
||||||
// 则将其移除
|
// 则将其移除
|
||||||
if _, exist := g.FreeVertexs[toKey]; exist {
|
delete(g.FreeVertexs, toKey)
|
||||||
delete(g.FreeVertexs, toKey)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DelNode delete a node to the graph
|
// DelNode delete a node to the graph
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,7 @@ func newLokiSyncer(lCfg config.LokiConfig) *lokiSyncer {
|
||||||
client: &http.Client{Timeout: 5 * time.Second},
|
client: &http.Client{Timeout: 5 * time.Second},
|
||||||
ch: make(chan string, 512),
|
ch: make(chan string, 512),
|
||||||
}
|
}
|
||||||
ls.wg.Add(1)
|
ls.wg.Go(ls.run)
|
||||||
go ls.run()
|
|
||||||
return ls
|
return ls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,7 +69,6 @@ func (ls *lokiSyncer) Sync() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *lokiSyncer) run() {
|
func (ls *lokiSyncer) run() {
|
||||||
defer ls.wg.Done()
|
|
||||||
ticker := time.NewTicker(2 * time.Second)
|
ticker := time.NewTicker(2 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -185,13 +185,11 @@ func (w *TaskWorker) Start() error {
|
||||||
|
|
||||||
// Start multiple consumers for better throughput
|
// Start multiple consumers for better throughput
|
||||||
for i := 0; i < w.cfg.QueueConsumerCount; i++ {
|
for i := 0; i < w.cfg.QueueConsumerCount; i++ {
|
||||||
w.wg.Add(1)
|
w.wg.Go(func() { w.consumerLoop(i) })
|
||||||
go w.consumerLoop(i)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start health check goroutine
|
// Start health check goroutine
|
||||||
w.wg.Add(1)
|
w.wg.Go(w.healthCheckLoop)
|
||||||
go w.healthCheckLoop()
|
|
||||||
|
|
||||||
logger.Info(w.ctx, "task worker started successfully")
|
logger.Info(w.ctx, "task worker started successfully")
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -199,8 +197,6 @@ func (w *TaskWorker) Start() error {
|
||||||
|
|
||||||
// consumerLoop runs a single RabbitMQ consumer
|
// consumerLoop runs a single RabbitMQ consumer
|
||||||
func (w *TaskWorker) consumerLoop(consumerID int) {
|
func (w *TaskWorker) consumerLoop(consumerID int) {
|
||||||
defer w.wg.Done()
|
|
||||||
|
|
||||||
logger.Info(w.ctx, "starting consumer", "consumer_id", consumerID)
|
logger.Info(w.ctx, "starting consumer", "consumer_id", consumerID)
|
||||||
|
|
||||||
// Consume messages from the queue
|
// Consume messages from the queue
|
||||||
|
|
@ -478,8 +474,6 @@ func (w *TaskWorker) dispatch(ctx context.Context, taskType TaskType, taskID uui
|
||||||
|
|
||||||
// healthCheckLoop periodically checks worker health and metrics
|
// healthCheckLoop periodically checks worker health and metrics
|
||||||
func (w *TaskWorker) healthCheckLoop() {
|
func (w *TaskWorker) healthCheckLoop() {
|
||||||
defer w.wg.Done()
|
|
||||||
|
|
||||||
ticker := time.NewTicker(w.cfg.PollingInterval)
|
ticker := time.NewTicker(w.cfg.PollingInterval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue