From e90d734c7c70513a21a7eaf78e424b2a190f2f1c Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Tue, 16 Nov 2021 22:18:20 -0800 Subject: Track X-API-Key request count --- app/middleware/auth.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/middleware/auth.go b/app/middleware/auth.go index 167d261..0a20a9e 100644 --- a/app/middleware/auth.go +++ b/app/middleware/auth.go @@ -12,8 +12,19 @@ import ( "code.crute.us/mcrute/cloud-identity-broker/auth/github" "github.com/labstack/echo/v4" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" ) +// apiKeyRequests tracks the number of requests made with the legacy X-API-Key +// header instead of the Authorization header so that we can track when it's +// safe to remove that edge-case. +var apiKeyRequests = promauto.NewCounterVec(prometheus.CounterOpts{ + Namespace: "aws_access", // Legacy Namespace + Name: "api_key_request_total", + Help: "Total number of requests using the X-API-Key header", +}, nil) + // canRegisterUrls is an interface that identifies what about an HTTP router is // needed by this middleware. This mainly exists to work around the fact that // our server is actually a golib.EchoWrapper and not an echo.Echo. @@ -106,6 +117,8 @@ func (m *AuthenticationMiddleware) Middleware(next echo.HandlerFunc) echo.Handle if len(tp) == 2 && tp[0] == "Bearer" { token = tp[1] } + } else { + apiKeyRequests.With(nil).Inc() } // If an API key is specified this is a success or failure path. There -- cgit v1.2.3