Skip to content

Commit 1bf6c27

Browse files
committed
promehteus middleware: happy path, redundant c.Next()
1 parent 52e6ef2 commit 1bf6c27

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

pkg/apiserver/controllers/v1/metrics.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,30 @@ import (
1111

1212
func PrometheusBouncersHasEmptyDecision(c *gin.Context) {
1313
bouncer, _ := getBouncerFromContext(c)
14-
if bouncer != nil {
15-
metrics.LapiNilDecisions.With(prometheus.Labels{
16-
"bouncer": bouncer.Name,
17-
}).Inc()
14+
if bouncer == nil {
15+
return
1816
}
17+
18+
metrics.LapiNilDecisions.With(prometheus.Labels{
19+
"bouncer": bouncer.Name,
20+
}).Inc()
1921
}
2022

2123
func PrometheusBouncersHasNonEmptyDecision(c *gin.Context) {
2224
bouncer, _ := getBouncerFromContext(c)
23-
if bouncer != nil {
24-
metrics.LapiNonNilDecisions.With(prometheus.Labels{
25-
"bouncer": bouncer.Name,
26-
}).Inc()
25+
if bouncer == nil {
26+
return
2727
}
28+
29+
metrics.LapiNonNilDecisions.With(prometheus.Labels{
30+
"bouncer": bouncer.Name,
31+
}).Inc()
2832
}
2933

3034
func PrometheusMachinesMiddleware() gin.HandlerFunc {
3135
return func(c *gin.Context) {
3236
machineID, _ := getMachineIDFromContext(c)
3337
if machineID == "" {
34-
c.Next()
3538
return
3639
}
3740

@@ -47,7 +50,6 @@ func PrometheusBouncersMiddleware() gin.HandlerFunc {
4750
return func(c *gin.Context) {
4851
bouncer, _ := getBouncerFromContext(c)
4952
if bouncer == nil {
50-
c.Next()
5153
return
5254
}
5355

@@ -70,6 +72,10 @@ func PrometheusMiddleware() gin.HandlerFunc {
7072
c.Next()
7173

7274
elapsed := time.Since(startTime)
73-
metrics.LapiResponseTime.With(prometheus.Labels{"method": c.Request.Method, "endpoint": c.FullPath()}).Observe(elapsed.Seconds())
75+
metrics.LapiResponseTime.With(
76+
prometheus.Labels{
77+
"method": c.Request.Method,
78+
"endpoint": c.FullPath(),
79+
}).Observe(elapsed.Seconds())
7480
}
7581
}

0 commit comments

Comments
 (0)