mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix(usage): scope the executions breakdown to function executions
`executions` is the umbrella metric covering both functions and sites,
but the table it feeds is headed "Function" and links each row to
/functions/function-{resourceId}. A project with a trafficked site would
get rows showing a raw site ID, unresolvable by functions.list, linking
to a function that does not exist. `functions.executions` is the metric
that matches the table.
Fold the call into the load function's existing Promise.all so it no
longer serialises behind the invoice and usage requests, and report a
failure through trackError instead of swallowing it — a 403 or a
malformed response was previously indistinguishable from a project with
no executions.
Drop the duplicate database-type read in the collection layout, which
recomputed locally what the component already derives.
This commit is contained in:
1 parent
1cc7e263bd
commit
28b46d9f7b
4 files changed
+18
-12
No files matched your search
@@ -259,6 +259,7 @@ export enum Submit {
|
||||
ProjectService = 'submit_project_service',
|
||||
ProjectUpdateSMTP = 'submit_project_update_smtp',
|
||||
ProjectUpdateOAuth2Server = 'submit_project_update_oauth2_server',
|
||||
ProjectUsageExecutionsBreakdown = 'submit_project_usage_executions_breakdown',
|
||||
ProjectResume = 'submit_project_resume',
|
||||
MemberCreate = 'submit_member_create',
|
||||
MemberDelete = 'submit_member_delete',
|
||||
|
||||
@@ -37,6 +37,11 @@ const executionsBreakdownLimit = 25;
|
||||
/**
|
||||
* `UsageProject.executionsBreakdown` was dropped in SDK 16; the per-resource split now comes from
|
||||
* the dimensional usage API, which returns bare resource IDs, so names are resolved separately.
|
||||
*
|
||||
* Scoped to `functions.executions` rather than the umbrella `executions` metric, which also counts
|
||||
* site executions — those resolve to no name here and their rows link to a function that does not exist.
|
||||
* Omitting `interval` makes each point a whole-window aggregate per resource, so the limit is a
|
||||
* top-N-by-total rather than a truncation of the underlying data.
|
||||
*/
|
||||
export async function listExecutionsBreakdown(
|
||||
region: string,
|
||||
@@ -47,7 +52,7 @@ export async function listExecutionsBreakdown(
|
||||
const project = sdk.forProject(region, projectId);
|
||||
|
||||
const events = await project.usage.listEvents({
|
||||
metrics: [UsageEventMetric.Executions],
|
||||
metrics: [UsageEventMetric.FunctionsExecutions],
|
||||
dimensions: [UsageEventDimension.ResourceId],
|
||||
startAt,
|
||||
endAt,
|
||||
|
||||
+1
-2
@@ -257,8 +257,7 @@
|
||||
const { rows, ids } = generateFakeRecords($randomDataModalState.value, fields);
|
||||
documentIds = ids;
|
||||
|
||||
const dbType = data.database?.type;
|
||||
const isVectorsDb = dbType === 'vectorsdb';
|
||||
const isVectorsDb = databaseType === 'vectorsdb';
|
||||
const dimension = collection?.dimension ?? DEFAULT_VECTOR_DIMENSION;
|
||||
|
||||
// For vectorsdb, wrap fields in metadata and add empty embeddings
|
||||
|
||||
+10
-9
@@ -1,4 +1,5 @@
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Submit, trackError } from '$lib/actions/analytics';
|
||||
import type { PageLoad } from './$types';
|
||||
import { accumulateUsage, listExecutionsBreakdown, type ExecutionsBreakdown } from '$lib/sdk/usage';
|
||||
import { type Models, Query } from '@appwrite.io/console';
|
||||
@@ -35,12 +36,19 @@ export const load: PageLoad = async ({ params, parent }) => {
|
||||
}
|
||||
}
|
||||
|
||||
const [invoices, usage] = await Promise.all([
|
||||
const [invoices, usage, executionsBreakdown] = await Promise.all([
|
||||
sdk.forConsole.organizations.listInvoices({
|
||||
organizationId: organization.$id,
|
||||
queries: [Query.orderDesc('from')]
|
||||
}),
|
||||
sdk.forProject(region, project).project.getUsage({ startDate, endDate })
|
||||
sdk.forProject(region, project).project.getUsage({ startDate, endDate }),
|
||||
listExecutionsBreakdown(region, project, startDate, endDate).catch(
|
||||
(error): ExecutionsBreakdown[] => {
|
||||
// supplementary to the executions chart, so never fail the page for it
|
||||
trackError(error, Submit.ProjectUsageExecutionsBreakdown);
|
||||
return [];
|
||||
}
|
||||
)
|
||||
]);
|
||||
|
||||
if (currentAggregation) {
|
||||
@@ -66,13 +74,6 @@ export const load: PageLoad = async ({ params, parent }) => {
|
||||
|
||||
usage.users = accumulateUsage(usage.users, usage.usersTotal);
|
||||
|
||||
let executionsBreakdown: ExecutionsBreakdown[] = [];
|
||||
try {
|
||||
executionsBreakdown = await listExecutionsBreakdown(region, project, startDate, endDate);
|
||||
} catch {
|
||||
// supplementary — a server without the usage events API still renders the rest of the page
|
||||
}
|
||||
|
||||
return {
|
||||
usage,
|
||||
invoices,
|
||||
|
||||
Reference in new issue
Block a user