cmd/kg: add pprof endpoints
This commit enhances the Kilo agent internal HTTP server to include pprof endpoints. For simplicity, this commit migrates the internal server creation to https://github.com/metalmatze/signal/internalserver, which allows for easy registration of common internal server observability endpoints. Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
This commit is contained in:
parent
826593d6ba
commit
7291a3bd71
@ -27,10 +27,10 @@ import (
|
||||
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/go-kit/kit/log/level"
|
||||
"github.com/metalmatze/signal/internalserver"
|
||||
"github.com/oklog/run"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/spf13/cobra"
|
||||
apiextensions "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@ -251,18 +251,21 @@ func runRoot(_ *cobra.Command, _ []string) error {
|
||||
|
||||
var g run.Group
|
||||
{
|
||||
h := internalserver.NewHandler(
|
||||
internalserver.WithName("Internal Kilo API"),
|
||||
internalserver.WithPrometheusRegistry(registry),
|
||||
internalserver.WithPProf(),
|
||||
)
|
||||
h.AddEndpoint("/health", "Exposes health checks", healthHandler)
|
||||
h.AddEndpoint("/graph", "Exposes Kilo mesh topology graph", (&graphHandler{m, gr, &hostname, s}).ServeHTTP)
|
||||
// Run the HTTP server.
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/health", healthHandler)
|
||||
mux.Handle("/graph", &graphHandler{m, gr, &hostname, s})
|
||||
mux.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
|
||||
l, err := net.Listen("tcp", listen)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to listen on %s: %v", listen, err)
|
||||
}
|
||||
|
||||
g.Add(func() error {
|
||||
if err := http.Serve(l, mux); err != nil && err != http.ErrServerClosed {
|
||||
if err := http.Serve(l, h); err != nil && err != http.ErrServerClosed {
|
||||
return fmt.Errorf("error: server exited unexpectedly: %v", err)
|
||||
}
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user