From ef85f577fbd20d892846a6aaeb32fb37e9a34c1f Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Thu, 1 Feb 2024 16:42:37 +0100 Subject: [PATCH] Use the Admiral metrics/profile helper and enable profiling The CoreDNS plugin uses the built-in profiling support. Signed-off-by: Stephen Kitt --- go.mod | 2 +- go.sum | 4 ++-- pkg/agent/main.go | 25 ++----------------------- 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 255f3bb0e..c2960f597 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/onsi/gomega v1.31.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.18.0 - github.com/submariner-io/admiral v0.17.0 + github.com/submariner-io/admiral v0.17.1-0.20240326134036-98f201ca3674 github.com/submariner-io/shipyard v0.17.0 k8s.io/api v0.29.1 k8s.io/apimachinery v0.29.1 diff --git a/go.sum b/go.sum index a5797fd55..f9ab7f708 100644 --- a/go.sum +++ b/go.sum @@ -390,8 +390,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/submariner-io/admiral v0.17.0 h1:Hz722z70W8hPAlKv/Y70MhNGwmmjl4eMZ+bDw9S+BAQ= -github.com/submariner-io/admiral v0.17.0/go.mod h1:OYkNN5EYaMZ1w1qxzVzD5q8hVNtojQkVoNPcO8/LL+Y= +github.com/submariner-io/admiral v0.17.1-0.20240326134036-98f201ca3674 h1:gAVNTHz4scVMNGnBvjdB4Dk3BGhpit+Qs8cN18yxpJ0= +github.com/submariner-io/admiral v0.17.1-0.20240326134036-98f201ca3674/go.mod h1:OYkNN5EYaMZ1w1qxzVzD5q8hVNtojQkVoNPcO8/LL+Y= github.com/submariner-io/shipyard v0.17.0 h1:MMs7LkptS4QabYzRrvxxauJov0uQ0gAcdSjBkebpyNU= github.com/submariner-io/shipyard v0.17.0/go.mod h1:1TX7V+rxEEEZKm5t7kruTyBm52eOk7PSBJLAqMrqNNc= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= diff --git a/pkg/agent/main.go b/pkg/agent/main.go index 94296296d..5b2212bb7 100644 --- a/pkg/agent/main.go +++ b/pkg/agent/main.go @@ -19,15 +19,12 @@ limitations under the License. package main import ( - "errors" "flag" "fmt" - "net/http" "os" - "time" "github.com/kelseyhightower/envconfig" - "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/submariner-io/admiral/pkg/http" "github.com/submariner-io/admiral/pkg/log" "github.com/submariner-io/admiral/pkg/log/kzerolog" "github.com/submariner-io/admiral/pkg/names" @@ -147,15 +144,11 @@ func main() { err = lightHouseAgent.Start(ctx.Done()) exitOnError(err, "Failed to start lighthouse agent") - httpServer := startHTTPServer() + defer http.StartServer(http.Metrics|http.Profile, 8082)() <-ctx.Done() logger.Info("All controllers stopped or exited. Stopping main loop") - - if err := httpServer.Shutdown(ctx); err != nil { - logger.Error(err, "Error shutting down metrics HTTP server") - } } func init() { @@ -163,17 +156,3 @@ func init() { flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") } - -func startHTTPServer() *http.Server { - srv := &http.Server{Addr: ":8082", ReadHeaderTimeout: 60 * time.Second} - - http.Handle("/metrics", promhttp.Handler()) - - go func() { - if err := srv.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) { - logger.Error(err, "Error starting metrics server") - } - }() - - return srv -}