feat(server): serve /metrics endpoint when embedded metrics enabled
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/claude-agent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -26,7 +26,7 @@ type Server struct {
|
|||||||
apiKeys atomic.Pointer[map[string]struct{}]
|
apiKeys atomic.Pointer[map[string]struct{}]
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *config.Config, pool *auth.Pool, profile *proxy.SniffedProfile, tracker *ratelimit.Tracker) *Server {
|
func New(cfg *config.Config, pool *auth.Pool, profile *proxy.SniffedProfile, tracker *ratelimit.Tracker, metricsHandler http.Handler) *Server {
|
||||||
s := &Server{configPath: "config.yaml"}
|
s := &Server{configPath: "config.yaml"}
|
||||||
|
|
||||||
san := proxy.NewSanitizer(cfg.Sanitize)
|
san := proxy.NewSanitizer(cfg.Sanitize)
|
||||||
@@ -39,7 +39,7 @@ func New(cfg *config.Config, pool *auth.Pool, profile *proxy.SniffedProfile, tra
|
|||||||
engine := gin.New()
|
engine := gin.New()
|
||||||
engine.Use(gin.Recovery())
|
engine.Use(gin.Recovery())
|
||||||
engine.Use(corsMiddleware())
|
engine.Use(corsMiddleware())
|
||||||
if cfg.Telemetry.ExportEnabled() {
|
if cfg.Telemetry.Export.Enabled() {
|
||||||
engine.Use(otelgin.Middleware(cfg.Telemetry.ServiceName))
|
engine.Use(otelgin.Middleware(cfg.Telemetry.ServiceName))
|
||||||
}
|
}
|
||||||
engine.Use(s.authMiddleware())
|
engine.Use(s.authMiddleware())
|
||||||
@@ -51,6 +51,10 @@ func New(cfg *config.Config, pool *auth.Pool, profile *proxy.SniffedProfile, tra
|
|||||||
engine.POST("/v1/messages", handler)
|
engine.POST("/v1/messages", handler)
|
||||||
engine.POST("/messages", handler)
|
engine.POST("/messages", handler)
|
||||||
|
|
||||||
|
if metricsHandler != nil {
|
||||||
|
engine.GET("/metrics", gin.WrapH(metricsHandler))
|
||||||
|
}
|
||||||
|
|
||||||
engine.POST("/reload", s.handleReload())
|
engine.POST("/reload", s.handleReload())
|
||||||
engine.POST("/debug/refresh", handleDebugRefresh(pool))
|
engine.POST("/debug/refresh", handleDebugRefresh(pool))
|
||||||
engine.GET("/healthz", func(c *gin.Context) {
|
engine.GET("/healthz", func(c *gin.Context) {
|
||||||
@@ -137,7 +141,7 @@ func corsMiddleware() gin.HandlerFunc {
|
|||||||
func (s *Server) authMiddleware() gin.HandlerFunc {
|
func (s *Server) authMiddleware() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
path := c.Request.URL.Path
|
path := c.Request.URL.Path
|
||||||
if path == "/healthz" || path == "/reload" {
|
if path == "/healthz" || path == "/reload" || path == "/metrics" {
|
||||||
c.Next()
|
c.Next()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user