@substrat-run/control-plane-api 0.208.0 → 0.210.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +3 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +58 -1
- package/dist/api.js.map +1 -1
- package/dist/builder-sandbox-objects.d.ts +13 -0
- package/dist/builder-sandbox-objects.d.ts.map +1 -0
- package/dist/builder-sandbox-objects.js +25 -0
- package/dist/builder-sandbox-objects.js.map +1 -0
- package/dist/built-version.d.ts +31 -0
- package/dist/built-version.d.ts.map +1 -0
- package/dist/built-version.js +55 -0
- package/dist/built-version.js.map +1 -0
- package/dist/cf-observability.d.ts +8 -0
- package/dist/cf-observability.d.ts.map +1 -1
- package/dist/cf-observability.js +30 -1
- package/dist/cf-observability.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/platform-entry.generated.d.ts +1 -1
- package/dist/platform-entry.generated.d.ts.map +1 -1
- package/dist/platform-entry.generated.js +2 -2
- package/dist/platform-entry.generated.js.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type BuilderSandboxObjects } from '@substrat-run/contracts';
|
|
2
|
+
/**
|
|
3
|
+
* The Sandbox Durable Objects one team's builder containers run as (#3316), read from the builder's
|
|
4
|
+
* `GET /internal/sandbox-objects`. A container instance is its Sandbox object, so this is how the
|
|
5
|
+
* cost rollup's container backfill charges usage Cloudflare recorded before sandboxes carried a
|
|
6
|
+
* tenant label. Staff-only: it names project slugs.
|
|
7
|
+
*/
|
|
8
|
+
export type BuilderSandboxObjectsService = (tenantId: string) => Promise<BuilderSandboxObjects['objects']>;
|
|
9
|
+
/** The service over the builder's binding, behind the platform service token. */
|
|
10
|
+
export declare function builderSandboxObjectsService(service: {
|
|
11
|
+
fetch(request: Request): Promise<Response>;
|
|
12
|
+
} | undefined, token: string | undefined): BuilderSandboxObjectsService;
|
|
13
|
+
//# sourceMappingURL=builder-sandbox-objects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder-sandbox-objects.d.ts","sourceRoot":"","sources":["../src/builder-sandbox-objects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAG5F;;;;;GAKG;AACH,MAAM,MAAM,4BAA4B,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC;AAE3G,iFAAiF;AACjF,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE;IAAE,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAAE,GAAG,SAAS,EACnE,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,4BAA4B,CAkB9B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { builderSandboxObjects } from '@substrat-run/contracts';
|
|
2
|
+
import { ControlPlaneError } from '@substrat-run/control-plane-client';
|
|
3
|
+
/** The service over the builder's binding, behind the platform service token. */
|
|
4
|
+
export function builderSandboxObjectsService(service, token) {
|
|
5
|
+
return async (tenantId) => {
|
|
6
|
+
if (!service || !token)
|
|
7
|
+
throw new ControlPlaneError(503, 'the builder studio is not configured');
|
|
8
|
+
let response;
|
|
9
|
+
try {
|
|
10
|
+
response = await service.fetch(new Request('https://builder/internal/sandbox-objects', { headers: { 'x-service-token': token, 'x-substrat-tenant': tenantId } }));
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
console.error('builder-sandbox-objects.connection-failed', { detail: e instanceof Error ? e.message : String(e) });
|
|
14
|
+
throw new ControlPlaneError(502, 'the builder studio connection failed before it answered');
|
|
15
|
+
}
|
|
16
|
+
if (!response.ok)
|
|
17
|
+
throw new ControlPlaneError(502, `the builder studio refused the sandbox-object read (HTTP ${response.status})`);
|
|
18
|
+
// Parse, don't trust: an id that is not Cloudflare's shape would match nothing, silently.
|
|
19
|
+
const parsed = builderSandboxObjects.safeParse(await response.json().catch(() => null));
|
|
20
|
+
if (!parsed.success)
|
|
21
|
+
throw new ControlPlaneError(502, 'the builder studio answered a sandbox-object read in a shape this control plane does not know');
|
|
22
|
+
return parsed.data.objects;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=builder-sandbox-objects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder-sandbox-objects.js","sourceRoot":"","sources":["../src/builder-sandbox-objects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAA8B,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAUvE,iFAAiF;AACjF,MAAM,UAAU,4BAA4B,CAC1C,OAAmE,EACnE,KAAyB;IAEzB,OAAO,KAAK,EAAE,QAAQ,EAAE,EAAE;QACxB,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,iBAAiB,CAAC,GAAG,EAAE,sCAAsC,CAAC,CAAC;QACjG,IAAI,QAAkB,CAAC;QACvB,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAC5B,IAAI,OAAO,CAAC,0CAA0C,EAAE,EAAE,OAAO,EAAE,EAAE,iBAAiB,EAAE,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,EAAE,CAAC,CAClI,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,EAAE,MAAM,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACnH,MAAM,IAAI,iBAAiB,CAAC,GAAG,EAAE,yDAAyD,CAAC,CAAC;QAC9F,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,MAAM,IAAI,iBAAiB,CAAC,GAAG,EAAE,4DAA4D,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QACnI,0FAA0F;QAC1F,MAAM,MAAM,GAAG,qBAAqB,CAAC,SAAS,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QACxF,IAAI,CAAC,MAAM,CAAC,OAAO;YAAE,MAAM,IAAI,iBAAiB,CAAC,GAAG,EAAE,+FAA+F,CAAC,CAAC;QACvJ,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The version of a vertical already built from one source revision, if there is one.
|
|
3
|
+
*
|
|
4
|
+
* The studio's Run builds the project's saved revision into a version before it binds that
|
|
5
|
+
* version to a preview slot, and a build is minutes in a fresh container. When the revision is
|
|
6
|
+
* one the platform has already built (the commit prod was released from, or the one the last Run
|
|
7
|
+
* built), that build is redone for nothing. A source build stamps `manifest.build.revision` itself
|
|
8
|
+
* (D-66, the builder's agent), after the project's code ran and from the commit it checked out,
|
|
9
|
+
* so the stored manifest is the authority here. A version's `origin` is not: a snapshot push
|
|
10
|
+
* supplies its own.
|
|
11
|
+
*
|
|
12
|
+
* Bounded on purpose. A manifest is the largest thing the directory holds, so the search reads
|
|
13
|
+
* only the version prod points at, the one it serves, and the newest few. That covers the cases
|
|
14
|
+
* Run meets (an unchanged project, and a Run straight after a release), and a revision built
|
|
15
|
+
* long ago and since pushed past is built again, as it was before this existed.
|
|
16
|
+
*/
|
|
17
|
+
import { z, type PlatformActorId, type VerticalVersion } from '@substrat-run/contracts';
|
|
18
|
+
import type { HostAdmin } from '@substrat-run/kernel';
|
|
19
|
+
/** How many of the newest versions are searched, beside prod's. */
|
|
20
|
+
export declare const BUILT_VERSION_WINDOW = 10;
|
|
21
|
+
/** A git commit, as `manifest.build.revision` stores it. */
|
|
22
|
+
export declare const buildRevision: z.ZodString;
|
|
23
|
+
type Reader = Pick<HostAdmin, 'listChannels' | 'listVersions' | 'getVersion' | 'versionManifest'>;
|
|
24
|
+
/**
|
|
25
|
+
* The newest admissible version of `slug` built from `revision`, among prod's and the newest
|
|
26
|
+
* {@link BUILT_VERSION_WINDOW}; undefined when none is. A rejected version is passed over: it was
|
|
27
|
+
* refused, and a preview of it would show code the vertical's owner turned away.
|
|
28
|
+
*/
|
|
29
|
+
export declare function versionBuiltFrom(admin: Reader, actor: PlatformActorId, slug: string, revision: string, window?: number): Promise<VerticalVersion | undefined>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=built-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"built-version.d.ts","sourceRoot":"","sources":["../src/built-version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,CAAC,EAAE,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACxF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,4DAA4D;AAC5D,eAAO,MAAM,aAAa,aAAqC,CAAC;AAKhE,KAAK,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,cAAc,GAAG,cAAc,GAAG,YAAY,GAAG,iBAAiB,CAAC,CAAC;AAElG;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,eAAe,EACtB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,MAA6B,GACpC,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAoBtC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The version of a vertical already built from one source revision, if there is one.
|
|
3
|
+
*
|
|
4
|
+
* The studio's Run builds the project's saved revision into a version before it binds that
|
|
5
|
+
* version to a preview slot, and a build is minutes in a fresh container. When the revision is
|
|
6
|
+
* one the platform has already built (the commit prod was released from, or the one the last Run
|
|
7
|
+
* built), that build is redone for nothing. A source build stamps `manifest.build.revision` itself
|
|
8
|
+
* (D-66, the builder's agent), after the project's code ran and from the commit it checked out,
|
|
9
|
+
* so the stored manifest is the authority here. A version's `origin` is not: a snapshot push
|
|
10
|
+
* supplies its own.
|
|
11
|
+
*
|
|
12
|
+
* Bounded on purpose. A manifest is the largest thing the directory holds, so the search reads
|
|
13
|
+
* only the version prod points at, the one it serves, and the newest few. That covers the cases
|
|
14
|
+
* Run meets (an unchanged project, and a Run straight after a release), and a revision built
|
|
15
|
+
* long ago and since pushed past is built again, as it was before this existed.
|
|
16
|
+
*/
|
|
17
|
+
import { z } from '@substrat-run/contracts';
|
|
18
|
+
/** How many of the newest versions are searched, beside prod's. */
|
|
19
|
+
export const BUILT_VERSION_WINDOW = 10;
|
|
20
|
+
/** A git commit, as `manifest.build.revision` stores it. */
|
|
21
|
+
export const buildRevision = z.string().regex(/^[0-9a-f]{40}$/);
|
|
22
|
+
/** The one field the search reads; the rest of a stored manifest is not parsed. */
|
|
23
|
+
const stamped = z.object({ build: z.object({ revision: z.string() }).nullish() });
|
|
24
|
+
/**
|
|
25
|
+
* The newest admissible version of `slug` built from `revision`, among prod's and the newest
|
|
26
|
+
* {@link BUILT_VERSION_WINDOW}; undefined when none is. A rejected version is passed over: it was
|
|
27
|
+
* refused, and a preview of it would show code the vertical's owner turned away.
|
|
28
|
+
*/
|
|
29
|
+
export async function versionBuiltFrom(admin, actor, slug, revision, window = BUILT_VERSION_WINDOW) {
|
|
30
|
+
const prod = (await admin.listChannels(actor, slug)).find((ch) => ch.channel === 'prod');
|
|
31
|
+
const newest = await admin.listVersions(actor, slug, { limit: window, order: 'desc' });
|
|
32
|
+
const pinned = [prod?.servingVersionId, prod?.versionId].filter((id) => !!id);
|
|
33
|
+
// Prod's versions join the newest-first window when they have fallen out of it.
|
|
34
|
+
const candidates = [...newest];
|
|
35
|
+
for (const id of pinned) {
|
|
36
|
+
if (candidates.some((v) => v.id === id))
|
|
37
|
+
continue;
|
|
38
|
+
const found = await admin.getVersion(actor, id, slug);
|
|
39
|
+
if (found)
|
|
40
|
+
candidates.push(found);
|
|
41
|
+
}
|
|
42
|
+
for (const version of candidates) {
|
|
43
|
+
if (version.admission === 'rejected')
|
|
44
|
+
continue;
|
|
45
|
+
const json = await admin.versionManifest(actor, slug, version.id);
|
|
46
|
+
// A cheap refusal first: a manifest that does not hold the commit's text was not built from it.
|
|
47
|
+
if (!json || !json.includes(revision))
|
|
48
|
+
continue;
|
|
49
|
+
const parsed = stamped.safeParse(JSON.parse(json));
|
|
50
|
+
if (parsed.success && parsed.data.build?.revision === revision)
|
|
51
|
+
return version;
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=built-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"built-version.js","sourceRoot":"","sources":["../src/built-version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,CAAC,EAA8C,MAAM,yBAAyB,CAAC;AAGxF,mEAAmE;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEvC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAEhE,mFAAmF;AACnF,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAA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AC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAClE,gGAAgG;QAChG,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,SAAS;QAChD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACnD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,KAAK,QAAQ;YAAE,OAAO,OAAO,CAAC;IACjF,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -132,6 +132,12 @@ type FetchFn = (input: string, init?: RequestInit) => Promise<Response>;
|
|
|
132
132
|
* - `durableObjectsPeriodicGroups` per (namespace, object): rows read and written, storage write
|
|
133
133
|
* units, duration in GB-s (an aggregate, not a sample).
|
|
134
134
|
*
|
|
135
|
+
* And, for a day Cloudflare still keeps container usage for (`CONTAINER_USAGE_RETENTION_DAYS`,
|
|
136
|
+
* far fewer than the other datasets' 90), `containersUsageAdaptiveGroups` per (application,
|
|
137
|
+
* instance): vCPU-seconds, provisioned memory and disk in byte-seconds, bytes sent, with the
|
|
138
|
+
* tenant and app labels the platform set when it started the container (`containerLabels`). An
|
|
139
|
+
* older day is read without them: asking would refuse the whole day.
|
|
140
|
+
*
|
|
135
141
|
* Plus Cloudflare's namespace list, which is the only thing that says which class a namespace
|
|
136
142
|
* holds, so a ScopeDO is told from a ConfigDO, IdentityDO or SweeperDO. It is read once per reader,
|
|
137
143
|
* and the sweep builds one reader per pass, so a pass that reads several days lists it once.
|
|
@@ -147,6 +153,8 @@ export declare function createCloudflareUsageDayReader(opts: {
|
|
|
147
153
|
fetch?: FetchFn;
|
|
148
154
|
/** Rows per GraphQL page. Default `COST_USAGE_PAGE`, Cloudflare's ceiling; a test pages with fewer. */
|
|
149
155
|
pageSize?: number;
|
|
156
|
+
/** The clock container usage's retention is judged against. `Date.now` otherwise. */
|
|
157
|
+
now?: () => number;
|
|
150
158
|
}): (day: string) => Promise<CloudflareUsageDay>;
|
|
151
159
|
export {};
|
|
152
160
|
//# sourceMappingURL=cf-observability.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cf-observability.d.ts","sourceRoot":"","sources":["../src/cf-observability.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqE,KAAK,SAAS,EAAuB,MAAM,uBAAuB,CAAC;AAI/I,OAAO,
|
|
1
|
+
{"version":3,"file":"cf-observability.d.ts","sourceRoot":"","sources":["../src/cf-observability.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqE,KAAK,SAAS,EAAuB,MAAM,uBAAuB,CAAC;AAI/I,OAAO,EAYL,KAAK,kBAAkB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEpF,OAAO,KAAK,EACV,mBAAmB,EAWpB,MAAM,oBAAoB,CAAC;AAkB5B,eAAO,MAAM,mBAAmB,kCAAkC,CAAC;AA8SnE;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1B,KAAK,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,eAAe,GACjF,OAAO,CAST;AAED,iHAAiH;AACjH,QAAA,MAAM,cAAc,YAAI,WAAW,EAAE,eAAe,CAAU,CAAC;AAC/D,KAAK,eAAe,GAAG;KAAG,CAAC,IAAI,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE;CAAE,CAAC;AAsUtF;;;;;;;;GAQG;AACH,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAA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
CHANGED
|
@@ -4,7 +4,7 @@ import { cachedSource, cutOverSource } from './aggregate-source.js';
|
|
|
4
4
|
import { stableDeploymentRefFor } from './deploy.js';
|
|
5
5
|
import { aggregateReads } from './aggregate-reads.js';
|
|
6
6
|
import { serviceFamilyPattern } from './service-family.js';
|
|
7
|
-
import { ENTITY_TYPES_SEPARATOR, FIELD_COVERAGE_ID_FIELD, PLATFORM_SECRET_HEADER, ROUTER_REQUEST_POINT, ROUTER_SCRIPT_NAMES, cloudflareUsageDay, splitEntityTypes, utcDay, } from '@substrat-run/contracts';
|
|
7
|
+
import { CONTAINER_APP_LABEL, CONTAINER_TENANT_LABEL, CONTAINER_USAGE_RETENTION_DAYS, ENTITY_TYPES_SEPARATOR, FIELD_COVERAGE_ID_FIELD, PLATFORM_SECRET_HEADER, ROUTER_REQUEST_POINT, ROUTER_SCRIPT_NAMES, cloudflareUsageDay, splitEntityTypes, utcDay, } from '@substrat-run/contracts';
|
|
8
8
|
import { RequestRollupSaturated } from '@substrat-run/kernel';
|
|
9
9
|
import { readFieldCoverage } from './field-coverage-read.js';
|
|
10
10
|
import { TENANT_METRICS_LIMIT, REQUEST_FACET_KEYS, INVOCATION_KINDS, invocationKindOf, outboundCallsOf, requestMatchesSearch, requestSearchOf, } from './observability.js';
|
|
@@ -2055,6 +2055,12 @@ const NAMESPACE_PAGES_MAX = 200;
|
|
|
2055
2055
|
* - `durableObjectsPeriodicGroups` per (namespace, object): rows read and written, storage write
|
|
2056
2056
|
* units, duration in GB-s (an aggregate, not a sample).
|
|
2057
2057
|
*
|
|
2058
|
+
* And, for a day Cloudflare still keeps container usage for (`CONTAINER_USAGE_RETENTION_DAYS`,
|
|
2059
|
+
* far fewer than the other datasets' 90), `containersUsageAdaptiveGroups` per (application,
|
|
2060
|
+
* instance): vCPU-seconds, provisioned memory and disk in byte-seconds, bytes sent, with the
|
|
2061
|
+
* tenant and app labels the platform set when it started the container (`containerLabels`). An
|
|
2062
|
+
* older day is read without them: asking would refuse the whole day.
|
|
2063
|
+
*
|
|
2058
2064
|
* Plus Cloudflare's namespace list, which is the only thing that says which class a namespace
|
|
2059
2065
|
* holds, so a ScopeDO is told from a ConfigDO, IdentityDO or SweeperDO. It is read once per reader,
|
|
2060
2066
|
* and the sweep builds one reader per pass, so a pass that reads several days lists it once.
|
|
@@ -2064,6 +2070,7 @@ const NAMESPACE_PAGES_MAX = 200;
|
|
|
2064
2070
|
* whose directory can attribute it: one control plane per account.
|
|
2065
2071
|
*/
|
|
2066
2072
|
export function createCloudflareUsageDayReader(opts) {
|
|
2073
|
+
const now = opts.now ?? Date.now;
|
|
2067
2074
|
const pageSize = opts.pageSize ?? COST_USAGE_PAGE;
|
|
2068
2075
|
const send = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
2069
2076
|
const headers = { authorization: `Bearer ${opts.apiToken}`, 'content-type': 'application/json' };
|
|
@@ -2139,6 +2146,7 @@ export function createCloudflareUsageDayReader(opts) {
|
|
|
2139
2146
|
return {};
|
|
2140
2147
|
return { lower: Math.max(0, ci.lower), upper: Math.max(0, ci.upper) };
|
|
2141
2148
|
};
|
|
2149
|
+
const label = (v) => (typeof v === 'string' && v !== '' ? v : null);
|
|
2142
2150
|
const at = (row, ...path) => path.reduce((v, k) => (v && typeof v === 'object' ? v[k] : undefined), row);
|
|
2143
2151
|
return async (day) => {
|
|
2144
2152
|
if (!utcDay.safeParse(day).success) {
|
|
@@ -2147,6 +2155,12 @@ export function createCloudflareUsageDayReader(opts) {
|
|
|
2147
2155
|
const workers = await pages('workersInvocationsAdaptive', 'scriptName', 'sum { cpuTimeUs } confidence(level: 0.95) { sum { cpuTimeUs { lower upper isValid } } } dimensions { scriptName }', day);
|
|
2148
2156
|
const invocations = await pages('durableObjectsInvocationsAdaptiveGroups', 'namespaceId', 'sum { requests } confidence(level: 0.95) { sum { requests { lower upper isValid } } } dimensions { namespaceId scriptName }', day);
|
|
2149
2157
|
const objects = await pages('durableObjectsPeriodicGroups', 'objectId', 'sum { rowsRead rowsWritten storageWriteUnits duration } dimensions { namespaceId objectId }', day);
|
|
2158
|
+
// Cloudflare refuses a container read reaching further back than it keeps them, so an older
|
|
2159
|
+
// day is read without the dataset, never refused for it.
|
|
2160
|
+
const oldestContainerDay = new Date(now() - CONTAINER_USAGE_RETENTION_DAYS * 86_400_000).toISOString().slice(0, 10);
|
|
2161
|
+
const containers = day >= oldestContainerDay
|
|
2162
|
+
? await pages('containersUsageAdaptiveGroups', 'instanceId', `sum { cpuTimeSec allocatedMemory allocatedDisk txBytes } dimensions { instanceId applicationId tenant: label(name: "${CONTAINER_TENANT_LABEL}") app: label(name: "${CONTAINER_APP_LABEL}") }`, day)
|
|
2163
|
+
: null;
|
|
2150
2164
|
namespaces ??= listNamespaces().catch((err) => {
|
|
2151
2165
|
// A failed list is not kept: the next day's read asks again.
|
|
2152
2166
|
namespaces = undefined;
|
|
@@ -2174,6 +2188,21 @@ export function createCloudflareUsageDayReader(opts) {
|
|
|
2174
2188
|
duration: num(at(r, 'sum', 'duration')),
|
|
2175
2189
|
})),
|
|
2176
2190
|
namespaces: await namespaces,
|
|
2191
|
+
...(containers === null
|
|
2192
|
+
? {}
|
|
2193
|
+
: {
|
|
2194
|
+
containers: containers.map((r) => ({
|
|
2195
|
+
applicationId: String(at(r, 'dimensions', 'applicationId') ?? ''),
|
|
2196
|
+
instanceId: String(at(r, 'dimensions', 'instanceId') ?? ''),
|
|
2197
|
+
// Cloudflare answers an absent label as an empty string.
|
|
2198
|
+
tenant: label(at(r, 'dimensions', 'tenant')),
|
|
2199
|
+
app: label(at(r, 'dimensions', 'app')),
|
|
2200
|
+
cpuTimeSec: num(at(r, 'sum', 'cpuTimeSec')),
|
|
2201
|
+
allocatedMemory: num(at(r, 'sum', 'allocatedMemory')),
|
|
2202
|
+
allocatedDisk: num(at(r, 'sum', 'allocatedDisk')),
|
|
2203
|
+
txBytes: num(at(r, 'sum', 'txBytes')),
|
|
2204
|
+
})),
|
|
2205
|
+
}),
|
|
2177
2206
|
});
|
|
2178
2207
|
};
|
|
2179
2208
|
}
|