@ericminassian/platform-core 0.2.0 → 0.4.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 +1847 -212
- package/dist/api.js +694 -1
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts +19 -0
- package/dist/auth.js +32 -0
- package/dist/auth.js.map +1 -1
- package/dist/base64url.d.ts +3 -0
- package/dist/base64url.js +15 -0
- package/dist/base64url.js.map +1 -0
- package/dist/bindings.d.ts +69 -13
- package/dist/bindings.js +1 -1
- package/dist/bindings.js.map +1 -1
- package/dist/cloudfront-function.d.ts +5 -1
- package/dist/cloudfront-function.js +70 -2
- package/dist/cloudfront-function.js.map +1 -1
- package/dist/compute.d.ts +52 -0
- package/dist/compute.js +65 -0
- package/dist/compute.js.map +1 -0
- package/dist/config.d.ts +21 -1
- package/dist/config.js +16 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +67 -1
- package/dist/constants.js +56 -1
- package/dist/constants.js.map +1 -1
- package/dist/email.d.ts +84 -0
- package/dist/email.js +111 -0
- package/dist/email.js.map +1 -0
- package/dist/fingerprint.d.ts +9 -0
- package/dist/fingerprint.js +19 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +111 -0
- package/dist/jobs.js +214 -0
- package/dist/jobs.js.map +1 -0
- package/dist/manifest.d.ts +357 -112
- package/dist/manifest.js +270 -72
- package/dist/manifest.js.map +1 -1
- package/dist/naming.d.ts +93 -6
- package/dist/naming.js +98 -6
- package/dist/naming.js.map +1 -1
- package/dist/platform-api.d.ts +7792 -0
- package/dist/platform-api.js +455 -0
- package/dist/platform-api.js.map +1 -0
- package/dist/realtime.d.ts +139 -0
- package/dist/realtime.js +201 -0
- package/dist/realtime.js.map +1 -0
- package/dist/router/decide.d.ts +7 -1
- package/dist/router/decide.js +42 -5
- package/dist/router.d.ts +35 -13
- package/dist/router.js +36 -0
- package/dist/router.js.map +1 -1
- package/dist/runtime-config.d.ts +57 -0
- package/dist/runtime-config.js +12 -0
- package/dist/runtime-config.js.map +1 -1
- package/dist/storage.d.ts +55 -0
- package/dist/storage.js +112 -0
- package/dist/storage.js.map +1 -0
- package/dist/telemetry.d.ts +350 -83
- package/dist/telemetry.js +188 -15
- package/dist/telemetry.js.map +1 -1
- package/dist/web-compute.d.ts +191 -0
- package/dist/web-compute.js +257 -0
- package/dist/web-compute.js.map +1 -0
- package/package.json +28 -8
- package/src/api.ts +864 -238
- package/src/auth.ts +37 -0
- package/src/base64url.ts +13 -0
- package/src/bindings.ts +74 -7
- package/src/cloudfront-function.ts +70 -2
- package/src/compute.ts +86 -0
- package/src/config.ts +34 -2
- package/src/constants.ts +76 -1
- package/src/email.ts +168 -0
- package/src/fingerprint.ts +20 -0
- package/src/index.ts +6 -0
- package/src/jobs.ts +281 -0
- package/src/manifest.ts +542 -114
- package/src/naming.ts +103 -8
- package/src/platform-api.ts +630 -0
- package/src/realtime.ts +298 -0
- package/src/router/decide.d.ts +7 -1
- package/src/router/decide.js +42 -5
- package/src/router.ts +33 -13
- package/src/runtime-config.ts +70 -0
- package/src/storage.ts +120 -0
- package/src/telemetry.ts +198 -93
- package/src/web-compute.ts +342 -0
package/dist/telemetry.js
CHANGED
|
@@ -4,9 +4,173 @@
|
|
|
4
4
|
* filter forwards the interesting kinds to the telemetry processor, which
|
|
5
5
|
* aggregates rollups into the telemetry table. Logs Insights covers the rest
|
|
6
6
|
* (search, traces) on demand. No CloudWatch custom metrics are ever created.
|
|
7
|
+
*
|
|
8
|
+
* CloudWatch Logs bills every byte ingested, so lines leave out what a reader
|
|
9
|
+
* can tell without it (a `path` equal to its `route`, a first `attempt`), and
|
|
10
|
+
* most requests and jobs fold their spans into a count (`traceSampled`).
|
|
11
|
+
*/
|
|
12
|
+
import { Schema } from 'effect';
|
|
13
|
+
import { fingerprint, fnv1a } from './fingerprint.js';
|
|
14
|
+
export const TelemetryKind = Schema.Literals(['req', 'err', 'job', 'span', 'log', 'metric', 'limit', 'env']);
|
|
15
|
+
const base = {
|
|
16
|
+
/** Marker so the subscription filter only matches platform lines. */
|
|
17
|
+
_p: Schema.Literal(1),
|
|
18
|
+
/** Epoch milliseconds. */
|
|
19
|
+
ts: Schema.Finite,
|
|
20
|
+
app: Schema.String,
|
|
21
|
+
stage: Schema.String,
|
|
22
|
+
/** Deployment id. */
|
|
23
|
+
rev: Schema.String,
|
|
24
|
+
trace: Schema.optional(Schema.String),
|
|
25
|
+
span: Schema.optional(Schema.String),
|
|
26
|
+
parent: Schema.optional(Schema.String),
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* On a `req` or `job` line: the spans it made (SDK calls, `fetch`es, `traced`
|
|
30
|
+
* units) that weren't written as `span` lines, how many and their total ms.
|
|
31
|
+
* Absent when every span was written. See `TRACE_SAMPLE_RATE`.
|
|
32
|
+
*/
|
|
33
|
+
const unwrittenSpans = {
|
|
34
|
+
calls: Schema.optional(Schema.Finite),
|
|
35
|
+
callMs: Schema.optional(Schema.Finite),
|
|
36
|
+
};
|
|
37
|
+
export const RequestEvent = Schema.Struct({
|
|
38
|
+
...base,
|
|
39
|
+
t: Schema.Literal('req'),
|
|
40
|
+
method: Schema.String,
|
|
41
|
+
/** Route pattern when known (`/api/todos/:id`), else the raw path with ids as `:id`. */
|
|
42
|
+
route: Schema.String,
|
|
43
|
+
/** The raw path, when it isn't `route`. */
|
|
44
|
+
path: Schema.optional(Schema.String),
|
|
45
|
+
status: Schema.Finite,
|
|
46
|
+
/** Duration in ms. */
|
|
47
|
+
dur: Schema.Finite,
|
|
48
|
+
bytes: Schema.optional(Schema.Finite),
|
|
49
|
+
country: Schema.optional(Schema.String),
|
|
50
|
+
/** Hashed user id when signed in. */
|
|
51
|
+
user: Schema.optional(Schema.String),
|
|
52
|
+
cold: Schema.optional(Schema.Boolean),
|
|
53
|
+
...unwrittenSpans,
|
|
54
|
+
});
|
|
55
|
+
export const ErrorEvent = Schema.Struct({
|
|
56
|
+
...base,
|
|
57
|
+
t: Schema.Literal('err'),
|
|
58
|
+
/** `service`: a long-running service's `run` failed (it is rerun after a backoff). */
|
|
59
|
+
source: Schema.Literals(['http', 'job', 'unhandled', 'log', 'service']),
|
|
60
|
+
name: Schema.String,
|
|
61
|
+
message: Schema.String,
|
|
62
|
+
stack: Schema.optional(Schema.String),
|
|
63
|
+
route: Schema.optional(Schema.String),
|
|
64
|
+
job: Schema.optional(Schema.String),
|
|
65
|
+
fingerprint: Schema.String,
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* One unit of work. `service` jobs come from long-running services: `<service>`
|
|
69
|
+
* is a run of the service that ended (it is rerun; `dur` is how long it ran),
|
|
70
|
+
* `<service>/<unit>` a unit of work it marked with `traced`.
|
|
7
71
|
*/
|
|
72
|
+
export const JobEvent = Schema.Struct({
|
|
73
|
+
...base,
|
|
74
|
+
t: Schema.Literal('job'),
|
|
75
|
+
kind: Schema.Literals(['queue', 'event', 'cron', 'invoke', 'service']),
|
|
76
|
+
name: Schema.String,
|
|
77
|
+
status: Schema.Literals(['ok', 'error']),
|
|
78
|
+
dur: Schema.Finite,
|
|
79
|
+
/** A queue message's, event's or cron run's attempt, when it isn't the first. */
|
|
80
|
+
attempt: Schema.optional(Schema.Finite),
|
|
81
|
+
/** What happens after a failed run: tried again later, or moved to the dead-letter queue. */
|
|
82
|
+
next: Schema.optional(Schema.Literals(['retry', 'dead'])),
|
|
83
|
+
...unwrittenSpans,
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* A call a request or job made, written only when its request or job keeps its
|
|
87
|
+
* spans (`TRACE_SAMPLE_RATE`); `parent` is that request's or job's `span`.
|
|
88
|
+
*/
|
|
89
|
+
export const SpanEvent = Schema.Struct({
|
|
90
|
+
...base,
|
|
91
|
+
t: Schema.Literal('span'),
|
|
92
|
+
/** `db.get`, `db.query`, `queue.send`, `events.publish`, `storage.put`, `fetch`, ... */
|
|
93
|
+
op: Schema.String,
|
|
94
|
+
name: Schema.optional(Schema.String),
|
|
95
|
+
dur: Schema.Finite,
|
|
96
|
+
status: Schema.Literals(['ok', 'error']),
|
|
97
|
+
/** Start offset relative to the trace root, ms. */
|
|
98
|
+
start: Schema.optional(Schema.Finite),
|
|
99
|
+
});
|
|
100
|
+
/** A log line; any other fields are the structured fields it was logged with. */
|
|
101
|
+
export const LogEvent = Schema.StructWithRest(Schema.Struct({
|
|
102
|
+
...base,
|
|
103
|
+
t: Schema.Literal('log'),
|
|
104
|
+
level: Schema.Literals(['debug', 'info', 'warn', 'error']),
|
|
105
|
+
msg: Schema.String,
|
|
106
|
+
}), [Schema.Record(Schema.String, Schema.Unknown)]);
|
|
107
|
+
export const MetricEvent = Schema.Struct({
|
|
108
|
+
...base,
|
|
109
|
+
t: Schema.Literal('metric'),
|
|
110
|
+
name: Schema.String,
|
|
111
|
+
value: Schema.Finite,
|
|
112
|
+
unit: Schema.optional(Schema.String),
|
|
113
|
+
});
|
|
114
|
+
/** One `RateLimits` check, and whether the limit let it through. */
|
|
115
|
+
export const LimitEvent = Schema.Struct({
|
|
116
|
+
...base,
|
|
117
|
+
t: Schema.Literal('limit'),
|
|
118
|
+
/** The limit's name (`signups`). Its key (whom it counts) is never sent: it can be a client address. */
|
|
119
|
+
name: Schema.String,
|
|
120
|
+
ok: Schema.Boolean,
|
|
121
|
+
});
|
|
122
|
+
/** A runtime process starting or stopping (`service`: a container of a long-running service). */
|
|
123
|
+
export const EnvEvent = Schema.Struct({
|
|
124
|
+
...base,
|
|
125
|
+
t: Schema.Literal('env'),
|
|
126
|
+
event: Schema.Literals(['start', 'stop']),
|
|
127
|
+
runtime: Schema.Literals(['web', 'worker', 'service']),
|
|
128
|
+
/**
|
|
129
|
+
* How a deployed server runs (`runtime: 'web'`): `request`, a function per
|
|
130
|
+
* request, or `instance`, a Web Function environment. Absent under `plat dev`.
|
|
131
|
+
*/
|
|
132
|
+
compute: Schema.optional(Schema.Literals(['request', 'instance'])),
|
|
133
|
+
/** The service's name (`runtime: 'service'`). */
|
|
134
|
+
name: Schema.optional(Schema.String),
|
|
135
|
+
/** Why it stopped, e.g. `SIGTERM`. */
|
|
136
|
+
reason: Schema.optional(Schema.String),
|
|
137
|
+
initMs: Schema.optional(Schema.Finite),
|
|
138
|
+
});
|
|
139
|
+
/** One telemetry line, as the SDK writes it and the telemetry processor reads it. */
|
|
140
|
+
export const TelemetryEvent = Schema.Union([
|
|
141
|
+
RequestEvent,
|
|
142
|
+
ErrorEvent,
|
|
143
|
+
JobEvent,
|
|
144
|
+
SpanEvent,
|
|
145
|
+
LogEvent,
|
|
146
|
+
MetricEvent,
|
|
147
|
+
LimitEvent,
|
|
148
|
+
EnvEvent,
|
|
149
|
+
]);
|
|
8
150
|
/** Account-level subscription filter: only aggregate-worthy kinds reach the processor. */
|
|
9
|
-
export const TELEMETRY_FILTER_PATTERN = '{ ($._p = 1) && (($.t = "req") || ($.t = "err") || ($.t = "job") || ($.t = "metric") || ($.t = "env")) }';
|
|
151
|
+
export const TELEMETRY_FILTER_PATTERN = '{ ($._p = 1) && (($.t = "req") || ($.t = "err") || ($.t = "job") || ($.t = "metric") || ($.t = "limit") || ($.t = "env")) }';
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// Span sampling
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
/**
|
|
156
|
+
* A request or job writes its spans when it fails (a 5xx, a failed job, or an
|
|
157
|
+
* `err` line while it runs), takes `SLOW_TRACE_MS` or longer, or its trace is
|
|
158
|
+
* in this share of traces (`traceSampled`). The rest write only their own
|
|
159
|
+
* line, with the spans counted on it (`calls`, `callMs`).
|
|
160
|
+
*/
|
|
161
|
+
export const TRACE_SAMPLE_RATE = 1 / 20;
|
|
162
|
+
/** A request or job that takes this long (ms) or longer writes its spans. */
|
|
163
|
+
export const SLOW_TRACE_MS = 1_000;
|
|
164
|
+
/**
|
|
165
|
+
* Whether `trace` is one of the sampled traces. It depends on the trace id
|
|
166
|
+
* alone, so every hop of a trace (server → queue → worker) makes the same
|
|
167
|
+
* choice. Any string works: a client can send its own `x-platform-trace`.
|
|
168
|
+
*/
|
|
169
|
+
export function traceSampled(trace) {
|
|
170
|
+
// Comparing the hash with a threshold (not `% 20`) keeps a trace sampled at
|
|
171
|
+
// one rate sampled at any higher rate.
|
|
172
|
+
return fnv1a(trace) < TRACE_SAMPLE_RATE * 2 ** 32;
|
|
173
|
+
}
|
|
10
174
|
export function isTelemetryEvent(v) {
|
|
11
175
|
return (typeof v === 'object' &&
|
|
12
176
|
v !== null &&
|
|
@@ -38,6 +202,10 @@ export function percentile(hist, p) {
|
|
|
38
202
|
}
|
|
39
203
|
return null;
|
|
40
204
|
}
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
// Rollups (telemetry table layout)
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
export const Resolution = Schema.Literals(['1m', '1h', '1d']);
|
|
41
209
|
export const RESOLUTION_MS = { '1m': 60_000, '1h': 3_600_000, '1d': 86_400_000 };
|
|
42
210
|
/** How long each resolution is kept (DynamoDB TTL). */
|
|
43
211
|
export const RESOLUTION_TTL_DAYS = { '1m': 3, '1h': 35, '1d': 400 };
|
|
@@ -49,28 +217,41 @@ export function bucketStart(ts, res) {
|
|
|
49
217
|
* resolution; `sk` starts with the bucket time so a Query with `BETWEEN`
|
|
50
218
|
* returns a time range.
|
|
51
219
|
*
|
|
52
|
-
* - `m#<app>#<stage>#<res>` sk `<iso>` whole-stage HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[], cold
|
|
220
|
+
* - `m#<app>#<stage>#<res>` sk `<iso>` whole-stage HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[], cold,
|
|
221
|
+
* dur (ms handling them, summed), and process starts:
|
|
222
|
+
* webStarts (webInits of them reported webInitMs, summed),
|
|
223
|
+
* workerStarts, serviceStarts
|
|
53
224
|
* - `r#<app>#<stage>#<res>` sk `<iso>#<route>` per-route HTTP (same fields, plus method)
|
|
54
|
-
* - `j#<app>#<stage>#<res>` sk `<iso>#<kind>:<name>` jobs: ok, error, lat[]
|
|
55
|
-
*
|
|
225
|
+
* - `j#<app>#<stage>#<res>` sk `<iso>#<kind>:<name>` jobs: ok, error, lat[]; `service:<name>` rows also
|
|
226
|
+
* count `starts` (containers of that service starting)
|
|
227
|
+
* - `c#<app>#<stage>#<res>` sk `<iso>#<metric>` custom metrics: count, sum (and the unit)
|
|
228
|
+
* - `l#<app>#<stage>#<res>` sk `<iso>#<limit>` rate limit checks: allowed, denied
|
|
56
229
|
* - `e#<app>#<stage>` sk `<fingerprint>` error groups: count, firstSeen, lastSeen, sample, status
|
|
57
|
-
* - `u#<app>#<stage>` sk `<iso>` uptime
|
|
230
|
+
* - `u#<app>#<stage>` sk `<iso>` uptime: ok, source (`traffic`: req, s5xx; `check`, or none on
|
|
231
|
+
* rows before traffic counted: status, ms)
|
|
58
232
|
*/
|
|
59
233
|
export const telemetryKeys = {
|
|
60
234
|
stage: (app, stage, res) => `m#${app}#${stage}#${res}`,
|
|
61
235
|
route: (app, stage, res) => `r#${app}#${stage}#${res}`,
|
|
62
236
|
job: (app, stage, res) => `j#${app}#${stage}#${res}`,
|
|
63
237
|
metric: (app, stage, res) => `c#${app}#${stage}#${res}`,
|
|
238
|
+
limit: (app, stage, res) => `l#${app}#${stage}#${res}`,
|
|
64
239
|
errors: (app, stage) => `e#${app}#${stage}`,
|
|
65
240
|
uptime: (app, stage) => `u#${app}#${stage}`,
|
|
241
|
+
/**
|
|
242
|
+
* Email usage: sk `YYYY-MM-DD` (UTC), `n` recipients sent. The SDK writes it
|
|
243
|
+
* with the stage role, whose IAM grant covers only this partition.
|
|
244
|
+
*/
|
|
245
|
+
email: (app, stage) => `mail#${app}#${stage}`,
|
|
66
246
|
time: (ts) => new Date(ts).toISOString(),
|
|
67
247
|
};
|
|
68
248
|
// ---------------------------------------------------------------------------
|
|
69
249
|
// Error fingerprinting (Sentry-style grouping)
|
|
70
250
|
// ---------------------------------------------------------------------------
|
|
71
|
-
/** Normalize volatile parts (ids, numbers, quoted values) so similar errors group together. */
|
|
251
|
+
/** Normalize volatile parts (ARNs, ids, numbers, quoted values) so similar errors group together. */
|
|
72
252
|
export function normalizeErrorMessage(message) {
|
|
73
253
|
return message
|
|
254
|
+
.replace(/\barn:aws[\w-]*:[^\s"'`,()]+/g, '<arn>')
|
|
74
255
|
.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, '<uuid>')
|
|
75
256
|
.replace(/\b[0-9a-f]{16,}\b/gi, '<hex>')
|
|
76
257
|
.replace(/(["'`]).*?\1/g, '<str>')
|
|
@@ -91,15 +272,7 @@ export function topFrame(stack) {
|
|
|
91
272
|
}
|
|
92
273
|
return '';
|
|
93
274
|
}
|
|
94
|
-
|
|
95
|
-
export function fingerprint(parts) {
|
|
96
|
-
let h = 0x811c9dc5;
|
|
97
|
-
for (const ch of parts.join('|')) {
|
|
98
|
-
h ^= ch.codePointAt(0);
|
|
99
|
-
h = Math.imul(h, 0x01000193) >>> 0;
|
|
100
|
-
}
|
|
101
|
-
return h.toString(16).padStart(8, '0');
|
|
102
|
-
}
|
|
275
|
+
export { fingerprint } from './fingerprint.js';
|
|
103
276
|
export function errorFingerprint(name, message, stack) {
|
|
104
277
|
return fingerprint([name, normalizeErrorMessage(message), topFrame(stack)]);
|
|
105
278
|
}
|
package/dist/telemetry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,KAAK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,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
export declare const WEB_COMPUTE: readonly ['request', 'instance'];
|
|
2
|
+
export type WebCompute = (typeof WEB_COMPUTE)[number];
|
|
3
|
+
/** `web.compute` in plat.config.ts. */
|
|
4
|
+
export declare const WEB_COMPUTE_SETTINGS: readonly ["auto", "request", "instance"];
|
|
5
|
+
export type WebComputeSetting = (typeof WEB_COMPUTE_SETTINGS)[number];
|
|
6
|
+
/**
|
|
7
|
+
* Memory of a request-mode server unless `web.memoryMb` says otherwise, from
|
|
8
|
+
* the template app's server bundle (2.1 MB, measured 2026-11-16). INIT took
|
|
9
|
+
* 460–650 ms at 512, 1024 and 1769 MB alike, but Lambda gives the handler CPU
|
|
10
|
+
* in proportion to memory: the first request after INIT took ~115 ms at
|
|
11
|
+
* 512 MB, ~60 ms at 1024 and ~40 ms at 1769, and warm requests 12–148 ms at
|
|
12
|
+
* 512 against 5–11 ms at the other two. So 1024 MB answers faster than 512 and
|
|
13
|
+
* costs less per warm request (the shorter time more than pays for the
|
|
14
|
+
* doubled rate); 1769 MB only costs more. Each environment used ~140 MB.
|
|
15
|
+
*/
|
|
16
|
+
export declare const WEB_REQUEST_MEMORY_MB = 1024;
|
|
17
|
+
/**
|
|
18
|
+
* Most environments a Web Function endpoint runs at once. Lambda keeps
|
|
19
|
+
* spare, billed environments next to busy ones (CI bursts ran 9–25), so this
|
|
20
|
+
* also caps that headroom. Prod takes `web.maxEnvironments`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const WEB_MAX_ENVIRONMENTS: {
|
|
23
|
+
readonly preview: 2;
|
|
24
|
+
readonly prod: 10;
|
|
25
|
+
};
|
|
26
|
+
/** The first `@ericminassian/platform` whose server bundle also runs as a request-mode handler. */
|
|
27
|
+
export declare const REQUEST_MODE_MIN_SDK = "0.4.0";
|
|
28
|
+
/** Whether a bundle built with this SDK version can run in request mode. */
|
|
29
|
+
export declare function supportsRequestMode(sdk: string | undefined): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The account Lambda concurrency `auto` needs before it runs request mode.
|
|
32
|
+
* Request-mode servers share the account's concurrency with every worker; a
|
|
33
|
+
* new account's limit is 10, which one burst of browser tests on a preview
|
|
34
|
+
* can exceed, and Lambda answers throttled requests with errors. Web
|
|
35
|
+
* Functions scale on their own quota. AWS keeps 100 unreserved at the usual
|
|
36
|
+
* 1,000.
|
|
37
|
+
*/
|
|
38
|
+
export declare const REQUEST_MODE_MIN_ACCOUNT_CONCURRENCY = 100;
|
|
39
|
+
/** Why `auto` keeps a server off request mode on this account, or undefined when it needn't. */
|
|
40
|
+
export declare function requestModeBlocked(accountConcurrency: number | undefined): string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* The mode a deploy runs the server in. `auto` runs request mode everywhere
|
|
43
|
+
* but prod, where a stage keeps the mode it has (the chooser changes it) and
|
|
44
|
+
* starts in request mode. A bundle built with an SDK older than
|
|
45
|
+
* `REQUEST_MODE_MIN_SDK` only runs as a Web Function, and so does `auto` on an
|
|
46
|
+
* account without the Lambda concurrency request mode needs
|
|
47
|
+
* (`requestModeBlocked`); `note` then says why.
|
|
48
|
+
*/
|
|
49
|
+
export declare function webComputeFor(input: {
|
|
50
|
+
setting: WebComputeSetting;
|
|
51
|
+
stage: string;
|
|
52
|
+
/** The mode the stage's server runs in now, if it has one. */
|
|
53
|
+
current?: WebCompute | undefined;
|
|
54
|
+
/** The deployment's `@ericminassian/platform` version. */
|
|
55
|
+
sdk?: string | undefined;
|
|
56
|
+
/** The account's Lambda concurrency limit, when known. */
|
|
57
|
+
accountConcurrency?: number | undefined;
|
|
58
|
+
}): {
|
|
59
|
+
compute: WebCompute;
|
|
60
|
+
note?: string;
|
|
61
|
+
} | {
|
|
62
|
+
error: string;
|
|
63
|
+
};
|
|
64
|
+
/** `maxEnvironments` of a stage's Web Function endpoints. */
|
|
65
|
+
export declare function webMaxEnvironments(web: {
|
|
66
|
+
maxEnvironments?: number | undefined;
|
|
67
|
+
}, stage: string): number;
|
|
68
|
+
/**
|
|
69
|
+
* What the router sends a stage's request-mode server in `ORIGIN_HEADER`:
|
|
70
|
+
* HKDF of the stage key, so the engine (which writes it into the route) and
|
|
71
|
+
* the SDK (which checks it) agree without storing another secret.
|
|
72
|
+
*/
|
|
73
|
+
export declare function originSecret(stageKey: string): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Prices behind the estimates, us-east-1, checked 2026-11-16. Request mode is
|
|
76
|
+
* Lambda on arm64; its INIT is billed like duration. Web Functions bill the
|
|
77
|
+
* memory an environment uses (not what it may use) for its whole life, vCPU
|
|
78
|
+
* per second it works, and requests. Neither estimate subtracts the free
|
|
79
|
+
* tier: the account's workers draw on it too.
|
|
80
|
+
*/
|
|
81
|
+
export declare const WEB_COMPUTE_PRICES_USD: {
|
|
82
|
+
readonly request: {
|
|
83
|
+
readonly gbSecond: 0.0000133334;
|
|
84
|
+
readonly perMillionRequests: 0.2;
|
|
85
|
+
};
|
|
86
|
+
readonly instance: {
|
|
87
|
+
readonly gbSecond: 0.000003667;
|
|
88
|
+
readonly vcpuSecond: 0.0000277;
|
|
89
|
+
readonly perMillionRequests: 0.3;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/** How long a Web Function environment lives after its last request (measured: ~290 s). */
|
|
93
|
+
export declare const INSTANCE_IDLE_SECONDS = 290;
|
|
94
|
+
/**
|
|
95
|
+
* How long Lambda keeps an idle request-mode environment for the next
|
|
96
|
+
* request. Undocumented; observed to be several minutes, so the simulation
|
|
97
|
+
* assumes the short end.
|
|
98
|
+
*/
|
|
99
|
+
export declare const REQUEST_IDLE_MINUTES = 5;
|
|
100
|
+
/** A Web Function environment's memory when CloudWatch has none for the stage (measured: ~250 MB). */
|
|
101
|
+
export declare const INSTANCE_DEFAULT_MEMORY_MB = 256;
|
|
102
|
+
/**
|
|
103
|
+
* A cold start's INIT when the stage reported none (`env` lines' `initMs`,
|
|
104
|
+
* which came within ~30 ms of Lambda's own figure). Measured: 460–650 ms for
|
|
105
|
+
* the template app's server.
|
|
106
|
+
*/
|
|
107
|
+
export declare const DEFAULT_INIT_MS = 550;
|
|
108
|
+
/** One minute of a stage's requests (the telemetry's whole-stage minute rollup). */
|
|
109
|
+
export interface MinuteTraffic {
|
|
110
|
+
/** Start of the minute, epoch ms. */
|
|
111
|
+
ts: number;
|
|
112
|
+
req: number;
|
|
113
|
+
/** Time spent handling them, summed (ms). */
|
|
114
|
+
durMs: number;
|
|
115
|
+
}
|
|
116
|
+
export interface WebComputeSimulationInput {
|
|
117
|
+
/** Minutes with requests in `from`..`to` (the others had none). */
|
|
118
|
+
minutes: readonly MinuteTraffic[];
|
|
119
|
+
from: number;
|
|
120
|
+
to: number;
|
|
121
|
+
/** `web.memoryMb`. */
|
|
122
|
+
requestMemoryMb: number;
|
|
123
|
+
/** What a Web Function environment uses. */
|
|
124
|
+
instanceMemoryMb: number;
|
|
125
|
+
/** `web.concurrency`: requests one Web Function environment serves at once. */
|
|
126
|
+
maxConcurrencyPerEnvironment: number;
|
|
127
|
+
/** A cold start's INIT, ms. */
|
|
128
|
+
initMs: number;
|
|
129
|
+
}
|
|
130
|
+
export interface WebComputeEstimate {
|
|
131
|
+
/** A month of this traffic in request mode. */
|
|
132
|
+
request: {
|
|
133
|
+
monthlyUsd: number;
|
|
134
|
+
coldStartsPerMonth: number;
|
|
135
|
+
};
|
|
136
|
+
/** A month of this traffic in instance mode. */
|
|
137
|
+
instance: {
|
|
138
|
+
monthlyUsd: number;
|
|
139
|
+
environmentHoursPerMonth: number;
|
|
140
|
+
};
|
|
141
|
+
requestsPerMonth: number;
|
|
142
|
+
/** Days of traffic the month is extrapolated from. */
|
|
143
|
+
days: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Both modes' monthly cost for the traffic in `minutes`, extrapolated from
|
|
147
|
+
* `from`..`to`. Minute data only has averages, so a minute's concurrency is
|
|
148
|
+
* its handling time over 60 s:
|
|
149
|
+
*
|
|
150
|
+
* - request: handling time × memory, cold starts × INIT × memory, requests.
|
|
151
|
+
* A minute needs as many environments as its concurrency (at least one);
|
|
152
|
+
* environments idle longer than `REQUEST_IDLE_MINUTES` are gone.
|
|
153
|
+
* - instance: environments alive from each busy minute until
|
|
154
|
+
* `INSTANCE_IDLE_SECONDS` after it, as many as its concurrency over
|
|
155
|
+
* `maxConcurrencyPerEnvironment` (at least one), × memory; vCPU for the
|
|
156
|
+
* time an environment has a request in flight; requests.
|
|
157
|
+
*
|
|
158
|
+
* Overlapping requests are what instance mode bills once and request mode
|
|
159
|
+
* bills each, so a stage busy enough to keep requests overlapping is the one
|
|
160
|
+
* that moves to instance mode.
|
|
161
|
+
*/
|
|
162
|
+
export declare function simulateWebCompute(input: WebComputeSimulationInput): WebComputeEstimate;
|
|
163
|
+
/** The other mode must cost this much less (a share of the current one's cost), this many days running. */
|
|
164
|
+
export declare const COMPUTE_SWITCH_RULE: {
|
|
165
|
+
readonly cheaperBy: 0.25;
|
|
166
|
+
readonly days: 3;
|
|
167
|
+
};
|
|
168
|
+
/** Days in a row the other mode was cheaper enough, kept on the stage. */
|
|
169
|
+
export interface ComputeStreak {
|
|
170
|
+
to: WebCompute;
|
|
171
|
+
days: number;
|
|
172
|
+
/** The last day it was (UTC, `YYYY-MM-DD`). */
|
|
173
|
+
day: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Today's step of the switching rule: the streak to keep, and the mode to
|
|
177
|
+
* switch to once the other mode has been `COMPUTE_SWITCH_RULE.cheaperBy`
|
|
178
|
+
* cheaper `COMPUTE_SWITCH_RULE.days` days running. A second run on the same
|
|
179
|
+
* day changes nothing; a day the other mode wasn't cheaper enough, or a day
|
|
180
|
+
* without a run, starts the count over.
|
|
181
|
+
*/
|
|
182
|
+
export declare function nextComputeStreak(input: {
|
|
183
|
+
current: WebCompute;
|
|
184
|
+
estimate: Pick<WebComputeEstimate, 'request' | 'instance'>;
|
|
185
|
+
streak?: ComputeStreak | undefined;
|
|
186
|
+
/** Today, UTC `YYYY-MM-DD`. */
|
|
187
|
+
day: string;
|
|
188
|
+
}): {
|
|
189
|
+
streak?: ComputeStreak;
|
|
190
|
+
switchTo?: WebCompute;
|
|
191
|
+
};
|