mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: label unpriced token usage metric by provider name and type (#28210)
## Problem The `provider` label was inconsistent between AI Gateway metrics. Every metric emitted by the gateway labels `provider` with the provider instance name, for example `anthropic-eu`, while `coder_ai_gateway_cost_control_unpriced_token_usage_records_total` used the provider type, for example `anthropic`. The two could not be correlated on `provider`. The metric was also inconsistent with itself: the path where a provider fails to resolve labelled by instance name, and the path where a model has no price labelled by type. The type is still worth exposing, since prices are keyed on `(provider_type, model)` and that is what an operator needs to add a price. ## Changes - Label the metric with `provider` (the instance name, consistent with the other gateway metrics) and add `provider_type` (the configured type the price is keyed on). - Use `unknown` for `provider_type` when the provider does not resolve to a configured type. - Log the unresolved-provider case at `warn` instead of `info`. A missing price is an expected steady state, but a provider that cannot be resolved is not. - Update the metrics docs and the `metricsdocgen` fixture. Closes [AIGOV-574](https://linear.app/codercom/issue/AIGOV-574) > [!NOTE] > Initially generated by Claude Opus 5, modified and reviewed by @ssncferreira
This commit is contained in:
@@ -208,10 +208,11 @@ Replace `<VERSION>` with your Coder minor version, for example `2.36`.
|
||||
> effectively unlimited.
|
||||
|
||||
Monitor `coder_ai_gateway_cost_control_unpriced_token_usage_records_total`,
|
||||
labeled by `provider` and `model`, to detect unpriced usage. Any non-zero value
|
||||
means spend is under-counted. Because the price book ships with the release, a
|
||||
newly launched model is unpriced until you upgrade Coder or set a price for it
|
||||
yourself.
|
||||
labeled by `provider`, `provider_type`, and `model`, to detect unpriced usage.
|
||||
Use the `(provider_type, model)` tuple to find the price to set. Any non-zero
|
||||
value means spend is under-counted. Because the price book ships with the
|
||||
release, a newly launched model is unpriced until you upgrade Coder or set a
|
||||
price for it yourself.
|
||||
|
||||
### Set model prices
|
||||
|
||||
|
||||
@@ -54,12 +54,12 @@ Budget enforcement runs in `coderd`.
|
||||
Cost control metrics are exported only from the `coderd` Prometheus listener.
|
||||
Standalone replicas do not export them.
|
||||
|
||||
| Metric | Type | Labels | Purpose |
|
||||
|--------------------------------------------------------------------|-----------|---------------------|------------------------------------------------------------------------------------------|
|
||||
| `coder_ai_gateway_cost_control_blocked_requests_total` | counter | `group_id` | AI requests blocked because the initiator's budget was exceeded. |
|
||||
| `coder_ai_gateway_cost_control_blocked_users` | gauge | `group_id` | Users currently over their AI budget. |
|
||||
| `coder_ai_gateway_cost_control_enforcement_duration_seconds` | histogram | `outcome` | Duration of AI budget enforcement checks. `outcome` is `allowed`, `blocked`, or `error`. |
|
||||
| `coder_ai_gateway_cost_control_unpriced_token_usage_records_total` | counter | `model`, `provider` | Recorded token-usage records for which no model price was found. |
|
||||
| Metric | Type | Labels | Purpose |
|
||||
|--------------------------------------------------------------------|-----------|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `coder_ai_gateway_cost_control_blocked_requests_total` | counter | `group_id` | AI requests blocked because the initiator's budget was exceeded. |
|
||||
| `coder_ai_gateway_cost_control_blocked_users` | gauge | `group_id` | Users currently over their AI budget. |
|
||||
| `coder_ai_gateway_cost_control_enforcement_duration_seconds` | histogram | `outcome` | Duration of AI budget enforcement checks. `outcome` is `allowed`, `blocked`, or `error`. |
|
||||
| `coder_ai_gateway_cost_control_unpriced_token_usage_records_total` | counter | `model`, `provider`, `provider_type` | Recorded token-usage records for which no model price was found. `provider` is the provider instance name, and `provider_type` is the configured type the price is keyed on, or `unknown` when the provider could not be resolved. |
|
||||
|
||||
### AI Gateway Proxy metrics
|
||||
|
||||
|
||||
Reference in New Issue
Block a user