mirror of
https://github.com/mudler/edgevpn.git
synced 2025-11-02 12:44:08 +08:00
⚙️ Attach pprof to API for debugging
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"io/fs"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -62,7 +63,7 @@ const (
|
||||
PeerstoreURL = "/api/peerstore"
|
||||
)
|
||||
|
||||
func API(ctx context.Context, l string, defaultInterval, timeout time.Duration, e *node.Node) error {
|
||||
func API(ctx context.Context, l string, defaultInterval, timeout time.Duration, e *node.Node, debugMode bool) error {
|
||||
|
||||
ledger, _ := e.Ledger()
|
||||
|
||||
@@ -77,6 +78,9 @@ func API(ctx context.Context, l string, defaultInterval, timeout time.Duration,
|
||||
}
|
||||
|
||||
assetHandler := http.FileServer(getFileSystem())
|
||||
if debugMode {
|
||||
ec.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux))
|
||||
}
|
||||
|
||||
// Get data from ledger
|
||||
ec.GET(FileURL, func(c echo.Context) error {
|
||||
|
||||
@@ -54,7 +54,7 @@ var _ = Describe("API", func() {
|
||||
e.Start(ctx)
|
||||
|
||||
go func() {
|
||||
err := API(ctx, fmt.Sprintf("unix://%s", socket), 10*time.Second, 20*time.Second, e)
|
||||
err := API(ctx, fmt.Sprintf("unix://%s", socket), 10*time.Second, 20*time.Second, e, false)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}()
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ func API() cli.Command {
|
||||
A simple UI interface is available to display network data.`,
|
||||
UsageText: "edgevpn api",
|
||||
Flags: append(CommonFlags,
|
||||
&cli.BoolFlag{
|
||||
Name: "debug",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "listen",
|
||||
Value: ":8080",
|
||||
@@ -53,7 +56,7 @@ A simple UI interface is available to display network data.`,
|
||||
return err
|
||||
}
|
||||
|
||||
return api.API(ctx, c.String("listen"), 5*time.Second, 20*time.Second, e)
|
||||
return api.API(ctx, c.String("listen"), 5*time.Second, 20*time.Second, e, c.Bool("debug"))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@ func MainFlags() []cli.Flag {
|
||||
Name: "b",
|
||||
Usage: "Encodes the new config in base64, so it can be used as a token",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Usage: "Starts API with pprof attached",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "api",
|
||||
Usage: "Starts also the API daemon locally for inspecting the network status",
|
||||
@@ -223,7 +227,7 @@ func Main() func(c *cli.Context) error {
|
||||
}
|
||||
|
||||
if c.Bool("api") {
|
||||
go api.API(ctx, c.String("api-listen"), 5*time.Second, 20*time.Second, e)
|
||||
go api.API(ctx, c.String("api-listen"), 5*time.Second, 20*time.Second, e, c.Bool("debug"))
|
||||
}
|
||||
|
||||
return e.Start(ctx)
|
||||
|
||||
@@ -38,6 +38,9 @@ func Proxy() cli.Command {
|
||||
Usage: "Listening address",
|
||||
EnvVar: "PROXYLISTEN",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "debug",
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "interval",
|
||||
Usage: "proxy announce time interval",
|
||||
@@ -71,7 +74,7 @@ func Proxy() cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
return api.API(ctx, c.String("listen"), 5*time.Second, 20*time.Second, e)
|
||||
return api.API(ctx, c.String("listen"), 5*time.Second, 20*time.Second, e, c.Bool("debug"))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user