From 3c0f7fc77974a378a518cb7285dc72cd17a036bd Mon Sep 17 00:00:00 2001 From: Roman Tkachenko Date: Sat, 29 Jul 2023 08:07:11 -0700 Subject: [PATCH] Added Prometheus metric for created access requests (#29761) --- lib/auth/auth.go | 15 +++++++++++++++ metrics.go | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/lib/auth/auth.go b/lib/auth/auth.go index 3280c682895f4..25af355e5952e 100644 --- a/lib/auth/auth.go +++ b/lib/auth/auth.go @@ -36,6 +36,7 @@ import ( insecurerand "math/rand" "os" "sort" + "strconv" "strings" "sync" "time" @@ -530,11 +531,21 @@ var ( []string{teleport.TagUpgrader}, ) + accessRequestsCreatedMetric = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: teleport.MetricNamespace, + Name: teleport.MetricAccessRequestsCreated, + Help: "Tracks the number of created access requests", + }, + []string{teleport.TagRoles, teleport.TagResources}, + ) + prometheusCollectors = []prometheus.Collector{ generateRequestsCount, generateThrottledRequestsCount, generateRequestsCurrent, generateRequestsLatencies, UserLoginCount, heartbeatsMissedByAuth, registeredAgents, migrations, totalInstancesMetric, enrolledInUpgradesMetric, upgraderCountsMetric, + accessRequestsCreatedMetric, } ) @@ -4013,6 +4024,10 @@ func (a *Server) CreateAccessRequestV2(ctx context.Context, req types.AccessRequ if err != nil { log.WithError(err).Warn("Failed to emit access request create event.") } + + accessRequestsCreatedMetric.WithLabelValues( + strconv.Itoa(len(req.GetRoles())), + strconv.Itoa(len(req.GetRequestedResourceIDs()))).Inc() return req, nil } diff --git a/metrics.go b/metrics.go index 83d7f1b90899f..22c71aef03b66 100644 --- a/metrics.go +++ b/metrics.go @@ -105,6 +105,13 @@ const ( // TagUpgrader is a metric tag for upgraders. TagUpgrader = "upgrader" + + // MetricsAccessRequestsCreated provides total number of created access requests. + MetricAccessRequestsCreated = "access_requests_created" + // TagRoles is a number of roles requested as a part of access request. + TagRoles = "roles" + // TagResources is a number of resources requested as a part of access request. + TagResources = "resources" ) const (