feat(prometheus): add per-team litellm_team_members_metric gauge - #31506
Conversation
Emit litellm_team_members_metric on every team member add and delete, labelled by team and team_alias and set to the team's authoritative member count. Because it is set from the current membership rather than incremented or decremented, it tracks the count up and down, never goes negative, and self-corrects on the next change after a proxy restart. Bulk member add is covered for free since it delegates to team_member_add, and the helper no-ops when the Prometheus callback is not registered. Resolves LIT-3082
|
|
Greptile SummaryThis PR adds a per-team Prometheus gauge for team member counts. The main changes are:
Confidence Score: 5/5The change is narrowly scoped to Prometheus metric emission for team membership updates and includes focused coverage for the new gauge behavior. No correctness issues were identified in the changed metric registration, emission seam, or endpoint update paths, and the tests cover the important label and count semantics.
What T-Rex did
Reviews (1): Last reviewed commit: "feat(prometheus): add per-team litellm_t..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR adds a Prometheus metric for per-team member counts. The main changes are:
Confidence Score: 5/5The change appears safe to merge. The implementation is narrowly scoped, covered by targeted tests, and no correctness or security issues were identified.
What T-Rex did
Reviews (2): Last reviewed commit: "feat(prometheus): add per-team litellm_t..." | Re-trigger Greptile |
b2e708d
into
litellm_internal_staging
…riAI#31506) Emit litellm_team_members_metric on every team member add and delete, labelled by team and team_alias and set to the team's authoritative member count. Because it is set from the current membership rather than incremented or decremented, it tracks the count up and down, never goes negative, and self-corrects on the next change after a proxy restart. Bulk member add is covered for free since it delegates to team_member_add, and the helper no-ops when the Prometheus callback is not registered. Resolves LIT-3082
Relevant issues
Linear ticket
Resolves LIT-3082
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
Live proxy with
callbacks: ["prometheus"]against a real Postgres. The metric is scraped straight off/metrics. Master key auth elided as$KEY, base URL is the proxyBefore the change, on the base branch, adding a member emits no such metric at all
After the change, the gauge appears and tracks the team's current member count up and down. Sequence below starts from a team that already has
default_user_id(admin) plus alice, bob, carolThe HELP/TYPE lines confirm the registration
Type
🆕 New Feature
Changes
Adds a per-team Prometheus gauge
litellm_team_members_metric, labelled byteam(team id) andteam_alias, that reflects the number of members in a team. It is emitted from/team/member_addand/team/member_delete(and/team/bulk_member_add, which delegates to member add), so the count rises on each add and falls on each delete as the ticket asksThe gauge is set to the team's authoritative member count after the membership write rather than incremented or decremented by a delta. That keeps it equal to the real current membership, so it never drifts negative and self-corrects on the first change after a proxy restart, which a delta-since-startup counter cannot do. The delete-path emission sits immediately after the authoritative team-table update so the gauge stays consistent with the persisted state even if a later cleanup step raises
Emission goes through a small
_emit_team_members_metricseam that fetches thePrometheusLoggerfromlitellm.callbacksand no-ops when Prometheus is not enabled, so this is zero-cost for proxies that have not registered the callback and a metric failure can never break a team add or deleteTests cover the gauge being set to the member count for several counts, that re-emitting overwrites with the authoritative value rather than accumulating, the
team_alias=Nonefallback to an empty label, per-team label isolation, and the seam's registered/unregistered/raising paths