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:
parent
3309e53653
commit
195150d9b1
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: grafana
|
name: grafana-service
|
||||||
namespace: default
|
namespace: default
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
port: 3000
|
port: 3000
|
||||||
targetPort: 3000
|
targetPort: 3000
|
||||||
nodePort: 31000 # Grafana UI: http://<NodeIP>:31000
|
nodePort: 31000 # Grafana UI: http://<NodeIP>:31000
|
||||||
selector:
|
selector:
|
||||||
app: grafana
|
app: grafana
|
||||||
type: NodePort
|
type: NodePort
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
@ -9,19 +9,19 @@ spec:
|
||||||
- name: ui
|
- name: ui
|
||||||
port: 16686
|
port: 16686
|
||||||
targetPort: 16686
|
targetPort: 16686
|
||||||
nodePort: 31686 # Jaeger UI,浏览器访问 http://<NodeIP>:31686
|
nodePort: 31686 # Jaeger UI,浏览器访问 http://<NodeIP>:31686
|
||||||
- name: collector-http
|
- name: collector-http
|
||||||
port: 14268
|
port: 14268
|
||||||
targetPort: 14268
|
targetPort: 14268
|
||||||
nodePort: 31268 # Jaeger 原生 HTTP collector(非 OTel)
|
nodePort: 31268 # Jaeger 原生 HTTP collector(非 OTel)
|
||||||
- name: otlp-http
|
- name: otlp-http
|
||||||
port: 4318
|
port: 4318
|
||||||
targetPort: 4318
|
targetPort: 4318
|
||||||
nodePort: 31318 # OTLP HTTP,集群外使用 <NodeIP>:31318
|
nodePort: 31318 # OTLP HTTP,集群外使用 <NodeIP>:31318
|
||||||
- name: otlp-grpc
|
- name: otlp-grpc
|
||||||
port: 4317
|
port: 4317
|
||||||
targetPort: 4317
|
targetPort: 4317
|
||||||
nodePort: 31317 # OTLP gRPC,集群外使用 <NodeIP>:31317
|
nodePort: 31317 # OTLP gRPC,集群外使用 <NodeIP>:31317
|
||||||
selector:
|
selector:
|
||||||
app: jaeger
|
app: jaeger
|
||||||
type: NodePort
|
type: NodePort
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: loki
|
name: loki-service
|
||||||
namespace: default
|
namespace: default
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
port: 3100
|
port: 3100
|
||||||
targetPort: 3100
|
targetPort: 3100
|
||||||
nodePort: 31100 # 集群外访问: http://<NodeIP>:31100
|
nodePort: 31100 # 集群外访问: http://<NodeIP>:31100
|
||||||
selector:
|
selector:
|
||||||
app: loki
|
app: loki
|
||||||
type: NodePort
|
type: NodePort
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,4 @@ spec:
|
||||||
- ReadWriteOnce
|
- ReadWriteOnce
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 2Gi
|
storage: 6Gi
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,12 @@ func (p *QueueProducer) declareInfrastructure() error {
|
||||||
// Declare durable direct exchange
|
// Declare durable direct exchange
|
||||||
err := p.ch.ExchangeDeclare(
|
err := p.ch.ExchangeDeclare(
|
||||||
constants.TaskExchangeName, // name
|
constants.TaskExchangeName, // name
|
||||||
"direct", // type
|
"direct", // type
|
||||||
true, // durable
|
true, // durable
|
||||||
false, // auto-deleted
|
false, // auto-deleted
|
||||||
false, // internal
|
false, // internal
|
||||||
false, // no-wait
|
false, // no-wait
|
||||||
nil, // arguments
|
nil, // arguments
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to declare exchange: %w", err)
|
return fmt.Errorf("failed to declare exchange: %w", err)
|
||||||
|
|
@ -81,12 +81,12 @@ func (p *QueueProducer) declareInfrastructure() error {
|
||||||
// Declare durable queue with priority support and message TTL
|
// Declare durable queue with priority support and message TTL
|
||||||
_, err = p.ch.QueueDeclare(
|
_, err = p.ch.QueueDeclare(
|
||||||
constants.TaskQueueName, // name
|
constants.TaskQueueName, // name
|
||||||
true, // durable
|
true, // durable
|
||||||
false, // delete when unused
|
false, // delete when unused
|
||||||
false, // exclusive
|
false, // exclusive
|
||||||
false, // no-wait
|
false, // no-wait
|
||||||
amqp.Table{
|
amqp.Table{
|
||||||
"x-max-priority": constants.TaskMaxPriority, // support priority levels 0-10
|
"x-max-priority": constants.TaskMaxPriority, // support priority levels 0-10
|
||||||
"x-message-ttl": constants.TaskDefaultMessageTTL.Milliseconds(), // message TTL
|
"x-message-ttl": constants.TaskDefaultMessageTTL.Milliseconds(), // message TTL
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -99,8 +99,8 @@ func (p *QueueProducer) declareInfrastructure() error {
|
||||||
constants.TaskQueueName, // queue name
|
constants.TaskQueueName, // queue name
|
||||||
constants.TaskRoutingKey, // routing key
|
constants.TaskRoutingKey, // routing key
|
||||||
constants.TaskExchangeName, // exchange name
|
constants.TaskExchangeName, // exchange name
|
||||||
false, // no-wait
|
false, // no-wait
|
||||||
nil, // arguments
|
nil, // arguments
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to bind queue: %w", err)
|
return fmt.Errorf("failed to bind queue: %w", err)
|
||||||
|
|
@ -148,8 +148,8 @@ func (p *QueueProducer) PublishTask(ctx context.Context, taskID uuid.UUID, taskT
|
||||||
ctx,
|
ctx,
|
||||||
constants.TaskExchangeName, // exchange
|
constants.TaskExchangeName, // exchange
|
||||||
constants.TaskRoutingKey, // routing key
|
constants.TaskRoutingKey, // routing key
|
||||||
false, // mandatory
|
false, // mandatory
|
||||||
false, // immediate
|
false, // immediate
|
||||||
publishing,
|
publishing,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -211,10 +211,10 @@ func (p *QueueProducer) Close() error {
|
||||||
func (p *QueueProducer) GetQueueInfo() (*amqp.Queue, error) {
|
func (p *QueueProducer) GetQueueInfo() (*amqp.Queue, error) {
|
||||||
queue, err := p.ch.QueueDeclarePassive(
|
queue, err := p.ch.QueueDeclarePassive(
|
||||||
constants.TaskQueueName, // name
|
constants.TaskQueueName, // name
|
||||||
true, // durable
|
true, // durable
|
||||||
false, // delete when unused
|
false, // delete when unused
|
||||||
false, // exclusive
|
false, // exclusive
|
||||||
false, // no-wait
|
false, // no-wait
|
||||||
amqp.Table{
|
amqp.Table{
|
||||||
"x-max-priority": constants.TaskMaxPriority,
|
"x-max-priority": constants.TaskMaxPriority,
|
||||||
"x-message-ttl": constants.TaskDefaultMessageTTL.Milliseconds(),
|
"x-message-ttl": constants.TaskDefaultMessageTTL.Milliseconds(),
|
||||||
|
|
@ -246,22 +246,22 @@ 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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue