Skip to content

Commit

Permalink
Use the Admiral metrics/profile helper and enable profiling
Browse files Browse the repository at this point in the history
The CoreDNS plugin uses the built-in profiling support.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
  • Loading branch information
skitt committed Feb 2, 2024
1 parent c409afc commit 7cb220e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.18.0-m0
github.com/submariner-io/admiral v0.18.0-m0.0.20240202125330-437b20afae61
github.com/submariner-io/shipyard v0.18.0-m0
k8s.io/api v0.29.1
k8s.io/apimachinery v0.29.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.18.0-m0 h1:kGXUY4a/j1STdC3I173WnjurlWd6ADmhC16qRB+cNV0=
github.com/submariner-io/admiral v0.18.0-m0/go.mod h1:6WKEdEhKHUGbAz2EwMSALZpyT0iWKQX6noJyEezyDTI=
github.com/submariner-io/admiral v0.18.0-m0.0.20240202125330-437b20afae61 h1:XVWSRQ959C0PRe6LkCMjvyWCOWh2Ns8WaIuMe8xLMz8=
github.com/submariner-io/admiral v0.18.0-m0.0.20240202125330-437b20afae61/go.mod h1:6WKEdEhKHUGbAz2EwMSALZpyT0iWKQX6noJyEezyDTI=
github.com/submariner-io/shipyard v0.18.0-m0 h1:d5iJP6LWyLprbMYdzVDh4mZn/Qsgt7X15Gamv1d5q+Y=
github.com/submariner-io/shipyard v0.18.0-m0/go.mod h1:1TX7V+rxEEEZKm5t7kruTyBm52eOk7PSBJLAqMrqNNc=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Expand Down
25 changes: 2 additions & 23 deletions pkg/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -147,33 +144,15 @@ 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() {
flag.StringVar(&kubeConfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
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
}

0 comments on commit 7cb220e

Please sign in to comment.