Skip to content

Commit

Permalink
Added Prometheus metric for created access requests (gravitational#29761
Browse files Browse the repository at this point in the history
)
  • Loading branch information
r0mant authored Jul 29, 2023
1 parent 90774ac commit 3c0f7fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
insecurerand "math/rand"
"os"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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,
}
)

Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 3c0f7fc

Please sign in to comment.