mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-11 10:56:53 +00:00
fix(metrics): strip urls for login counter
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user