Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit aa8925d

Browse files
mrnuggetdaxmc99
authored andcommitted
perm syncer metrics: reduce cardinality of metrics (#45607)
High-cardinality metrics is not something that Prometheus is built for. This reduces the cardinality by reducing it to 2 in most cases: "repo" or "user" and "success" or "not success".
1 parent 12d9bce commit aa8925d

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

enterprise/cmd/repo-updater/internal/authz/metrics.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,23 @@ var (
5252
metricsSuccessPermsSyncs = promauto.NewCounterVec(prometheus.CounterOpts{
5353
Name: "src_repoupdater_perms_syncer_success_syncs",
5454
Help: "Total number of successful permissions syncs",
55-
}, []string{"type", "id"})
55+
}, []string{"type"})
5656
metricsFailedPermsSyncs = promauto.NewCounterVec(prometheus.CounterOpts{
5757
Name: "src_repoupdater_perms_syncer_failed_syncs",
5858
Help: "Total number of failed permissions syncs",
59-
}, []string{"type", "id"})
59+
}, []string{"type"})
6060
metricsFirstPermsSyncs = promauto.NewCounterVec(prometheus.CounterOpts{
6161
Name: "src_repoupdater_perms_syncer_initial_syncs",
6262
Help: "Total number of new user/repo permissions syncs",
63-
}, []string{"type", "id"})
64-
metricsPermsFound = promauto.NewGaugeVec(prometheus.GaugeOpts{
65-
Name: "src_repoupdater_perms_syncer_perms_found",
66-
Help: "The number of perms found for user/repo after sync",
67-
}, []string{"type", "id"})
63+
}, []string{"type"})
6864
metricsPermsConsecutiveSyncDelay = promauto.NewGaugeVec(prometheus.GaugeOpts{
6965
Name: "src_repoupdater_perms_syncer_perms_consecutive_sync_delay",
7066
Help: "The duration in minutes between last and current complete premissions sync.",
71-
}, []string{"type", "id"})
67+
}, []string{"type"})
7268
metricsPermsFirstSyncDelay = promauto.NewGaugeVec(prometheus.GaugeOpts{
7369
Name: "src_repoupdater_perms_syncer_perms_first_sync_delay",
7470
Help: "The duration in minutes it took for first user/repo complete perms sync after creation",
75-
}, []string{"type", "id"})
71+
}, []string{"type"})
7672
metricsItemsSyncScheduled = promauto.NewGaugeVec(prometheus.GaugeOpts{
7773
Name: "src_repoupdater_perms_syncer_items_sync_scheduled",
7874
Help: "The number of users/repos scheduled for sync",

enterprise/cmd/repo-updater/internal/authz/perms_syncer.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,13 @@ func (s *PermsSyncer) syncUserPerms(ctx context.Context, userID int32, noPerms b
620620
log.Object("fetchOpts", log.Bool("InvalidateCache", fetchOpts.InvalidateCaches)),
621621
)
622622

623-
userLabel := strconv.Itoa(int(p.UserID))
624-
metricsSuccessPermsSyncs.WithLabelValues("user", userLabel).Inc()
625-
metricsPermsFound.WithLabelValues("user", userLabel).Set(float64(len(p.IDs)))
623+
metricsSuccessPermsSyncs.WithLabelValues("user").Inc()
626624

627625
if !oldPerms.SyncedAt.IsZero() {
628-
metricsPermsConsecutiveSyncDelay.WithLabelValues("user", userLabel).Set(p.SyncedAt.Sub(oldPerms.SyncedAt).Seconds())
626+
metricsPermsConsecutiveSyncDelay.WithLabelValues("user").Set(p.SyncedAt.Sub(oldPerms.SyncedAt).Seconds())
629627
} else {
630-
metricsFirstPermsSyncs.WithLabelValues("user", userLabel).Inc()
631-
metricsPermsFirstSyncDelay.WithLabelValues("user", userLabel).Set(p.SyncedAt.Sub(user.CreatedAt).Seconds())
628+
metricsFirstPermsSyncs.WithLabelValues("user").Inc()
629+
metricsPermsFirstSyncDelay.WithLabelValues("user").Set(p.SyncedAt.Sub(user.CreatedAt).Seconds())
632630
}
633631

634632
return providerStates, nil
@@ -812,14 +810,13 @@ func (s *PermsSyncer) syncRepoPerms(ctx context.Context, repoID api.RepoID, noPe
812810
log.Object("fetchOpts", log.Bool("invalidateCaches", fetchOpts.InvalidateCaches)),
813811
)
814812

815-
metricsSuccessPermsSyncs.WithLabelValues("repo", string(p.RepoID)).Inc()
816-
metricsPermsFound.WithLabelValues("repo", string(p.RepoID)).Set(float64(regularCount))
813+
metricsSuccessPermsSyncs.WithLabelValues("repo").Inc()
817814

818815
if !oldPerms.SyncedAt.IsZero() {
819-
metricsPermsConsecutiveSyncDelay.WithLabelValues("repo", string(p.RepoID)).Set(p.SyncedAt.Sub(oldPerms.SyncedAt).Seconds())
816+
metricsPermsConsecutiveSyncDelay.WithLabelValues("repo").Set(p.SyncedAt.Sub(oldPerms.SyncedAt).Seconds())
820817
} else {
821-
metricsFirstPermsSyncs.WithLabelValues("repo", string(p.RepoID)).Inc()
822-
metricsPermsFirstSyncDelay.WithLabelValues("repo", string(p.RepoID)).Set(p.SyncedAt.Sub(repo.CreatedAt).Seconds())
818+
metricsFirstPermsSyncs.WithLabelValues("repo").Inc()
819+
metricsPermsFirstSyncDelay.WithLabelValues("repo").Set(p.SyncedAt.Sub(repo.CreatedAt).Seconds())
823820
}
824821

825822
return providerStates, nil
@@ -891,9 +888,9 @@ func (s *PermsSyncer) syncPerms(ctx context.Context, syncGroups map[requestType]
891888
)
892889

893890
if request.Type == requestTypeUser {
894-
metricsFailedPermsSyncs.WithLabelValues("user", string(request.ID)).Inc()
891+
metricsFailedPermsSyncs.WithLabelValues("user").Inc()
895892
} else {
896-
metricsFailedPermsSyncs.WithLabelValues("repo", string(request.ID)).Inc()
893+
metricsFailedPermsSyncs.WithLabelValues("repo").Inc()
897894
}
898895
} else {
899896
logger.Debug("succeeded in syncing permissions",

0 commit comments

Comments
 (0)