feat(observability): 为 API 和 worker 增加独立 pprof 诊断端口

This commit is contained in:
tangerineyu
2026-03-25 19:27:33 +08:00
parent 21efce6049
commit 9a0ba45a51
7 changed files with 144 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
package observability
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestNewPprofMux(t *testing.T) {
t.Parallel()
req := httptest.NewRequest(http.MethodGet, "/debug/pprof/", nil)
rr := httptest.NewRecorder()
NewPprofMux().ServeHTTP(rr, req)
if rr.Code != http.StatusOK {
t.Errorf("Expected status code 200, got %d", rr.Code)
}
}
func TestStartPprofServerWithDisabled(t *testing.T) {
t.Parallel()
server, err := StartPprofServer("api", false, "localhost:6060")
if err != nil {
t.Fatalf("Failed to start pprof server: %v", err)
}
if server != nil {
t.Fatalf("Expected nil server when pprof is disabled, got non-nil")
}
}