Auto-adjust cost histogram bucket intervals (#436)#490
Conversation
Server-side autoInterval picks optimal bucket width: 1h→5m, 6h→15m, 24h→1h, 72h→3h, 7d→6h, 30d→1d. Targets 12-24 buckets for visual clarity at any zoom level. Removed duplicated interval maps from both ContinuumMetricsWidget and MetricsDetailWidget — single source of truth in AICostServerCommand. Closes #436.
There was a problem hiding this comment.
Pull request overview
This PR centralizes time-series histogram bucket sizing for the cost dashboard by moving “adaptive interval” selection to the ai/cost server command, allowing widgets to omit client-side interval maps while preserving the ability to override with an explicit interval.
Changes:
- Add server-side
autoInterval()selection and use it whenparams.intervalis not provided. - Remove duplicated client-side
intervalMaplogic from the two metrics widgets. - Keep support for explicit
intervaloverrides via the existing command parameter.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/widgets/metrics-detail/MetricsDetailWidget.ts | Removes client-side interval mapping so the server chooses bucket width automatically. |
| src/widgets/continuum-metrics/ContinuumMetricsWidget.ts | Removes duplicated adaptive interval map and relies on server defaults. |
| src/commands/ai/cost/server/AICostServerCommand.ts | Introduces autoInterval(spanMs) and uses it to pick a default interval for time-series generation. |
Comments suppressed due to low confidence (1)
src/commands/ai/cost/server/AICostServerCommand.ts:305
parseIntervalToMs()accepts intervals like "0m"/"0h" (regex allows 0), which makesintervalMs= 0 and will cause an infinite loop ingenerateTimeSeries()(bucketStart never advances). Please validate that the parsed value is >= 1 (or thatintervalMs > 0) and throw a clear error otherwise.
private parseIntervalToMs(interval: string): number {
const match = interval.match(/^(\d+)(m|h|d|w)$/);
if (!match) {
throw new Error(`Invalid interval format: ${interval}. Use "5m", "1h", "6h", "1d", "1w"`);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| /** | ||
| * Auto-select bucket interval based on time range span. | ||
| * Targets 12-24 buckets for visual clarity at any zoom level. |
There was a problem hiding this comment.
The docstring claims this targets 12–24 buckets, but the current mapping can exceed that (e.g., 7d with 6h => 28 buckets; 30d with 1d => 30 buckets). Please update the comment to reflect the actual behavior/target range so future callers don’t rely on an incorrect guarantee.
| * Targets 12-24 buckets for visual clarity at any zoom level. | |
| * Aims for a reasonable number of buckets for visual clarity (typically | |
| * around a dozen to a few dozen), but may exceed 24 buckets for longer | |
| * ranges (e.g., ~28 buckets for 7d@6h, ~30 buckets for 30d@1d). |
Summary
autoInterval()picks optimal bucket width based on time range: 1h→5m, 6h→15m, 24h→1h, 72h→3h, 7d→6h, 30d→1dintervalparamCloses #436.
Test plan