Skip to content

Commit

Permalink
add switch for pprof (#46)
Browse files Browse the repository at this point in the history
* add switch for pprof

* add changelog v1.3.1
  • Loading branch information
weilaaa authored Sep 6, 2023
1 parent f3a26cd commit 9487e2d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v1.3.1
2023-09-05
## Feature
- add switch for pprof [#46](https://github.com/kubecube-io/kubecube-webconsole/pull/39)
## Dependency:
- kubecube 1.4.0+

# v1.3.0
2023-03-16
## Feature
Expand Down
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 9487e2d

Please sign in to comment.