feat(observability): 为 API 和 worker 增加独立 pprof 诊断端口
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
apphttp "feedsystem_video_go/internal/http"
|
||||
rabbitmq "feedsystem_video_go/internal/middleware/rabbitmq"
|
||||
rediscache "feedsystem_video_go/internal/middleware/redis"
|
||||
"feedsystem_video_go/internal/observability"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -64,6 +65,22 @@ func main() {
|
||||
defer rmq.Close()
|
||||
log.Printf("RabbitMQ connected")
|
||||
}
|
||||
// Pprof
|
||||
pprofServer, err := observability.StartPprofServer(
|
||||
"API",
|
||||
cfg.ObservabilityConfig.Pprof.Enabled,
|
||||
cfg.ObservabilityConfig.Pprof.ApiAddr,
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("Failed to start API pprof server: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 3 * time.Second)
|
||||
defer cancel()
|
||||
if err := observability.Shutdown(shutdownCtx, pprofServer); err != nil {
|
||||
log.Printf("Failed to shutdown API pprof server: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// 设置路由
|
||||
r := apphttp.SetRouter(sqlDB, cache, rmq)
|
||||
|
||||
Reference in New Issue
Block a user