-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose metrics for registration service on a separate server/port to avoid making them available from the current Route include a unit test to verify that the new `sandbox_promhttp_*` metrics are exposed on the `/metrics` endpoint Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
- Loading branch information
Showing
21 changed files
with
451 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package middleware | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// see https://pkg.go.dev/github.com/prometheus/client_golang/prometheus/promhttp#example-InstrumentRoundTripperDuration | ||
|
||
func InstrumentRoundTripperInFlight(gauge prometheus.Gauge) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
gauge.Inc() | ||
defer func() { | ||
gauge.Dec() | ||
}() | ||
c.Next() | ||
} | ||
} | ||
|
||
func InstrumentRoundTripperCounter(counter *prometheus.CounterVec) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
defer func() { | ||
counter.With(prometheus.Labels{ | ||
"code": strconv.Itoa(c.Writer.Status()), | ||
"method": c.Request.Method, | ||
"path": c.Request.URL.Path, | ||
}).Inc() | ||
}() | ||
c.Next() | ||
} | ||
} | ||
|
||
func InstrumentRoundTripperDuration(histVec *prometheus.HistogramVec) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
start := time.Now() | ||
defer func() { | ||
duration := time.Since(start) | ||
histVec.With(prometheus.Labels{ | ||
"code": strconv.Itoa(c.Writer.Status()), | ||
"method": c.Request.Method, | ||
"path": c.Request.URL.Path, | ||
}).Observe(float64(duration.Milliseconds())) | ||
}() | ||
c.Next() | ||
} | ||
} |
Oops, something went wrong.