feat: add API key usage endpoint with provider and key grouping

- Implemented `GetAPIKeyUsage` to expose recent request data grouped by provider and API key.
- Added supporting function `mergeRecentRequestBuckets` for bucket aggregation.
- Registered new endpoint `/v0/management/api-key-usage` in the management API.
- Included extensive unit tests for provider and key-based grouping validation.
- Updated `formatRecentRequestBucketLabel` to support configurable bucket duration.
This commit is contained in:
Luis Pater
2026-05-01 23:34:18 +08:00
parent 6187919000
commit b0dc9df887
4 changed files with 175 additions and 1 deletions
+1 -1
View File
@@ -164,7 +164,7 @@ func recentRequestBucketIndex(bucketID int64) int {
func formatRecentRequestBucketLabel(bucketID int64) string {
start := time.Unix(bucketID*recentRequestBucketSeconds, 0).In(time.Local)
end := start.Add(10 * time.Minute)
end := start.Add(time.Duration(recentRequestBucketSeconds) * time.Second)
return start.Format("15:04") + "-" + end.Format("15:04")
}