Skip to content

Commit 469b374

Browse files
authored
don't use empty path as label for LAPI hits metrics (#4106)
1 parent df8918b commit 469b374

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

pkg/apiserver/controllers/v1/metrics.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ func PrometheusMachinesMiddleware() gin.HandlerFunc {
3030
return func(c *gin.Context) {
3131
machineID, _ := getMachineIDFromContext(c)
3232
if machineID != "" {
33+
fullPath := c.FullPath()
34+
if fullPath == "" {
35+
fullPath = "invalid-endpoint"
36+
}
3337
metrics.LapiMachineHits.With(prometheus.Labels{
3438
"machine": machineID,
35-
"route": c.FullPath(),
39+
"route": fullPath,
3640
"method": c.Request.Method,
3741
}).Inc()
3842
}
@@ -45,9 +49,13 @@ func PrometheusBouncersMiddleware() gin.HandlerFunc {
4549
return func(c *gin.Context) {
4650
bouncer, _ := getBouncerFromContext(c)
4751
if bouncer != nil {
52+
fullPath := c.FullPath()
53+
if fullPath == "" {
54+
fullPath = "invalid-endpoint"
55+
}
4856
metrics.LapiBouncerHits.With(prometheus.Labels{
4957
"bouncer": bouncer.Name,
50-
"route": c.FullPath(),
58+
"route": fullPath,
5159
"method": c.Request.Method,
5260
}).Inc()
5361
}
@@ -60,8 +68,13 @@ func PrometheusMiddleware() gin.HandlerFunc {
6068
return func(c *gin.Context) {
6169
startTime := time.Now()
6270

71+
fullPath := c.FullPath()
72+
if fullPath == "" {
73+
fullPath = "invalid-endpoint"
74+
}
75+
6376
metrics.LapiRouteHits.With(prometheus.Labels{
64-
"route": c.FullPath(),
77+
"route": fullPath,
6578
"method": c.Request.Method,
6679
}).Inc()
6780
c.Next()

0 commit comments

Comments
 (0)