fix: fix K8s service names, deployment command, and GORM logger

- rename all K8s services to xxx-service convention and update
    all configmap references (postgres, mongodb, loki, jaeger)
  - add explicit command: ["/app/modelrt"] to deployment to prevent
    args from being treated as the executable (no ENTRYPOINT in
    Dockerfile)
  - set deploy_env to development to bypass Redis empty-password
    guard in non-production Minikube environment
  - fix GormLogger Info/Warn/Error to use fmt.Sprintf(msg, data...)
    so GORM printf-style messages are formatted correctly and avoid
    json: unsupported type: func() time.Time serialization panic
  - expand pg PVC storage from 2Gi to 6Gi
  - rename loop variable msg to task in PushTaskToRabbitMQ for clarity
  - align comment indentation in queue_producer.go
This commit is contained in:
douxu 2026-06-03 17:11:54 +08:00
parent 3309e53653
commit 195150d9b1
12 changed files with 49 additions and 47 deletions

View File

@ -10,7 +10,7 @@ data:
- name: Loki - name: Loki
type: loki type: loki
access: proxy access: proxy
url: http://loki:3100 url: http://loki-service:3100
isDefault: true isDefault: true
jsonData: jsonData:
# derivedFields: 从日志的 traceID 字段生成跳转链接到 Jaeger # derivedFields: 从日志的 traceID 字段生成跳转链接到 Jaeger
@ -23,4 +23,4 @@ data:
type: jaeger type: jaeger
uid: jaeger uid: jaeger
access: proxy access: proxy
url: http://jaeger:16686 url: http://jaeger-service:16686

View File

@ -1,7 +1,7 @@
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: grafana name: grafana-service
namespace: default namespace: default
spec: spec:
ports: ports:

View File

@ -1,7 +1,7 @@
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: jaeger name: jaeger-serivce
labels: labels:
app: jaeger app: jaeger
spec: spec:

View File

@ -1,7 +1,7 @@
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: loki name: loki-service
namespace: default namespace: default
spec: spec:
ports: ports:

View File

@ -5,7 +5,7 @@ metadata:
data: data:
config.yaml: | config.yaml: |
postgres: postgres:
host: "192.168.1.101" host: "postgres-service"
port: 5432 port: 5432
database: "demo" database: "demo"
user: "postgres" user: "postgres"
@ -35,7 +35,7 @@ data:
endpoint: "" # Promtail handles log collection in K8s, direct push disabled endpoint: "" # Promtail handles log collection in K8s, direct push disabled
otel: otel:
endpoint: "jaeger:4318" endpoint: "jaeger-service:4318"
insecure: true insecure: true
ants: ants:
@ -77,7 +77,7 @@ data:
service_addr: ":8080" service_addr: ":8080"
service_name: "modelRT" service_name: "modelRT"
secret_key: "" # injected via env SERVICE_SECRET_KEY secret_key: "" # injected via env SERVICE_SECRET_KEY
deploy_env: "production" deploy_env: "development"
dataRT: dataRT:
host: "http://127.0.0.1" host: "http://127.0.0.1"

View File

@ -16,8 +16,9 @@ spec:
spec: spec:
containers: containers:
- name: modelrt - name: modelrt
image: coslight/modelrt:latest image: modelrt:v1
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
command: ["/app/modelrt"]
args: args:
- "-modelRT_config_dir=/app/configs" - "-modelRT_config_dir=/app/configs"
- "-modelRT_config_name=config" - "-modelRT_config_name=config"

View File

@ -1,7 +1,7 @@
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: mongodb name: mongodb-service
labels: labels:
app: mongodb app: mongodb
spec: spec:

View File

@ -7,4 +7,4 @@ spec:
- ReadWriteOnce - ReadWriteOnce
resources: resources:
requests: requests:
storage: 2Gi storage: 6Gi

View File

@ -1,7 +1,7 @@
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: postgres name: postgres-service
labels: labels:
app: postgres app: postgres
spec: spec:

View File

@ -13,7 +13,7 @@ data:
filename: /tmp/positions.yaml filename: /tmp/positions.yaml
clients: clients:
- url: http://loki:3100/loki/api/v1/push - url: http://loki-service:3100/loki/api/v1/push
scrape_configs: scrape_configs:
- job_name: kubernetes-pods - job_name: kubernetes-pods

View File

@ -4,6 +4,7 @@ package logger
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
@ -29,17 +30,17 @@ func (l *GormLogger) LogMode(_ gormLogger.LogLevel) gormLogger.Interface {
// Info define func for implementing gormLogger.Interface // Info define func for implementing gormLogger.Interface
func (l *GormLogger) Info(ctx context.Context, msg string, data ...any) { func (l *GormLogger) Info(ctx context.Context, msg string, data ...any) {
Info(ctx, msg, "data", data) Info(ctx, fmt.Sprintf(msg, data...))
} }
// Warn define func for implementing gormLogger.Interface // Warn define func for implementing gormLogger.Interface
func (l *GormLogger) Warn(ctx context.Context, msg string, data ...any) { func (l *GormLogger) Warn(ctx context.Context, msg string, data ...any) {
Warn(ctx, msg, "data", data) Warn(ctx, fmt.Sprintf(msg, data...))
} }
// Error define func for implementing gormLogger.Interface // Error define func for implementing gormLogger.Interface
func (l *GormLogger) Error(ctx context.Context, msg string, data ...any) { func (l *GormLogger) Error(ctx context.Context, msg string, data ...any) {
Error(ctx, msg, "data", data) Error(ctx, fmt.Sprintf(msg, data...))
} }
// Trace define func for implementing gormLogger.Interface // Trace define func for implementing gormLogger.Interface

View File

@ -246,20 +246,20 @@ func PushTaskToRabbitMQ(ctx context.Context, cfg config.RabbitMQConfig, taskChan
case <-ctx.Done(): case <-ctx.Done():
logger.Info(ctx, "push task to RabbitMQ stopped by context cancel") logger.Info(ctx, "push task to RabbitMQ stopped by context cancel")
return return
case msg, ok := <-taskChan: case task, ok := <-taskChan:
if !ok { if !ok {
logger.Info(ctx, "task channel closed, exiting push loop") logger.Info(ctx, "task channel closed, exiting push loop")
return return
} }
// Restore trace context from the handler that enqueued this message // Restore trace context from the handler that enqueued this message
taskCtx := otel.GetTextMapPropagator().Extract(ctx, propagation.MapCarrier(msg.TraceCarrier)) taskCtx := otel.GetTextMapPropagator().Extract(ctx, propagation.MapCarrier(task.TraceCarrier))
taskCtx, pubSpan := otel.Tracer("modelRT/task").Start(taskCtx, "task.publish", taskCtx, pubSpan := otel.Tracer("modelRT/task").Start(taskCtx, "task.publish",
oteltrace.WithAttributes(attribute.String("task_id", msg.TaskID.String())), oteltrace.WithAttributes(attribute.String("task_id", task.TaskID.String())),
) )
if err := producer.PublishTaskWithRetry(taskCtx, msg.TaskID, msg.TaskType, msg.Priority, msg.Params, 3); err != nil { if err := producer.PublishTaskWithRetry(taskCtx, task.TaskID, task.TaskType, task.Priority, task.Params, 3); err != nil {
pubSpan.RecordError(err) pubSpan.RecordError(err)
logger.Error(taskCtx, "publish task to RabbitMQ failed", logger.Error(taskCtx, "publish task to RabbitMQ failed",
"task_id", msg.TaskID, "error", err) "task_id", task.TaskID, "error", err)
} }
pubSpan.End() pubSpan.End()
} }