fix: error port for the pprof server (#2766)
Signed-off-by: saltbo <saltbo@foxmail.com>
This commit is contained in:
@@ -25,7 +25,6 @@ package profile
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
@@ -35,26 +34,18 @@ import (
|
|||||||
"github.com/fission/fission/pkg/utils/httpserver"
|
"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) {
|
func ProfileIfEnabled(ctx context.Context, logger *zap.Logger) {
|
||||||
enablePprof := os.Getenv("PPROF_ENABLED")
|
enablePprof := os.Getenv("PPROF_ENABLED")
|
||||||
if enablePprof != "true" {
|
if enablePprof != "true" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
pprofPort := os.Getenv("PPROF_PORT")
|
||||||
|
if pprofPort == "" {
|
||||||
|
pprofPort = "6060"
|
||||||
|
}
|
||||||
|
|
||||||
pprofMux := http.DefaultServeMux
|
pprofMux := http.DefaultServeMux
|
||||||
http.DefaultServeMux = http.NewServeMux()
|
http.DefaultServeMux = http.NewServeMux()
|
||||||
|
|
||||||
go httpserver.StartServer(ctx, logger, "pprof", getPprofAddr(), pprofMux)
|
go httpserver.StartServer(ctx, logger, "pprof", pprofPort, pprofMux)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user