@plitzi/sdk-kernel 0.39.8 → 0.39.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @plitzi/sdk-kernel
2
2
 
3
+ ## 0.39.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 97d3b64: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
8
+ `@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
9
+ - Updated dependencies [97d3b64]
10
+ - @plitzi/sdk-shared@0.39.10
11
+
12
+ ## 0.39.9
13
+
14
+ ### Patch Changes
15
+
16
+ - f04c646: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
17
+ `@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
18
+ - Updated dependencies [f04c646]
19
+ - @plitzi/sdk-shared@0.39.9
20
+
3
21
  ## 0.39.8
4
22
 
5
23
  ### Patch Changes
@@ -247,10 +247,24 @@ var seriesOf = (buckets, minute) => {
247
247
  lagMs: load.lagMs
248
248
  } : {},
249
249
  ...bucket && bucket.slow.length > 0 ? { runsOf: bucket.slow } : {},
250
- ...bucket && bucket.names.size > 0 ? { names: [...bucket.names.values()].sort((a, b) => b.totalMs - a.totalMs).slice(0, 8) } : {}
250
+ ...bucket && bucket.names.size > 0 ? { names: [...bucket.names.values()].sort((a, b) => b.totalMs - a.totalMs).slice(0, 8) } : {},
251
+ ...bucket && bucket.environments.size > 0 ? { environments: Object.fromEntries(bucket.environments) } : {}
251
252
  };
252
253
  });
253
254
  };
255
+ /** The minute's count for one environment, begun at nothing the first time it is named. */
256
+ var workOf = (bucket, environment) => {
257
+ const kept = bucket.environments.get(environment);
258
+ if (kept) return kept;
259
+ const work = {
260
+ runs: 0,
261
+ failed: 0,
262
+ limited: 0,
263
+ refused: 0
264
+ };
265
+ bucket.environments.set(environment, work);
266
+ return work;
267
+ };
254
268
  /** Whether a kept run is one to look at: it failed, or it reached a limit. */
255
269
  var unanswered = (run) => Number(run.failure !== void 0 || run.limit !== void 0);
256
270
  /**
@@ -340,7 +354,8 @@ var createStatsRecorder = (identity, now = Date.now) => {
340
354
  limits: /* @__PURE__ */ new Map(),
341
355
  refusals: /* @__PURE__ */ new Map(),
342
356
  slow: [],
343
- names: /* @__PURE__ */ new Map()
357
+ names: /* @__PURE__ */ new Map(),
358
+ environments: /* @__PURE__ */ new Map()
344
359
  };
345
360
  buckets.push(bucket);
346
361
  while (buckets.length > 0 && (buckets[0]?.minute ?? minute) <= minute - KEPT_MINUTES) buckets.shift();
@@ -408,15 +423,24 @@ var createStatsRecorder = (identity, now = Date.now) => {
408
423
  }
409
424
  if (end && "failed" in end) add(bucket.failures, end.failed);
410
425
  if (end && "limit" in end) add(bucket.limits, end.limit);
426
+ if (label?.environment) {
427
+ const work = workOf(bucket, label.environment);
428
+ work.runs += 1;
429
+ work.failed += Number(end !== void 0 && "failed" in end);
430
+ work.limited += Number(end !== void 0 && "limit" in end);
431
+ }
411
432
  },
412
- refuse: (reason) => {
413
- add(current().refusals, reason);
433
+ refuse: (reason, environment) => {
434
+ const bucket = current();
435
+ add(bucket.refusals, reason);
436
+ if (environment) workOf(bucket, environment).refused += 1;
414
437
  },
415
- slot: (name, of, used, { queues = false } = {}) => {
438
+ slot: (name, of, used, { queues = false, environments } = {}) => {
416
439
  slots.set(name, {
417
440
  of,
418
441
  used,
419
- queues
442
+ queues,
443
+ ...environments ? { environments } : {}
420
444
  });
421
445
  },
422
446
  snapshot: () => {
@@ -430,7 +454,8 @@ var createStatsRecorder = (identity, now = Date.now) => {
430
454
  const load = {
431
455
  slots: Object.fromEntries([...slots].map(([name, slot]) => [name, {
432
456
  used: slot.used(),
433
- of: slot.of
457
+ of: slot.of,
458
+ ...slot.environments ? { environments: slot.environments() } : {}
434
459
  }])),
435
460
  cpu,
436
461
  memory: {
@@ -1,5 +1,5 @@
1
1
  import { a as isLogged, c as serverLog, d as keepLogEvent, l as traceField, s as renderLogEvent } from "../chunks/serverLog-BWNOjPMV.mjs";
2
- import { a as bearerMatches, f as SHUTDOWN_ANNOUNCE_MS, h as shutdownOf, m as markStopping, n as statsConfigProblem, p as isStopping } from "../chunks/stage-C62Zvzw_.mjs";
2
+ import { a as bearerMatches, f as SHUTDOWN_ANNOUNCE_MS, h as shutdownOf, m as markStopping, n as statsConfigProblem, p as isStopping } from "../chunks/stage-DRzpjuxT.mjs";
3
3
  import { i as hstsFor, n as applySecurityHeaders, r as frameAncestorsOf, t as spaceDeploymentMiddleware } from "../chunks/spaceDeployment-J2IMLfij.mjs";
4
4
  import { TRACEPARENT, readTraceparent, runInTrace, spanOf, traceparentOf } from "../trace/index.mjs";
5
5
  import { a as hostable, i as createStoreHost, n as createFleetHub, o as isFleetMessage, r as createListeners, t as createFleetClient } from "../chunks/channel-b11VTzOp.mjs";
@@ -107,10 +107,13 @@ var buildResponseHelpers = (raw, acceptEncoding, compression = DEFAULT_COMPRESSI
107
107
  * all, where a credential travels beside a value the caller chose (the `scope` it echoes back). Compressing the
108
108
  * two together is the shape a BREACH-style attack needs, and the stage that knows this is the one that has
109
109
  * already said so in a header.
110
+ *
111
+ * A stage that says it to the proxies alone — a page, whose HTML must not be rewritten on the way but is this
112
+ * server's to compress — sends with `ownEncoding`.
110
113
  */
111
- const transformable = () => !String(raw.getHeaders()["cache-control"]).includes("no-transform");
114
+ const transformable = (ownEncoding) => ownEncoding || !String(raw.getHeaders()["cache-control"]).includes("no-transform");
112
115
  /** A stored form this request can take as it is, without the body it was made from. */
113
- const storedFor = (store) => encoding === "identity" || !transformable() ? void 0 : store?.[encoding];
116
+ const storedFor = (store, ownEncoding) => encoding === "identity" || !transformable(ownEncoding) ? void 0 : store?.[encoding];
114
117
  const writeBody = (payload, encoded) => {
115
118
  if (encoded) {
116
119
  raw.setHeader("Content-Encoding", encoding);
@@ -120,8 +123,8 @@ var buildResponseHelpers = (raw, acceptEncoding, compression = DEFAULT_COMPRESSI
120
123
  if (!raw.headersSent) raw.writeHead(statusCode);
121
124
  raw.end(payload);
122
125
  };
123
- const writeSend = (content, store) => {
124
- const stored = typeof content === "function" ? storedFor(store) : void 0;
126
+ const writeSend = (content, store, ownEncoding = false) => {
127
+ const stored = typeof content === "function" ? storedFor(store, ownEncoding) : void 0;
125
128
  if (stored) {
126
129
  writeBody(stored, true);
127
130
  return;
@@ -135,7 +138,7 @@ var buildResponseHelpers = (raw, acceptEncoding, compression = DEFAULT_COMPRESSI
135
138
  * corrupts any font, image or archive served through it. What a Buffer holds is also compressed already
136
139
  * (woff2, png), so re-encoding it would cost CPU to make it bigger.
137
140
  */
138
- const compressed = typeof body === "string" && transformable() ? compressOnce(body, encoding, compression, store) : body;
141
+ const compressed = typeof body === "string" && transformable(ownEncoding) ? compressOnce(body, encoding, compression, store) : body;
139
142
  writeBody(compressed, compressed !== body);
140
143
  };
141
144
  return {
@@ -152,7 +155,7 @@ var buildResponseHelpers = (raw, acceptEncoding, compression = DEFAULT_COMPRESSI
152
155
  statusCode = code;
153
156
  },
154
157
  send(body, options) {
155
- writeSend(body, options?.compressed);
158
+ writeSend(body, options?.compressed, options?.ownEncoding);
156
159
  },
157
160
  write(chunk) {
158
161
  if (!raw.headersSent) raw.writeHead(statusCode);
@@ -7,4 +7,4 @@ export { processMemoryLimit, sampleProcessMemory } from './memory';
7
7
  export type { MemoryReading } from './memory';
8
8
  export type { ProcessLoad } from './load';
9
9
  export type { StatsRecorder } from './recorder';
10
- export type { InstanceHealth, InstancePhase, InstanceStatus, NamedWork, PoolHealth, PoolInstance, PoolKnob, PoolOverride, PoolReport, PoolResources, PoolResourcesControl, PoolScaler, PoolSource, ProcessStats, RunEnd, RunLabel, SlowRun, StatsConfig, StatsGauge, StatsMinute, StatsThresholds, StatsWindow } from './types';
10
+ export type { EnvironmentWork, InstanceHealth, InstancePhase, InstanceStatus, NamedWork, PoolHealth, PoolInstance, PoolKnob, PoolOverride, PoolReport, PoolResources, PoolResourcesControl, PoolScaler, PoolSource, ProcessStats, RunEnd, RunLabel, SlowRun, StatsConfig, StatsGauge, StatsMinute, StatsThresholds, StatsWindow } from './types';
@@ -1,4 +1,4 @@
1
- import { _ as STATS_METRICS_PATH, c as METRICS_CONTENT_TYPE, d as processGauges, g as STATS_LOGS_PATH, i as withStopping, l as gaugesText, n as statsConfigProblem, o as createStatsRecorder, r as statsStage, s as statsRecorderFor, t as deploymentGauges, u as metricsText, v as STATS_PATH } from "../chunks/stage-C62Zvzw_.mjs";
1
+ import { _ as STATS_METRICS_PATH, c as METRICS_CONTENT_TYPE, d as processGauges, g as STATS_LOGS_PATH, i as withStopping, l as gaugesText, n as statsConfigProblem, o as createStatsRecorder, r as statsStage, s as statsRecorderFor, t as deploymentGauges, u as metricsText, v as STATS_PATH } from "../chunks/stage-DRzpjuxT.mjs";
2
2
  import { t as isRecord } from "../chunks/isRecord-jspv0BWl.mjs";
3
3
  import { availableParallelism } from "node:os";
4
4
  import { readFileSync } from "node:fs";
@@ -5,8 +5,8 @@ export type StatsRecorder = {
5
5
  * code), and — when the recorder knows — what it was.
6
6
  */
7
7
  run: (durationMs: number, end?: RunEnd, label?: RunLabel) => void;
8
- /** A request refused before it became a run. */
9
- refuse: (reason: string) => void;
8
+ /** A request refused before it became a run — and for which environment, when whoever refuses it knows. */
9
+ refuse: (reason: string, environment?: string) => void;
10
10
  /**
11
11
  * Work in flight against a size: read when the stats are, so nothing is counted twice. With `queues`, what comes past
12
12
  * the size waits its turn rather than being refused — a worker's jobs, a runner's invocations — and a full slot is a
@@ -15,6 +15,8 @@ export type StatsRecorder = {
15
15
  */
16
16
  slot: (name: string, of: number, used: () => number, options?: {
17
17
  queues?: boolean;
18
+ /** What of it each environment's is, read with `used`: what a screen narrowed to one environment shows. */
19
+ environments?: () => Record<string, number>;
18
20
  }) => void;
19
21
  snapshot: () => ProcessStats;
20
22
  };
@@ -60,6 +60,15 @@ export type RunLabel = {
60
60
  name: string;
61
61
  trigger?: string;
62
62
  runId?: string;
63
+ /** Which of the space's environments it ran for (`production`, `main`…), when whoever records it knows. */
64
+ environment?: string;
65
+ };
66
+ /** What a minute counted for one environment of the spaces: a share of the minute's own figures, never beside them. */
67
+ export type EnvironmentWork = {
68
+ runs: number;
69
+ failed: number;
70
+ limited: number;
71
+ refused: number;
63
72
  };
64
73
  /**
65
74
  * How a run ended when it did not simply answer — three things, because they ask different things of whoever reads it:
@@ -123,6 +132,11 @@ export type StatsMinute = {
123
132
  runsOf?: SlowRun[];
124
133
  /** The actions and functions that took the most of it, up to {@link MINUTE_NAMES}. */
125
134
  names?: NamedWork[];
135
+ /**
136
+ * The minute's work by the environment it was for — the runs and refusals whose recorder said one. What nobody
137
+ * named an environment for is in the minute's totals alone: these never add up to more than them.
138
+ */
139
+ environments?: Record<string, EnvironmentWork>;
126
140
  };
127
141
  /** How many of a minute's runs it keeps by name (its slowest, its failures), and how many of its names. */
128
142
  export declare const MINUTE_RUNS = 5;
@@ -137,10 +151,14 @@ export type ProcessStats = {
137
151
  at: string;
138
152
  uptimeSeconds: number;
139
153
  load: {
140
- /** Work in flight against what this process takes at once: `calls`, `renders`, `isolates`. */
154
+ /**
155
+ * Work in flight against what this process takes at once: `calls`, `renders`, `isolates` — and, where its owner
156
+ * knows, how much of it each environment's is (`environments`).
157
+ */
141
158
  slots: Record<string, {
142
159
  used: number;
143
160
  of: number;
161
+ environments?: Record<string, number>;
144
162
  }>;
145
163
  /** CPU spent over the last sample (ten seconds), as a share of one core over that time. */
146
164
  cpu: number;
@@ -49,9 +49,14 @@ export type SSRResponseHelpers = {
49
49
  *
50
50
  * A function is a body read only when it is needed: when the stored form for this request's encoding is missing, or
51
51
  * the client takes no compression. A static file is then read from disk once per encoding, not on every request.
52
+ *
53
+ * `ownEncoding` is for a body whose `Cache-Control: no-transform` is said to the proxies after this server, not to
54
+ * this server: it is still compressed here — that encoding is how the origin sends it — and nothing on the way may
55
+ * change it. Without it `no-transform` holds this server too, as a response carrying a credential needs.
52
56
  */
53
57
  send: (body: string | Buffer | (() => string), options?: {
54
58
  compressed?: CompressedBodies;
59
+ ownEncoding?: boolean;
55
60
  }) => void;
56
61
  write: (chunk: string | Buffer) => void;
57
62
  end: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-kernel",
3
- "version": "0.39.8",
3
+ "version": "0.39.10",
4
4
  "license": "AGPL-3.0",
5
5
  "description": "What every Plitzi server process is built on: the HTTP pipeline, health and shutdown, the host → deployment resolution, and verifying who a request is.",
6
6
  "files": [
@@ -37,7 +37,7 @@
37
37
  "build:prod": "vite build"
38
38
  },
39
39
  "dependencies": {
40
- "@plitzi/sdk-shared": "0.39.8",
40
+ "@plitzi/sdk-shared": "0.39.10",
41
41
  "jsonwebtoken": "^9.0.3",
42
42
  "undici": "^8.12.4",
43
43
  "ws": "^8.23.0"