fix(metrics): strip urls for login counter

This commit is contained in:
Trong Huu Nguyen
2023-04-26 09:57:29 +02:00
parent 55d2e0ce3b
commit c60f9478a5
2 changed files with 11 additions and 2 deletions

View File

@@ -7,7 +7,6 @@ import (
"fmt"
"net/http"
urllib "net/url"
"strings"
"time"
"github.com/sethvargo/go-retry"
@@ -215,7 +214,7 @@ func (s *Standalone) LoginCallback(w http.ResponseWriter, r *http.Request) {
}
mw.LogEntryFrom(r).WithFields(fields).Info("callback: successful login")
metrics.ObserveLogin(tokens.IDToken.GetAmrClaim(), strings.TrimSuffix(redirect, "/"))
metrics.ObserveLogin(tokens.IDToken.GetAmrClaim(), redirect)
cookie.Clear(w, cookie.Retry, s.GetCookieOptions(r))
http.Redirect(w, r, redirect, http.StatusTemporaryRedirect)
}

View File

@@ -2,6 +2,8 @@ package metrics
import (
"net/http"
"net/url"
"strings"
"time"
"github.com/prometheus/client_golang/prometheus"
@@ -153,6 +155,14 @@ func ObserveRedisLatency(operation string, fun func() error) error {
}
func ObserveLogin(amrValue, redirect string) {
u, err := url.Parse(redirect)
if err == nil {
u.Path = strings.TrimSuffix(u.Path, "/")
u.RawQuery = ""
u.RawFragment = ""
redirect = u.String()
}
Logins.With(prometheus.Labels{
LabelAmr: amrValue,
LabelRedirect: redirect,