fix(prometheus): allow litellm_total_users and litellm_teams_count in metrics config

These two gauge metrics are registered as litellm_total_users and
litellm_teams_count but were missing from DEFINED_PROMETHEUS_METRICS. Because
prometheus_metrics_config validation rejects any name not in that set, listing
either metric raised a configuration validation error, so operators could not
opt into them.

Adding both names to the allowed set lets them be configured like any other
metric. Includes a regression test that configures both metrics and asserts the
logger initializes and enables them without raising
This commit is contained in:
Ardit Tirana 2026-06-20 00:31:16 +02:00
parent 4847fa5dd5
commit e2e36d08b0
2 changed files with 28 additions and 0 deletions

View file

@ -224,6 +224,9 @@ DEFINED_PROMETHEUS_METRICS = Literal[
"litellm_remaining_user_budget_metric",
"litellm_user_max_budget_metric",
"litellm_user_budget_remaining_hours_metric",
# User and team count metrics
"litellm_total_users",
"litellm_teams_count",
"litellm_deployment_state",
"litellm_deployment_failure_responses",
"litellm_deployment_total_requests",

View file

@ -927,3 +927,28 @@ def test_custom_latency_buckets():
REGISTRY.unregister(collector)
except Exception:
pass
def test_user_team_count_metrics_pass_config_validation(monkeypatch):
"""litellm_total_users and litellm_teams_count must be configurable via
prometheus_metrics_config without raising a validation error.
Regression test for https://github.com/BerriAI/litellm/issues/30839
"""
import litellm
monkeypatch.setattr(
litellm,
"prometheus_metrics_config",
[
{
"group": "my_metrics",
"metrics": ["litellm_total_users", "litellm_teams_count"],
}
],
)
logger = PrometheusLogger()
assert "litellm_total_users" in logger.enabled_metrics
assert "litellm_teams_count" in logger.enabled_metrics