this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move metrics to a different port for Palomar and BGS (#374)

authored by

Jaz and committed by
GitHub
7bf6d21e c2be5868

+34 -13
+9 -8
bgs/bgs.go
··· 38 38 "github.com/labstack/echo/v4" 39 39 "github.com/labstack/echo/v4/middleware" 40 40 promclient "github.com/prometheus/client_golang/prometheus" 41 + "github.com/prometheus/client_golang/prometheus/promhttp" 41 42 dto "github.com/prometheus/client_model/go" 42 43 "go.opentelemetry.io/otel" 43 44 "go.opentelemetry.io/otel/attribute" ··· 142 143 return bgs, nil 143 144 } 144 145 146 + func (bgs *BGS) StartMetrics(listen string) error { 147 + http.Handle("/metrics", promhttp.Handler()) 148 + return http.ListenAndServe(listen, nil) 149 + } 150 + 151 + // Disabled for now, maybe reimplement behind admin auth later 145 152 func (bgs *BGS) StartDebug(listen string) error { 146 153 http.HandleFunc("/repodbg/user", func(w http.ResponseWriter, r *http.Request) { 147 154 ctx := r.Context() ··· 258 265 } else { 259 266 e.Use(middleware.LoggerWithConfig(middleware.DefaultLoggerConfig)) 260 267 } 261 - 262 - e.Use(MetricsMiddleware) 263 268 264 269 // React uses a virtual router, so we need to serve the index.html for all 265 270 // routes that aren't otherwise handled or in the /assets directory. ··· 267 272 e.File("/dash/*", "/public/index.html") 268 273 e.Static("/assets", "/public/assets") 269 274 275 + e.Use(MetricsMiddleware) 276 + 270 277 e.HTTPErrorHandler = func(err error, ctx echo.Context) { 271 278 switch err := err.(type) { 272 279 case *echo.HTTPError: ··· 308 315 e.GET("/xrpc/com.atproto.sync.getLatestCommit", bgs.HandleComAtprotoSyncGetLatestCommit) 309 316 e.GET("/xrpc/com.atproto.sync.notifyOfUpdate", bgs.HandleComAtprotoSyncNotifyOfUpdate) 310 317 e.GET("/xrpc/_health", bgs.HandleHealthCheck) 311 - 312 - promh := prometheusHandler() 313 - e.GET("/metrics", func(e echo.Context) error { 314 - promh.ServeHTTP(e.Response().Writer, e.Request()) 315 - return nil 316 - }) 317 318 318 319 admin := e.Group("/admin", bgs.checkAdminAuth) 319 320
+6 -5
cmd/bigsky/main.go
··· 105 105 Value: ":2470", 106 106 }, 107 107 &cli.StringFlag{ 108 - Name: "debug-listen", 109 - Value: "localhost:2471", 108 + Name: "metrics-listen", 109 + Value: ":2471", 110 + EnvVars: []string{"BGS_METRICS_LISTEN"}, 110 111 }, 111 112 &cli.StringFlag{ 112 113 Name: "disk-blob-store", ··· 340 341 } 341 342 } 342 343 343 - // set up pprof endpoint 344 + // set up metrics endpoint 344 345 go func() { 345 - if err := bgs.StartDebug(cctx.String("debug-listen")); err != nil { 346 - panic(err) 346 + if err := bgs.StartMetrics(cctx.String("metrics-listen")); err != nil { 347 + log.Fatalf("failed to start metrics endpoint: %s", err) 347 348 } 348 349 }() 349 350
+13
cmd/palomar/main.go
··· 121 121 Value: ":3999", 122 122 EnvVars: []string{"PALOMAR_BIND"}, 123 123 }, 124 + &cli.StringFlag{ 125 + Name: "metrics-listen", 126 + Usage: "IP or address, and port, to listen on for metrics APIs", 127 + Value: ":3998", 128 + EnvVars: []string{"PALOMAR_METRICS_LISTEN"}, 129 + }, 124 130 &cli.IntFlag{ 125 131 Name: "bgs-sync-rate-limit", 126 132 Usage: "max repo sync (checkout) requests per second to upstream (BGS)", ··· 184 190 if err != nil { 185 191 return err 186 192 } 193 + 194 + go func() { 195 + if err := srv.RunMetrics(cctx.String("metrics-listen")); err != nil { 196 + slog.Error("failed to start metrics endpoint", "error", err) 197 + panic(fmt.Errorf("failed to start metrics endpoint: %w", err)) 198 + } 199 + }() 187 200 188 201 go func() { 189 202 srv.RunAPI(cctx.String("bind"))
+6
search/server.go
··· 6 6 "fmt" 7 7 "io" 8 8 "log/slog" 9 + "net/http" 9 10 "os" 10 11 "strings" 11 12 ··· 205 206 206 207 s.logger.Info("starting search API daemon", "bind", listen) 207 208 return s.echo.Start(listen) 209 + } 210 + 211 + func (s *Server) RunMetrics(listen string) error { 212 + http.Handle("/metrics", promhttp.Handler()) 213 + return http.ListenAndServe(listen, nil) 208 214 } 209 215 210 216 func (s *Server) Shutdown(ctx context.Context) error {