Commit 7abef0d7 authored by ale's avatar ale

Add latency metrics

Measure latency of the authentication requests (only the ones where we
actually perform encryption).
parent 78905166
Pipeline #2669 passed with stages
in 1 minute and 47 seconds
......@@ -6,6 +6,7 @@ import (
"fmt"
"log"
"path/filepath"
"time"
"github.com/pquerna/otp/totp"
"github.com/prometheus/client_golang/prometheus"
......@@ -294,6 +295,8 @@ func (s *Server) getUser(ctx context.Context, service *service, username string)
// Authenticate a user with the parameters specified in the incoming AuthRequest.
func (s *Server) Authenticate(ctx context.Context, req *auth.Request) *auth.Response {
start := time.Now()
svc, ok := s.getService(req.Service)
if !ok {
log.Printf("unknown service %s", req.Service)
......@@ -338,6 +341,9 @@ func (s *Server) Authenticate(ctx context.Context, req *auth.Request) *auth.Resp
"service": req.Service,
"status": resp.Status.String(),
}).Inc()
authRequestLatency.With(prometheus.Labels{
"service": req.Service,
}).Observe(time.Since(start).Seconds() * 1000)
return resp
}
......@@ -501,6 +507,14 @@ var (
},
[]string{"service", "status"},
)
authRequestLatency = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "auth_latency",
Help: "Latency of authentication requests (server side).",
Buckets: prometheus.ExponentialBuckets(5, 1.4142, 16),
},
[]string{"service"},
)
ratelimitCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "auth_requests_ratelimited",
......@@ -512,5 +526,6 @@ var (
func init() {
prometheus.MustRegister(authRequestsCounter)
prometheus.MustRegister(authRequestLatency)
prometheus.MustRegister(ratelimitCounter)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment