Files
supabase/apps/studio/data/analytics/keys.ts
Jordi Enric 88ed2aad97 new home: refactor charts to use old sources (#42245)
- refactors new charts in homepage to use stable analytics endpoints
- changes are behind newHomepageUsageV2 flag

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Centralized per-service health metrics hook with per-service data,
loading/error states and refresh.

* **Improvements**
  * Time-series normalization into fixed buckets aligned to an end time.
* Updated UI: success-rate formatting, per-service loading/error
surfaced, refreshed click/refresh behavior; removed delta display.

* **Removals**
  * Legacy project-metrics query and mapping utilities removed.

* **Tests**
* Extensive unit tests added for date ranges, bucket normalization, and
health metric calculations; some obsolete tests removed.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-01-28 17:02:00 +00:00

165 lines
3.3 KiB
TypeScript

export const analyticsKeys = {
// logs/reports endpoints
functionsCombinedStats: (
projectRef: string | undefined,
{
interval,
functionId,
}: {
functionId: string | undefined
interval: string | undefined
}
) =>
[
'projects',
projectRef,
'functions-combined-stats',
{
interval,
functionId,
},
] as const,
functionsInvStats: (
projectRef: string | undefined,
{
interval,
functionId,
}: {
functionId: string | undefined
interval: string | undefined
}
) =>
[
'projects',
projectRef,
'functions-inv-stats',
{
interval,
functionId,
},
] as const,
functionsReqStats: (
projectRef: string | undefined,
{
interval,
functionId,
}: {
functionId: string | undefined
interval: string | undefined
}
) =>
[
'projects',
projectRef,
'functions-req-stats',
{
interval,
functionId,
},
] as const,
functionsResourceUsage: (
projectRef: string | undefined,
{
interval,
functionId,
}: {
functionId: string | undefined
interval: string | undefined
}
) =>
[
'projects',
projectRef,
'functions-resource-usage',
{
interval,
functionId,
},
] as const,
orgDailyStats: (
orgSlug: string | undefined,
{
startDate,
endDate,
projectRef,
}: {
startDate?: string
endDate?: string
projectRef?: string
}
) =>
[
'organizations',
orgSlug,
'daily-stats',
{
startDate: isoDateStringToDate(startDate),
endDate: isoDateStringToDate(endDate),
projectRef,
},
] as const,
infraMonitoring: (
projectRef: string | undefined,
{
attribute,
startDate,
endDate,
interval,
databaseIdentifier,
}: {
attribute?: string
startDate?: string
endDate?: string
interval?: string
databaseIdentifier?: string
}
) =>
[
'projects',
projectRef,
'infra-monitoring',
{ attribute, startDate, endDate, interval, databaseIdentifier },
] as const,
infraMonitoringGroup: (
projectRef: string | undefined,
{
attributes,
startDate,
endDate,
interval,
databaseIdentifier,
}: {
attributes?: string[]
startDate?: string
endDate?: string
interval?: string
databaseIdentifier?: string
}
) =>
[
'projects',
projectRef,
'infra-monitoring',
'group',
{
attributes: attributes ? [...attributes].sort() : undefined,
startDate,
endDate,
interval,
databaseIdentifier,
},
] as const,
usageApiCounts: (projectRef: string | undefined, interval: string | undefined) =>
['projects', projectRef, 'usage.api-counts', interval] as const,
usageApiRequestsCount: (projectRef: string | undefined) =>
['projects', projectRef, 'usage.api-requests-count'] as const,
}
function isoDateStringToDate(isoDateString: string | undefined): string | undefined {
if (!isoDateString) return isoDateString
return isoDateString.split('T')[0]
}