Skip to content

Commit

Permalink
add a handler for /metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorVin committed Jun 10, 2024
1 parent 71fc2ba commit d6909a4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/httpsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
ginzap "github.com/gin-contrib/zap"
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.hollow.sh/toolbox/events"
"go.hollow.sh/toolbox/ginauth"
"go.hollow.sh/toolbox/ginjwt"
Expand Down Expand Up @@ -42,6 +43,12 @@ var (
noOpAuthMiddleware = &ginauth.MultiTokenMiddleware{}
)

func getGinPrometheusAdapter(h http.Handler) gin.HandlerFunc {
return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}

func (s *Server) setup() *gin.Engine {
var err error
authMW := noOpAuthMiddleware
Expand Down Expand Up @@ -118,6 +125,8 @@ func (s *Server) setup() *gin.Engine {
r.GET("/healthz/liveness", s.livenessCheck)
r.GET("/healthz/readiness", s.readinessCheck)

r.GET("/metrics", getGinPrometheusAdapter(promhttp.Handler()))

v1 := r.Group("/api/v1")
{
v1Rtr.Routes(v1)
Expand Down

0 comments on commit d6909a4

Please sign in to comment.