/** * Usage counters, emitted as one rolled-up event per N requests. * * ONE EVENT PER REQUEST WAS THE OBVIOUS SHAPE AND IT DOES NOT WORK. The log * rotates at 4 MiB and a flush sends at most 500 events, so a busy session would * write thousands of rows, upload the first 500 of them and drop the rest -- and * the totals computed from that upload would be a sample nobody chose, biased * toward the start of every session. Accumulating in memory and emitting a * rollup keeps the totals EXACT for every request that happened, at the cost of * the per-request distribution, and one rollup per 200 requests means a single * 500-event flush covers a hundred thousand requests. * * WHAT IS LOST IF THE PROCESS DIES: at most the requests since the last rollup. * `flushRollup` is called on proxy shutdown to narrow that to zero on a clean * exit, and a kill costs under 200 requests' worth of counts -- which is why the * emit is periodic rather than only at the end. * * NOTHING HERE DECIDES CONSENT. Counting happens in memory whatever the policy * says, because the counters are also what the proxy's own log reports; `record` * is the gate, and it checks the policy itself on every call. A session that * never opted in accumulates numbers that are never written anywhere. */ import { record } from './recorder.js'; /** Requests per rollup. See the header for why this is not 1. */ export declare const ROLLUP_EVERY = 200; /** One request's facts, as the proxy summary already reports them. */ export interface RequestFacts { readonly beforeBytes: number; readonly afterBytes: number; readonly compressed: boolean; readonly injectedChars?: number; readonly elisions?: number; readonly spilledBlocks?: number; /** * How many withheld units this request brought back. * * `spilledBlocks` is how many left; this is how many returned. The ratio is * the reference rate, and it is the only thing the whole withholding case * turns on: a withheld unit saves its residency for every remaining turn and * costs nothing unless it is wanted again. It had been estimated once, at * 0.23, from textual recurrence on a borrowed corpus, in the direction that * flatters the arm, with no second signal to check it against. */ readonly reinstatedUnits?: number; /** * True when nothing may leave the request -- the default arm. * * Mirrors `!options.spill` at the proxy, which is fixed for the life of the * process, so every request in a window reports the same value. */ readonly losslessMode?: boolean; } /** * Count one request, and emit a rollup when the window is full. * * Returns the event if one was written, so a caller can assert that the * threshold is what triggers an emit rather than inferring it from a file. */ export declare function noteRequest(facts: RequestFacts, env?: NodeJS.ProcessEnv): ReturnType; /** * Write what has accumulated, if anything has. Called at shutdown. * * `reason` is a COUNT, not a string: the schema admits numbers and booleans * only, so "was this the shutdown rollup" is a boolean and not a label that * would be silently dropped on the way to disk. */ export declare function flushRollup(env?: NodeJS.ProcessEnv): ReturnType; /** The counts not yet emitted. For `doctor` and for tests; never for a caller's arithmetic. */ export declare function pendingCounts(): Readonly>; /** Drop everything counted so far without writing it. Tests only. */ export declare function resetRollup(): void; //# sourceMappingURL=rollup.d.ts.map