@goodtiming/baton-sdk 0.6.3 → 0.6.4
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/index.cjs +385 -149
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +92 -32
- package/dist/index.d.ts +92 -32
- package/dist/index.js +385 -149
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const SDK_VERSION = "ts-0.6.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.6.4";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -2232,8 +2232,8 @@ declare function identityScrub(value: unknown): unknown;
|
|
|
2232
2232
|
* for the same reason as Python: MCP stdio transport reserves stdout for
|
|
2233
2233
|
* JSON-RPC framing).
|
|
2234
2234
|
* - `FileSink` — JSONL appended to a file.
|
|
2235
|
-
* - `HttpSink` — POST to any HTTP endpoint with bearer auth;
|
|
2236
|
-
* buffer, retry with backoff, circuit breaker. This is the contract a
|
|
2235
|
+
* - `HttpSink` — POST batches to any HTTP endpoint with bearer auth;
|
|
2236
|
+
* bounded buffer, retry with backoff, circuit breaker. This is the contract a
|
|
2237
2237
|
* Console or any compatible collector consumes.
|
|
2238
2238
|
* - `MultiSink` — every event to each of several sinks.
|
|
2239
2239
|
*/
|
|
@@ -2313,14 +2313,20 @@ interface HttpSinkOptions {
|
|
|
2313
2313
|
/** How long the flush at process exit, or an explicit `flush()` or
|
|
2314
2314
|
* `aclose()`, may take in total, in ms, at most 2^31 - 1. Default 3000. */
|
|
2315
2315
|
shutdownFlushTimeoutMs?: number;
|
|
2316
|
+
/** The longest an event waits before its batch is sent, in ms. Default 5000. */
|
|
2317
|
+
flushIntervalMs?: number;
|
|
2316
2318
|
/** Injectable for tests; defaults to the global `fetch`. */
|
|
2317
2319
|
fetchImpl?: typeof fetch;
|
|
2318
2320
|
}
|
|
2319
|
-
/** POST events to an HTTP endpoint. Bounded buffer + retry +
|
|
2321
|
+
/** POST events to an HTTP endpoint in batches. Bounded buffer + retry +
|
|
2322
|
+
* circuit breaker.
|
|
2320
2323
|
*
|
|
2321
2324
|
* This is the contract a Console or any compatible collector consumes:
|
|
2322
|
-
* `POST {url}/v0/events` with `Authorization: Bearer
|
|
2323
|
-
*
|
|
2325
|
+
* `POST {url}/v0/events/batch` (SPEC §2.5) with `Authorization: Bearer
|
|
2326
|
+
* {apiKey}` and `{"events": [...]}` of SPEC §11.4 envelopes. A batch goes when
|
|
2327
|
+
* 100 events wait, when the next would take the body over 1 MiB, or
|
|
2328
|
+
* `flushIntervalMs` after the oldest waiting one was written. A collector
|
|
2329
|
+
* with no batch endpoint gets one event per `POST {url}/v0/events`.
|
|
2324
2330
|
*
|
|
2325
2331
|
* Failures are bounded — buffer overflow drops the oldest event; network
|
|
2326
2332
|
* failures retry with backoff; the circuit breaker opens after consecutive
|
|
@@ -2328,12 +2334,17 @@ interface HttpSinkOptions {
|
|
|
2328
2334
|
declare class HttpSink implements Sink {
|
|
2329
2335
|
private readonly url;
|
|
2330
2336
|
private readonly apiKey;
|
|
2337
|
+
/** Waiting events only: a batch being sent is out of it, so the bound
|
|
2338
|
+
* never pushes out an event in flight (SPEC §11.2 rule 4). */
|
|
2331
2339
|
private readonly buffer;
|
|
2340
|
+
private bufferedBytes;
|
|
2341
|
+
private sendingEvents;
|
|
2332
2342
|
private readonly bufferSize;
|
|
2333
2343
|
private readonly requestTimeoutMs;
|
|
2334
2344
|
private readonly shutdownFlushTimeoutMs;
|
|
2335
|
-
|
|
2336
|
-
|
|
2345
|
+
private readonly flushIntervalMs;
|
|
2346
|
+
/** Set when an exit pass ends; cleared once a normal drain sends
|
|
2347
|
+
* everything, which means the process went on. */
|
|
2337
2348
|
private exitPassRan;
|
|
2338
2349
|
/** Whether the exit pass warned about every event now buffered. */
|
|
2339
2350
|
private unsentWarned;
|
|
@@ -2343,7 +2354,8 @@ declare class HttpSink implements Sink {
|
|
|
2343
2354
|
private readonly circuit;
|
|
2344
2355
|
private readonly fetchImpl;
|
|
2345
2356
|
private overflowWarned;
|
|
2346
|
-
/** Per status, so a new kind of refusal, such as a 401
|
|
2357
|
+
/** Per status or refusal code, so a new kind of refusal, such as a 401
|
|
2358
|
+
* after a 422, still warns. */
|
|
2347
2359
|
private readonly refusals;
|
|
2348
2360
|
/** Aborted once `aclose()` returns: nothing Baton started may keep the
|
|
2349
2361
|
* process alive after the vendor closed it. */
|
|
@@ -2353,6 +2365,16 @@ declare class HttpSink implements Sink {
|
|
|
2353
2365
|
private skipWarnedFor;
|
|
2354
2366
|
private closeOnce;
|
|
2355
2367
|
private drainChain;
|
|
2368
|
+
private queuedDrain;
|
|
2369
|
+
/** Whether the queued pass sends everything waiting, not only what is due. */
|
|
2370
|
+
private forceNext;
|
|
2371
|
+
private flushTimer;
|
|
2372
|
+
/** Set by a failed batch: only the timer, a flush or a close tries again. */
|
|
2373
|
+
private waitForTimer;
|
|
2374
|
+
/** Nothing is sent before this `Date.now()`, from a 429's `Retry-After`. */
|
|
2375
|
+
private retryAt;
|
|
2376
|
+
/** Set for the life of the sink by a 404 or 405 on the batch path. */
|
|
2377
|
+
private batchless;
|
|
2356
2378
|
private exitHooks;
|
|
2357
2379
|
/** The least time between two of this sink's loss reports. */
|
|
2358
2380
|
private static reportIntervalMs;
|
|
@@ -2360,7 +2382,9 @@ declare class HttpSink implements Sink {
|
|
|
2360
2382
|
private reportedSum;
|
|
2361
2383
|
private lastReportAt;
|
|
2362
2384
|
private reportsStopped;
|
|
2363
|
-
|
|
2385
|
+
/** The envelope of a report due to ride the next batch, and when it was set up. */
|
|
2386
|
+
private pendingReport;
|
|
2387
|
+
private reportSetAt;
|
|
2364
2388
|
constructor(url: string, options: HttpSinkOptions);
|
|
2365
2389
|
/**
|
|
2366
2390
|
* What this sink shows when something prints it — never the bearer.
|
|
@@ -2375,6 +2399,9 @@ declare class HttpSink implements Sink {
|
|
|
2375
2399
|
*/
|
|
2376
2400
|
toJSON(): Record<string, unknown>;
|
|
2377
2401
|
private get closed();
|
|
2402
|
+
private get unsent();
|
|
2403
|
+
/** Encodes at once, not when the batch is cut, because the byte cap
|
|
2404
|
+
* decides when a batch goes. */
|
|
2378
2405
|
write(event: Event): Promise<void>;
|
|
2379
2406
|
flush(): Promise<void>;
|
|
2380
2407
|
/** A second call waits for the first (SPEC §11.2 rule 7). */
|
|
@@ -2388,54 +2415,87 @@ declare class HttpSink implements Sink {
|
|
|
2388
2415
|
* drain is not cancelled here, so after `flush()` it goes on sending;
|
|
2389
2416
|
* `aclose()` stops it. */
|
|
2390
2417
|
private drainWithinBudget;
|
|
2391
|
-
/** A full buffer may already have pushed `event` out while it was being sent. */
|
|
2392
|
-
private dequeue;
|
|
2393
2418
|
private enqueue;
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
*
|
|
2398
|
-
|
|
2419
|
+
private dropOverflow;
|
|
2420
|
+
private batchIsFull;
|
|
2421
|
+
/** The timer must not keep the vendor's process alive: the exit hooks send
|
|
2422
|
+
* what is left. */
|
|
2423
|
+
private armTimer;
|
|
2424
|
+
private clearTimer;
|
|
2425
|
+
/** Runs `drainLocked` after the pass under way, one pass at a time, so two
|
|
2426
|
+
* never send at once or race on the buffer. A pass not yet started is
|
|
2427
|
+
* shared by every caller: one per write would grow without bound while a
|
|
2428
|
+
* slow collector holds a pass. */
|
|
2399
2429
|
private scheduleDrain;
|
|
2400
2430
|
/** Best-effort flush when the process is about to exit without an
|
|
2401
2431
|
* explicit `aclose()`. SIGKILL, or SIGTERM with no installed handler, skip
|
|
2402
2432
|
* both hooks: a vendor needing that guarantee must call `aclose()` from
|
|
2403
2433
|
* their own handler. */
|
|
2404
2434
|
private ensureExitHooksRegistered;
|
|
2405
|
-
/** One attempt per
|
|
2435
|
+
/** One attempt per batch, no retry, within `shutdownFlushTimeoutMs` in
|
|
2406
2436
|
* total (SPEC §11.2); what is left is reported, not sent. */
|
|
2407
2437
|
private exitPass;
|
|
2408
2438
|
private unsentAtExit;
|
|
2409
|
-
private events_url;
|
|
2410
2439
|
private authHeaders;
|
|
2411
2440
|
private static classifyStatus;
|
|
2412
|
-
/**
|
|
2413
|
-
*
|
|
2414
|
-
*
|
|
2441
|
+
/** Counts `n` refused events and logs them, at most once a minute per
|
|
2442
|
+
* kind. A refused event is otherwise dropped silently, which looks the same
|
|
2443
|
+
* from the vendor's process as an accepted one. The collector's own message
|
|
2444
|
+
* is logged because it names the field at fault; it is capped and escaped
|
|
2415
2445
|
* because it is a remote server's text landing in the vendor's log. */
|
|
2416
|
-
private
|
|
2446
|
+
private refuse;
|
|
2417
2447
|
private warnUnloggedRefusals;
|
|
2418
|
-
/** How many refusals
|
|
2419
|
-
* when
|
|
2448
|
+
/** How many refusals of `kind` went unlogged before these `n`, or `null`
|
|
2449
|
+
* when these go unlogged too. */
|
|
2420
2450
|
private refusalToLog;
|
|
2421
2451
|
/** Enough of the body for `REFUSAL_BODY_MAX_LEN` code points; the rest is
|
|
2422
2452
|
* cancelled unread, so a large error page does not hold the drain. */
|
|
2423
2453
|
private static readHead;
|
|
2454
|
+
/** Sends what is due, one batch at a time; `force` (a flush or close) sends
|
|
2455
|
+
* everything waiting. A report set up before the pass rides along; one set
|
|
2456
|
+
* up by this pass's own delivery waits for the next batch. */
|
|
2424
2457
|
private drainLocked;
|
|
2425
|
-
/**
|
|
2426
|
-
*
|
|
2427
|
-
*
|
|
2458
|
+
/** A due report makes the next batch due only when it can ride it; the
|
|
2459
|
+
* timer is armed the same way, so a pass that sends nothing never re-arms
|
|
2460
|
+
* it at a time already past. */
|
|
2461
|
+
private isDue;
|
|
2462
|
+
/** A pending report can go in the next batch: alone, or with the head event's tenant and vendor. */
|
|
2463
|
+
private reportRidesHead;
|
|
2464
|
+
/** Takes the head of the buffer that fits one batch: one tenant and vendor
|
|
2465
|
+
* (SPEC §2.5), at most 100 events and 1 MiB. A due report with the head
|
|
2466
|
+
* event's tenant and vendor takes one of those places; otherwise it is not
|
|
2467
|
+
* built, and waits for a batch it can ride. Without a batch endpoint the same events go one
|
|
2468
|
+
* per request. */
|
|
2469
|
+
private takeBatch;
|
|
2470
|
+
/** Puts a kept batch's events back at the head of the buffer; `true` when
|
|
2471
|
+
* there were none. */
|
|
2472
|
+
private putBack;
|
|
2473
|
+
/** After a delivery, sets up a report of this process's loss totals (SPEC
|
|
2474
|
+
* §11.4.7) to ride the next batch. It stays outside the buffer, so it never
|
|
2475
|
+
* pushes an event out and is never counted as one. */
|
|
2428
2476
|
private maybeReport;
|
|
2429
2477
|
private stopReports;
|
|
2430
|
-
private
|
|
2431
|
-
|
|
2478
|
+
private buildReport;
|
|
2479
|
+
/** Sends one batch, splitting it on 413, until every event in it is
|
|
2480
|
+
* delivered or refused. Returns what a failure kept, to go back in the
|
|
2481
|
+
* buffer. */
|
|
2482
|
+
private sendBatch;
|
|
2483
|
+
private sendEachAlone;
|
|
2484
|
+
/** `alone` is one event per request (SPEC §2.5), so a whole refusal there is that event's own. */
|
|
2485
|
+
private settle;
|
|
2432
2486
|
/** `null`, with a warning, for an event `JSON.stringify` rejects. */
|
|
2433
2487
|
private encode;
|
|
2434
2488
|
private sleepUnlessClosed;
|
|
2435
2489
|
/** Aborted by the timeout or by `aclose()`. Built by hand: `AbortSignal.any`
|
|
2436
2490
|
* is missing before Node 20.3, and on some later versions it keeps every
|
|
2437
|
-
* combined signal alive as long as the long-lived `closing` signal.
|
|
2438
|
-
|
|
2491
|
+
* combined signal alive as long as the long-lived `closing` signal. Any body
|
|
2492
|
+
* read is under the same signal, so a stalled body cannot hold the drain. */
|
|
2493
|
+
private post;
|
|
2494
|
+
/** Every answer but a 2xx and a refusal of the whole batch. */
|
|
2495
|
+
private static otherAnswer;
|
|
2496
|
+
/** The refused results by `event_id` (SPEC §2.5). An event with no readable
|
|
2497
|
+
* result was delivered. */
|
|
2498
|
+
private static refusedIn;
|
|
2439
2499
|
}
|
|
2440
2500
|
|
|
2441
2501
|
/** Principal identity — what a vendor's resolver hands back, and how it goes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const SDK_VERSION = "ts-0.6.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.6.4";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -2232,8 +2232,8 @@ declare function identityScrub(value: unknown): unknown;
|
|
|
2232
2232
|
* for the same reason as Python: MCP stdio transport reserves stdout for
|
|
2233
2233
|
* JSON-RPC framing).
|
|
2234
2234
|
* - `FileSink` — JSONL appended to a file.
|
|
2235
|
-
* - `HttpSink` — POST to any HTTP endpoint with bearer auth;
|
|
2236
|
-
* buffer, retry with backoff, circuit breaker. This is the contract a
|
|
2235
|
+
* - `HttpSink` — POST batches to any HTTP endpoint with bearer auth;
|
|
2236
|
+
* bounded buffer, retry with backoff, circuit breaker. This is the contract a
|
|
2237
2237
|
* Console or any compatible collector consumes.
|
|
2238
2238
|
* - `MultiSink` — every event to each of several sinks.
|
|
2239
2239
|
*/
|
|
@@ -2313,14 +2313,20 @@ interface HttpSinkOptions {
|
|
|
2313
2313
|
/** How long the flush at process exit, or an explicit `flush()` or
|
|
2314
2314
|
* `aclose()`, may take in total, in ms, at most 2^31 - 1. Default 3000. */
|
|
2315
2315
|
shutdownFlushTimeoutMs?: number;
|
|
2316
|
+
/** The longest an event waits before its batch is sent, in ms. Default 5000. */
|
|
2317
|
+
flushIntervalMs?: number;
|
|
2316
2318
|
/** Injectable for tests; defaults to the global `fetch`. */
|
|
2317
2319
|
fetchImpl?: typeof fetch;
|
|
2318
2320
|
}
|
|
2319
|
-
/** POST events to an HTTP endpoint. Bounded buffer + retry +
|
|
2321
|
+
/** POST events to an HTTP endpoint in batches. Bounded buffer + retry +
|
|
2322
|
+
* circuit breaker.
|
|
2320
2323
|
*
|
|
2321
2324
|
* This is the contract a Console or any compatible collector consumes:
|
|
2322
|
-
* `POST {url}/v0/events` with `Authorization: Bearer
|
|
2323
|
-
*
|
|
2325
|
+
* `POST {url}/v0/events/batch` (SPEC §2.5) with `Authorization: Bearer
|
|
2326
|
+
* {apiKey}` and `{"events": [...]}` of SPEC §11.4 envelopes. A batch goes when
|
|
2327
|
+
* 100 events wait, when the next would take the body over 1 MiB, or
|
|
2328
|
+
* `flushIntervalMs` after the oldest waiting one was written. A collector
|
|
2329
|
+
* with no batch endpoint gets one event per `POST {url}/v0/events`.
|
|
2324
2330
|
*
|
|
2325
2331
|
* Failures are bounded — buffer overflow drops the oldest event; network
|
|
2326
2332
|
* failures retry with backoff; the circuit breaker opens after consecutive
|
|
@@ -2328,12 +2334,17 @@ interface HttpSinkOptions {
|
|
|
2328
2334
|
declare class HttpSink implements Sink {
|
|
2329
2335
|
private readonly url;
|
|
2330
2336
|
private readonly apiKey;
|
|
2337
|
+
/** Waiting events only: a batch being sent is out of it, so the bound
|
|
2338
|
+
* never pushes out an event in flight (SPEC §11.2 rule 4). */
|
|
2331
2339
|
private readonly buffer;
|
|
2340
|
+
private bufferedBytes;
|
|
2341
|
+
private sendingEvents;
|
|
2332
2342
|
private readonly bufferSize;
|
|
2333
2343
|
private readonly requestTimeoutMs;
|
|
2334
2344
|
private readonly shutdownFlushTimeoutMs;
|
|
2335
|
-
|
|
2336
|
-
|
|
2345
|
+
private readonly flushIntervalMs;
|
|
2346
|
+
/** Set when an exit pass ends; cleared once a normal drain sends
|
|
2347
|
+
* everything, which means the process went on. */
|
|
2337
2348
|
private exitPassRan;
|
|
2338
2349
|
/** Whether the exit pass warned about every event now buffered. */
|
|
2339
2350
|
private unsentWarned;
|
|
@@ -2343,7 +2354,8 @@ declare class HttpSink implements Sink {
|
|
|
2343
2354
|
private readonly circuit;
|
|
2344
2355
|
private readonly fetchImpl;
|
|
2345
2356
|
private overflowWarned;
|
|
2346
|
-
/** Per status, so a new kind of refusal, such as a 401
|
|
2357
|
+
/** Per status or refusal code, so a new kind of refusal, such as a 401
|
|
2358
|
+
* after a 422, still warns. */
|
|
2347
2359
|
private readonly refusals;
|
|
2348
2360
|
/** Aborted once `aclose()` returns: nothing Baton started may keep the
|
|
2349
2361
|
* process alive after the vendor closed it. */
|
|
@@ -2353,6 +2365,16 @@ declare class HttpSink implements Sink {
|
|
|
2353
2365
|
private skipWarnedFor;
|
|
2354
2366
|
private closeOnce;
|
|
2355
2367
|
private drainChain;
|
|
2368
|
+
private queuedDrain;
|
|
2369
|
+
/** Whether the queued pass sends everything waiting, not only what is due. */
|
|
2370
|
+
private forceNext;
|
|
2371
|
+
private flushTimer;
|
|
2372
|
+
/** Set by a failed batch: only the timer, a flush or a close tries again. */
|
|
2373
|
+
private waitForTimer;
|
|
2374
|
+
/** Nothing is sent before this `Date.now()`, from a 429's `Retry-After`. */
|
|
2375
|
+
private retryAt;
|
|
2376
|
+
/** Set for the life of the sink by a 404 or 405 on the batch path. */
|
|
2377
|
+
private batchless;
|
|
2356
2378
|
private exitHooks;
|
|
2357
2379
|
/** The least time between two of this sink's loss reports. */
|
|
2358
2380
|
private static reportIntervalMs;
|
|
@@ -2360,7 +2382,9 @@ declare class HttpSink implements Sink {
|
|
|
2360
2382
|
private reportedSum;
|
|
2361
2383
|
private lastReportAt;
|
|
2362
2384
|
private reportsStopped;
|
|
2363
|
-
|
|
2385
|
+
/** The envelope of a report due to ride the next batch, and when it was set up. */
|
|
2386
|
+
private pendingReport;
|
|
2387
|
+
private reportSetAt;
|
|
2364
2388
|
constructor(url: string, options: HttpSinkOptions);
|
|
2365
2389
|
/**
|
|
2366
2390
|
* What this sink shows when something prints it — never the bearer.
|
|
@@ -2375,6 +2399,9 @@ declare class HttpSink implements Sink {
|
|
|
2375
2399
|
*/
|
|
2376
2400
|
toJSON(): Record<string, unknown>;
|
|
2377
2401
|
private get closed();
|
|
2402
|
+
private get unsent();
|
|
2403
|
+
/** Encodes at once, not when the batch is cut, because the byte cap
|
|
2404
|
+
* decides when a batch goes. */
|
|
2378
2405
|
write(event: Event): Promise<void>;
|
|
2379
2406
|
flush(): Promise<void>;
|
|
2380
2407
|
/** A second call waits for the first (SPEC §11.2 rule 7). */
|
|
@@ -2388,54 +2415,87 @@ declare class HttpSink implements Sink {
|
|
|
2388
2415
|
* drain is not cancelled here, so after `flush()` it goes on sending;
|
|
2389
2416
|
* `aclose()` stops it. */
|
|
2390
2417
|
private drainWithinBudget;
|
|
2391
|
-
/** A full buffer may already have pushed `event` out while it was being sent. */
|
|
2392
|
-
private dequeue;
|
|
2393
2418
|
private enqueue;
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
*
|
|
2398
|
-
|
|
2419
|
+
private dropOverflow;
|
|
2420
|
+
private batchIsFull;
|
|
2421
|
+
/** The timer must not keep the vendor's process alive: the exit hooks send
|
|
2422
|
+
* what is left. */
|
|
2423
|
+
private armTimer;
|
|
2424
|
+
private clearTimer;
|
|
2425
|
+
/** Runs `drainLocked` after the pass under way, one pass at a time, so two
|
|
2426
|
+
* never send at once or race on the buffer. A pass not yet started is
|
|
2427
|
+
* shared by every caller: one per write would grow without bound while a
|
|
2428
|
+
* slow collector holds a pass. */
|
|
2399
2429
|
private scheduleDrain;
|
|
2400
2430
|
/** Best-effort flush when the process is about to exit without an
|
|
2401
2431
|
* explicit `aclose()`. SIGKILL, or SIGTERM with no installed handler, skip
|
|
2402
2432
|
* both hooks: a vendor needing that guarantee must call `aclose()` from
|
|
2403
2433
|
* their own handler. */
|
|
2404
2434
|
private ensureExitHooksRegistered;
|
|
2405
|
-
/** One attempt per
|
|
2435
|
+
/** One attempt per batch, no retry, within `shutdownFlushTimeoutMs` in
|
|
2406
2436
|
* total (SPEC §11.2); what is left is reported, not sent. */
|
|
2407
2437
|
private exitPass;
|
|
2408
2438
|
private unsentAtExit;
|
|
2409
|
-
private events_url;
|
|
2410
2439
|
private authHeaders;
|
|
2411
2440
|
private static classifyStatus;
|
|
2412
|
-
/**
|
|
2413
|
-
*
|
|
2414
|
-
*
|
|
2441
|
+
/** Counts `n` refused events and logs them, at most once a minute per
|
|
2442
|
+
* kind. A refused event is otherwise dropped silently, which looks the same
|
|
2443
|
+
* from the vendor's process as an accepted one. The collector's own message
|
|
2444
|
+
* is logged because it names the field at fault; it is capped and escaped
|
|
2415
2445
|
* because it is a remote server's text landing in the vendor's log. */
|
|
2416
|
-
private
|
|
2446
|
+
private refuse;
|
|
2417
2447
|
private warnUnloggedRefusals;
|
|
2418
|
-
/** How many refusals
|
|
2419
|
-
* when
|
|
2448
|
+
/** How many refusals of `kind` went unlogged before these `n`, or `null`
|
|
2449
|
+
* when these go unlogged too. */
|
|
2420
2450
|
private refusalToLog;
|
|
2421
2451
|
/** Enough of the body for `REFUSAL_BODY_MAX_LEN` code points; the rest is
|
|
2422
2452
|
* cancelled unread, so a large error page does not hold the drain. */
|
|
2423
2453
|
private static readHead;
|
|
2454
|
+
/** Sends what is due, one batch at a time; `force` (a flush or close) sends
|
|
2455
|
+
* everything waiting. A report set up before the pass rides along; one set
|
|
2456
|
+
* up by this pass's own delivery waits for the next batch. */
|
|
2424
2457
|
private drainLocked;
|
|
2425
|
-
/**
|
|
2426
|
-
*
|
|
2427
|
-
*
|
|
2458
|
+
/** A due report makes the next batch due only when it can ride it; the
|
|
2459
|
+
* timer is armed the same way, so a pass that sends nothing never re-arms
|
|
2460
|
+
* it at a time already past. */
|
|
2461
|
+
private isDue;
|
|
2462
|
+
/** A pending report can go in the next batch: alone, or with the head event's tenant and vendor. */
|
|
2463
|
+
private reportRidesHead;
|
|
2464
|
+
/** Takes the head of the buffer that fits one batch: one tenant and vendor
|
|
2465
|
+
* (SPEC §2.5), at most 100 events and 1 MiB. A due report with the head
|
|
2466
|
+
* event's tenant and vendor takes one of those places; otherwise it is not
|
|
2467
|
+
* built, and waits for a batch it can ride. Without a batch endpoint the same events go one
|
|
2468
|
+
* per request. */
|
|
2469
|
+
private takeBatch;
|
|
2470
|
+
/** Puts a kept batch's events back at the head of the buffer; `true` when
|
|
2471
|
+
* there were none. */
|
|
2472
|
+
private putBack;
|
|
2473
|
+
/** After a delivery, sets up a report of this process's loss totals (SPEC
|
|
2474
|
+
* §11.4.7) to ride the next batch. It stays outside the buffer, so it never
|
|
2475
|
+
* pushes an event out and is never counted as one. */
|
|
2428
2476
|
private maybeReport;
|
|
2429
2477
|
private stopReports;
|
|
2430
|
-
private
|
|
2431
|
-
|
|
2478
|
+
private buildReport;
|
|
2479
|
+
/** Sends one batch, splitting it on 413, until every event in it is
|
|
2480
|
+
* delivered or refused. Returns what a failure kept, to go back in the
|
|
2481
|
+
* buffer. */
|
|
2482
|
+
private sendBatch;
|
|
2483
|
+
private sendEachAlone;
|
|
2484
|
+
/** `alone` is one event per request (SPEC §2.5), so a whole refusal there is that event's own. */
|
|
2485
|
+
private settle;
|
|
2432
2486
|
/** `null`, with a warning, for an event `JSON.stringify` rejects. */
|
|
2433
2487
|
private encode;
|
|
2434
2488
|
private sleepUnlessClosed;
|
|
2435
2489
|
/** Aborted by the timeout or by `aclose()`. Built by hand: `AbortSignal.any`
|
|
2436
2490
|
* is missing before Node 20.3, and on some later versions it keeps every
|
|
2437
|
-
* combined signal alive as long as the long-lived `closing` signal.
|
|
2438
|
-
|
|
2491
|
+
* combined signal alive as long as the long-lived `closing` signal. Any body
|
|
2492
|
+
* read is under the same signal, so a stalled body cannot hold the drain. */
|
|
2493
|
+
private post;
|
|
2494
|
+
/** Every answer but a 2xx and a refusal of the whole batch. */
|
|
2495
|
+
private static otherAnswer;
|
|
2496
|
+
/** The refused results by `event_id` (SPEC §2.5). An event with no readable
|
|
2497
|
+
* result was delivered. */
|
|
2498
|
+
private static refusedIn;
|
|
2439
2499
|
}
|
|
2440
2500
|
|
|
2441
2501
|
/** Principal identity — what a vendor's resolver hands back, and how it goes
|