Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated backport of #1498: Use the Admiral metrics/profile helper and enable profiling #1526

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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
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.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=
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
}
Loading