Give an organization's managers a page of their own
A member of an organization can be its manager (users join --org X --role manager, or the star on the people page). /org shows a manager their organization: usage over time by team, project or person, its teams and projects with limits and 30-day spend, and its members, each once with every place they belong. Read-only; administrators see every organization. Only what was spent in the organization's projects is shown — UsageBucketsIn filters by where a request was spent. Found on the way: - Usage by org, team and project, and the quotas page's spend, joined through api_keys and so dropped every chat-page request, which has no key row. They now read usage.project_id; keys no longer move between projects, so the two agree. - /org was not exempt from API-key auth and answered browsers with a JSON error. A router test now drives the session pages through the middleware; it fails without the fix. Membership queries, org-scoped usage and the reworked joins pass the PostgreSQL store tests on 16. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
098886e0e4
commit
e493b2f53d
21 files changed
+716
-48
No files matched your search
+26
-21
@@ -134,27 +134,7 @@ func (p *AccountPages) renderUsage(w http.ResponseWriter, r *http.Request,
|
||||
return
|
||||
}
|
||||
|
||||
d.Requests = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
return float64(b.Requests)
|
||||
}), "", 4)
|
||||
d.Tokens = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
return float64(b.Prompt + b.Completion)
|
||||
}), "", 4)
|
||||
d.Spend = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
// Shown in whole units, as every other spend figure is: a budget is
|
||||
// written in units and a chart in micros would not compare with it.
|
||||
return float64(b.CostMicros) / 1e6
|
||||
}), "", 4)
|
||||
|
||||
for _, u := range rows {
|
||||
d.Rows = append(d.Rows, usageRow{
|
||||
Name: displayName(u),
|
||||
Requests: u.Requests,
|
||||
Tokens: u.Tokens(),
|
||||
Spend: unitsOf(u.CostMicros),
|
||||
Errors: u.Errors,
|
||||
})
|
||||
}
|
||||
d.Requests, d.Tokens, d.Spend, d.Rows = usageCharts(rows)
|
||||
render(w, "admin_usage", d)
|
||||
}
|
||||
|
||||
@@ -207,3 +187,28 @@ func groupLabel(g store.Grouping) string {
|
||||
return string(g)
|
||||
}
|
||||
}
|
||||
|
||||
// usageCharts draws usage over time three ways, with the table beneath them.
|
||||
func usageCharts(rows []store.UsageSeries) (req, tok, spend TimeSeries, table []usageRow) {
|
||||
req = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
return float64(b.Requests)
|
||||
}), "", 4)
|
||||
tok = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
return float64(b.Prompt + b.Completion)
|
||||
}), "", 4)
|
||||
spend = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
// Shown in whole units, as every other spend figure is: a budget is
|
||||
// written in units and a chart in micros would not compare with it.
|
||||
return float64(b.CostMicros) / 1e6
|
||||
}), "", 4)
|
||||
for _, u := range rows {
|
||||
table = append(table, usageRow{
|
||||
Name: displayName(u),
|
||||
Requests: u.Requests,
|
||||
Tokens: u.Tokens(),
|
||||
Spend: unitsOf(u.CostMicros),
|
||||
Errors: u.Errors,
|
||||
})
|
||||
}
|
||||
return req, tok, spend, table
|
||||
}
|
||||
Reference in new issue
Block a user