fix: error port for the pprof server (#2766)

Signed-off-by: saltbo <saltbo@foxmail.com>
This commit is contained in:
Ambor
2023-04-11 08:43:36 +05:30
committed by GitHub
parent 32530ac474
commit cd742a6d18
+5 -14
View File
@@ -25,7 +25,6 @@ package profile
import (
"context"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
@@ -35,26 +34,18 @@ import (
"github.com/fission/fission/pkg/utils/httpserver"
)
func getPprofAddr() string {
pprofHost := os.Getenv("PPROF_HOST")
if pprofHost == "" {
pprofHost = "localhost"
}
pprofPort := os.Getenv("PPROF_PORT")
if pprofPort == "" {
pprofPort = "6060"
}
return fmt.Sprintf("%s:%s", pprofHost, pprofPort)
}
func ProfileIfEnabled(ctx context.Context, logger *zap.Logger) {
enablePprof := os.Getenv("PPROF_ENABLED")
if enablePprof != "true" {
return
}
pprofPort := os.Getenv("PPROF_PORT")
if pprofPort == "" {
pprofPort = "6060"
}
pprofMux := http.DefaultServeMux
http.DefaultServeMux = http.NewServeMux()
go httpserver.StartServer(ctx, logger, "pprof", getPprofAddr(), pprofMux)
go httpserver.StartServer(ctx, logger, "pprof", pprofPort, pprofMux)
}