Skip to content

Commit

Permalink
add switch for pprof
Browse files Browse the repository at this point in the history
  • Loading branch information
weilaaa committed Sep 5, 2023
1 parent f3a26cd commit 4f64e67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
20 changes: 11 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"flag"
"fmt"
consolelog "kubecube-webconsole/clog"
"net/http"
"os"
"time"
Expand All @@ -30,10 +29,11 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
consolelog "kubecube-webconsole/clog"
"kubecube-webconsole/handler"
"kubecube-webconsole/utils"
_ "net/http/pprof"
ctrl "sigs.k8s.io/controller-runtime"

"kubecube-webconsole/handler"
)

// leader flag
Expand Down Expand Up @@ -109,10 +109,12 @@ func runAPIServer() {
response.WriteHeader(statusCode)
})

go func() {
err := http.ListenAndServe(fmt.Sprintf(":%d", *handler.ServerPort), nil)
if err != nil {
clog.Fatal("ListenAndServe failed,error msg: %s", err.Error())
}
}()
if utils.EnablePprof() {
go func() {
err := http.ListenAndServe(fmt.Sprintf(":%d", *handler.ServerPort), nil)
if err != nil {
clog.Fatal("ListenAndServe failed,error msg: %s", err.Error())
}
}()
}
}
8 changes: 8 additions & 0 deletions utils/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ func GetKubeCubeSvc() string {
func getJwtSecret() string {
return os.Getenv("JWT_SECRET")
}

func EnablePprof() bool {
v := os.Getenv("ENABLE_PPROF")
if v == "" {
return false
}
return v == "true"
}

0 comments on commit 4f64e67

Please sign in to comment.