@loadstrike/loadstrike-sdk 1.0.30201 → 1.0.31001

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.
@@ -0,0 +1,230 @@
1
+ import { type IterationObservationDiagnosticLogger } from "./iteration-observation-diagnostics.js";
2
+ export declare const ITERATION_OBSERVATION_SCHEMA_VERSION = "loadstrike.iteration-observation/1";
3
+ export declare const ITERATION_OBSERVATION_BATCH_SCHEMA_VERSION = "loadstrike.iteration-batch/1";
4
+ export declare const ITERATION_OBSERVATION_STREAM_COMPLETION_SCHEMA_VERSION = "loadstrike.iteration-stream-completion/1";
5
+ export interface LoadStrikeIterationStepObservationV1 {
6
+ stepName: string;
7
+ sortIndex: number;
8
+ startedUtcNs: string;
9
+ completedUtcNs: string;
10
+ observedLatencyUs64: string;
11
+ reportedLatencyUs64: string;
12
+ isSuccess: boolean;
13
+ statusCode: string;
14
+ sizeBytes64: string;
15
+ }
16
+ export interface LoadStrikeIterationObservationV1 {
17
+ schemaVersion: typeof ITERATION_OBSERVATION_SCHEMA_VERSION;
18
+ observationId: string;
19
+ runId: string;
20
+ sessionId: string;
21
+ resultOwnerId: string;
22
+ processGroup: number;
23
+ scenarioName: string;
24
+ scenarioIndex: number;
25
+ simulationIndex: number;
26
+ simulationKind: string;
27
+ phase: "warmup" | "bombing";
28
+ globalOrdinal64: string;
29
+ globalSecondaryOrdinal64: string;
30
+ shardIndex: number;
31
+ shardCount: number;
32
+ iterationId: string;
33
+ attemptIndex: number;
34
+ isFinalAttempt: boolean;
35
+ startedUtcNs: string;
36
+ completedUtcNs: string;
37
+ observedLatencyUs64: string;
38
+ reportedLatencyUs64: string;
39
+ isSuccess: boolean;
40
+ statusCode: string;
41
+ sizeBytes64: string;
42
+ steps: LoadStrikeIterationStepObservationV1[];
43
+ }
44
+ export interface LoadStrikeIterationObservationBatchV1 {
45
+ schemaVersion: typeof ITERATION_OBSERVATION_BATCH_SCHEMA_VERSION;
46
+ batchId: string;
47
+ runId: string;
48
+ sessionId: string;
49
+ resultOwnerId: string;
50
+ processGroup: number;
51
+ batchSequence64: string;
52
+ createdUtcNs: string;
53
+ firstObservationUtcNs: string;
54
+ lastObservationUtcNs: string;
55
+ observations: LoadStrikeIterationObservationV1[];
56
+ capturedCount64: string;
57
+ droppedBeforeBatch64: string;
58
+ compression: "gzip-json";
59
+ }
60
+ export interface LoadStrikeIterationObservationStreamCompletionV1 {
61
+ schemaVersion: typeof ITERATION_OBSERVATION_STREAM_COMPLETION_SCHEMA_VERSION;
62
+ runId: string;
63
+ sessionId: string;
64
+ resultOwnerId: string;
65
+ /** Additive in schema v1. Readers must treat an absent value as "1". */
66
+ expectedResultOwnerCount64?: string;
67
+ processGroup: number;
68
+ lastBatchSequence64: string;
69
+ capturedCount64: string;
70
+ deliveredCount64: string;
71
+ droppedBufferCount64: string;
72
+ droppedSinkCount64: string;
73
+ reportingComplete: boolean;
74
+ completedUtcNs: string;
75
+ }
76
+ export interface LoadStrikeObservationDeliveryStats {
77
+ lastBatchSequence64: string;
78
+ capturedCount64: string;
79
+ deliveredCount64: string;
80
+ droppedBufferCount64: string;
81
+ droppedSinkCount64: string;
82
+ readonly LastBatchSequence64?: string;
83
+ readonly CapturedCount64?: string;
84
+ readonly DeliveredCount64?: string;
85
+ readonly DroppedBufferCount64?: string;
86
+ readonly DroppedSinkCount64?: string;
87
+ }
88
+ export interface IterationObservationDeliveryResult extends LoadStrikeObservationDeliveryStats {
89
+ reportingComplete: boolean;
90
+ }
91
+ export interface IterationObservationGeneratorWarning {
92
+ code: string;
93
+ sinkName?: string;
94
+ scenarioName: string;
95
+ scenarioIndex: number;
96
+ simulationIndex: number;
97
+ simulationKind: string;
98
+ count64: string;
99
+ message: string;
100
+ firstObservedUtcNs: string;
101
+ lastObservedUtcNs: string;
102
+ }
103
+ export interface IterationObservationSettings {
104
+ flushIntervalMs: number;
105
+ maxBufferBytes: number;
106
+ maxObservationsPerBatch: number;
107
+ maxBatchBytes: number;
108
+ sinkQueueDepth: number;
109
+ sinkParallelism: number;
110
+ drainTimeoutMs: number;
111
+ }
112
+ export declare const DEFAULT_ITERATION_OBSERVATION_SETTINGS: Readonly<IterationObservationSettings>;
113
+ export interface IterationObservationClock {
114
+ nowUtcNs(): bigint;
115
+ setInterval(callback: () => void, intervalMs: number): unknown;
116
+ clearInterval(handle: unknown): void;
117
+ }
118
+ export interface IterationObservationSinkTarget {
119
+ name: string;
120
+ iterationObservationPortalSink?: boolean;
121
+ iterationObservationShapeLimited?: boolean;
122
+ saveIterationBatch?: (batch: LoadStrikeIterationObservationBatchV1) => Promise<void> | void;
123
+ completeIterationObservationStream?: (completion: LoadStrikeIterationObservationStreamCompletionV1) => Promise<void> | void;
124
+ }
125
+ export interface CreateIterationStepObservationInput {
126
+ stepName: string;
127
+ sortIndex: number;
128
+ startedUtcNs: string | bigint | number;
129
+ completedUtcNs: string | bigint | number;
130
+ observedLatencyUs64: string | bigint | number;
131
+ reportedLatencyUs64: string | bigint | number;
132
+ isSuccess: boolean;
133
+ statusCode: string;
134
+ sizeBytes64: string | bigint | number;
135
+ }
136
+ export interface CreateIterationObservationInput {
137
+ runId: string;
138
+ sessionId: string;
139
+ resultOwnerId: string;
140
+ processGroup: number;
141
+ scenarioName: string;
142
+ scenarioIndex: number;
143
+ simulationIndex: number;
144
+ simulationKind: string;
145
+ phase: "warmup" | "bombing";
146
+ globalOrdinal64: string | bigint | number;
147
+ globalSecondaryOrdinal64?: string | bigint | number;
148
+ iterationId?: string;
149
+ shardIndex: number;
150
+ shardCount: number;
151
+ attemptIndex: number;
152
+ isFinalAttempt: boolean;
153
+ startedUtcNs: string | bigint | number;
154
+ completedUtcNs: string | bigint | number;
155
+ observedLatencyUs64: string | bigint | number;
156
+ reportedLatencyUs64: string | bigint | number;
157
+ isSuccess: boolean;
158
+ statusCode: string;
159
+ sizeBytes64: string | bigint | number;
160
+ steps: LoadStrikeIterationStepObservationV1[];
161
+ }
162
+ interface BufferedObservation {
163
+ observation: LoadStrikeIterationObservationV1;
164
+ jsonBytes: number;
165
+ }
166
+ export declare function utcNowNs(): bigint;
167
+ export declare function deriveIterationId(runId: string, resultOwnerId: string, scenarioName: string, simulationIndex: number, globalOrdinal64: string | bigint | number): string;
168
+ export declare function deriveObservationId(iterationId: string, attemptIndex: number): string;
169
+ export declare function deriveIterationBatchId(runId: string, resultOwnerId: string, batchSequence64: string | bigint | number): string;
170
+ export declare function createIterationStepObservation(input: CreateIterationStepObservationInput): LoadStrikeIterationStepObservationV1;
171
+ export declare function createIterationObservation(input: CreateIterationObservationInput): LoadStrikeIterationObservationV1;
172
+ export declare function serializeIterationObservationBatchGzipJson(value: unknown): Buffer;
173
+ export declare class ProcessIterationObservationBuffer {
174
+ private readonly streams;
175
+ private readonly streamLimits;
176
+ private totalBytes;
177
+ get byteLength(): number;
178
+ register(streamKey: symbol, maxBufferBytes: number): void;
179
+ offer(streamKey: symbol, observation: LoadStrikeIterationObservationV1, maxBufferBytes: number, encodedBytes?: number): boolean;
180
+ drain(streamKey: symbol): BufferedObservation[];
181
+ release(streamKey: symbol): void;
182
+ unregister(streamKey: symbol): void;
183
+ private effectiveLimit;
184
+ }
185
+ export interface IterationObservationReporterOptions {
186
+ runId: string;
187
+ sessionId: string;
188
+ resultOwnerId: string;
189
+ expectedResultOwnerCount64?: string | bigint | number;
190
+ processGroup: number;
191
+ sinks: IterationObservationSinkTarget[];
192
+ settings?: Partial<IterationObservationSettings>;
193
+ buffer?: ProcessIterationObservationBuffer;
194
+ clock?: IterationObservationClock;
195
+ skipValidation?: boolean;
196
+ sinkRetryCount?: number;
197
+ sinkRetryBackoffMs?: number;
198
+ logger?: IterationObservationDiagnosticLogger;
199
+ }
200
+ export declare class IterationObservationReporter {
201
+ private readonly options;
202
+ private readonly streamKey;
203
+ private readonly settings;
204
+ private readonly buffer;
205
+ private readonly clock;
206
+ private readonly dispatchers;
207
+ private readonly warnings;
208
+ private readonly timer;
209
+ private readonly batchEnvelopeBytes;
210
+ private sequence;
211
+ private captured;
212
+ private droppedBuffer;
213
+ private unsupportedSinkCount;
214
+ private sealed;
215
+ private finalResult;
216
+ private readonly expectedResultOwnerCount64;
217
+ constructor(options: IterationObservationReporterOptions);
218
+ get enabled(): boolean;
219
+ capture(observation: LoadStrikeIterationObservationV1): boolean;
220
+ flushNow(): void;
221
+ sealAndDrain(): Promise<IterationObservationDeliveryResult>;
222
+ private completeWithRetries;
223
+ buildWarnings(): IterationObservationGeneratorWarning[];
224
+ private createBatch;
225
+ private createCompletion;
226
+ private recordSinkDrop;
227
+ private recordWarning;
228
+ }
229
+ export declare function validateIterationObservationSettings(settings: IterationObservationSettings): void;
230
+ export {};
@@ -0,0 +1,147 @@
1
+ export interface LoadEngineV2Settings {
2
+ contractVersion: 2;
3
+ maxInFlight: number;
4
+ clusterLoadScope: "Global";
5
+ statisticsReportingIntervalNs: bigint;
6
+ maxStatusGroupsPerSeries: number;
7
+ }
8
+ export interface LoadEngineV2TrafficMixUnit {
9
+ laneOrdinal: bigint;
10
+ globalRank: bigint;
11
+ }
12
+ export declare function buildLoadEngineV2TrafficMixRunId(runId: string, declarationIndex: number, name: string): string;
13
+ export declare function buildLoadEngineV2TrafficMixSeedId(declarationIndex: number, name: string): string;
14
+ export declare function loadEngineV2TrafficMixRank(weights: readonly number[], laneIndex: number, laneOrdinal: bigint): bigint;
15
+ export declare function loadEngineV2TrafficMixLaneUnitCount(globalUnitCount: bigint, weights: readonly number[], laneIndex: number): bigint;
16
+ export declare function loadEngineV2TrafficMixOwnedUnits(globalUnitCount: bigint, weights: readonly number[], laneIndex: number, shardIndex: number, shardCount: number): LoadEngineV2TrafficMixUnit[];
17
+ export type LoadEngineV2ArrivalDecision = "wait" | "start" | "scheduler_late" | "max_in_flight";
18
+ export interface LoadStrikeHistogramV1Sidecar {
19
+ schemaVersion: "loadstrike.histogram/1";
20
+ mode: "exact-normalized" | "quantized-v1";
21
+ count64: string;
22
+ zeroCount64: string;
23
+ minimum64: string;
24
+ maximum64: string;
25
+ origin64: string;
26
+ meanOffsetBits: string;
27
+ m2Bits: string;
28
+ exactTotal64: string;
29
+ exactSamples64: string[];
30
+ buckets: Array<{
31
+ bucketKey64: string;
32
+ count64: string;
33
+ }>;
34
+ }
35
+ export interface LoadEngineV2DistributionRecord {
36
+ seriesKind: "scenario" | "step" | "scheduler-decision-lag" | "scheduler-start-lag" | "correlation";
37
+ scenarioIndex64: string;
38
+ scenarioName: string;
39
+ identityKeyHex: string;
40
+ outcome: "ok" | "fail" | "all" | "none";
41
+ unit: "microseconds" | "bytes" | "count";
42
+ histogram: LoadStrikeHistogramV1Sidecar;
43
+ exactTotalDecimalOrEmpty?: string;
44
+ bands?: Array<{
45
+ bandId64: string;
46
+ count64: string;
47
+ }>;
48
+ }
49
+ export interface LoadEngineV2StatusSummaryRecord {
50
+ statusIdentityKeyHex: string;
51
+ display: string;
52
+ count64: string;
53
+ aggregatedObservationCount64: string;
54
+ hasAggregatedIdentities: boolean;
55
+ }
56
+ export interface LoadEngineV2MeasurementOutcomeSummary {
57
+ outcome: "ok" | "fail";
58
+ statusObservationCount64: string;
59
+ statuses: LoadEngineV2StatusSummaryRecord[];
60
+ }
61
+ export interface LoadEngineV2MeasurementSummary {
62
+ seriesKind: "scenario" | "step";
63
+ scenarioIndex64: string;
64
+ scenarioName: string;
65
+ identityKeyHex: string;
66
+ display: string;
67
+ observationCount64: string;
68
+ successCount64: string;
69
+ failureCount64: string;
70
+ aggregatedObservationCount64: string;
71
+ hasAggregatedIdentities: boolean;
72
+ outcomes: [LoadEngineV2MeasurementOutcomeSummary, LoadEngineV2MeasurementOutcomeSummary];
73
+ }
74
+ export interface LoadEngineV2HistogramArtifact {
75
+ distributions: LoadEngineV2DistributionRecord[];
76
+ measurementSummaries: LoadEngineV2MeasurementSummary[];
77
+ }
78
+ export declare class LoadEngineV2ExecutionBudget {
79
+ readonly maxInFlight: number;
80
+ private currentValue;
81
+ private highWaterValue;
82
+ constructor(maxInFlight: number);
83
+ get current(): number;
84
+ get highWater(): number;
85
+ tryAcquire(): (() => void) | undefined;
86
+ }
87
+ /**
88
+ * Canonical bounded streaming histogram used by Load Engine V2.
89
+ *
90
+ * The first 2,048 normalized values remain exact. Larger streams are promoted
91
+ * into the portable quantized-v1 layout, whose 7,296 counters cover every
92
+ * non-negative signed 64-bit value with a maximum relative error of 1/128.
93
+ */
94
+ export declare class LoadStrikeHistogramV1 {
95
+ static readonly exactLimit = 2048;
96
+ static readonly bucketCount = 7296;
97
+ private exactSamples;
98
+ private buckets;
99
+ private countValue;
100
+ private minimumValue;
101
+ private maximumValue;
102
+ private originValue;
103
+ private meanOffsetValue;
104
+ private m2;
105
+ private exactTotalValue;
106
+ get count(): bigint;
107
+ get minimum(): bigint;
108
+ get maximum(): bigint;
109
+ get origin(): bigint;
110
+ get meanOffset(): number;
111
+ get mean(): number;
112
+ get populationStandardDeviation(): number;
113
+ get mode(): "exact-normalized" | "quantized-v1";
114
+ get maxRelativeError(): number;
115
+ get retainedValueCount(): number;
116
+ get exactTotal(): bigint;
117
+ toSidecar(): LoadStrikeHistogramV1Sidecar;
118
+ static fromSidecar(sidecar: LoadStrikeHistogramV1Sidecar): LoadStrikeHistogramV1;
119
+ record(input: bigint): void;
120
+ clone(): LoadStrikeHistogramV1;
121
+ merge(other: LoadStrikeHistogramV1): void;
122
+ percentile(percentile: number): bigint;
123
+ private updateMoments;
124
+ private promote;
125
+ private addBucket;
126
+ private copyFrom;
127
+ private static bucketIndex;
128
+ private static bucketUpperBound;
129
+ private static bucketKeyFromIndex;
130
+ private static bucketIndexFromKey;
131
+ }
132
+ /** Serializes the canonical cumulative LoadStrikeHistogramArtifactV1 (`LS-H1`). */
133
+ export declare function serializeLoadEngineV2HistogramArtifact(artifact: LoadEngineV2HistogramArtifact): Buffer;
134
+ /** Strictly parses, validates, and canonical-byte checks an `LS-H1` artifact. */
135
+ export declare function parseLoadEngineV2HistogramArtifact(bytes: Uint8Array): LoadEngineV2HistogramArtifact;
136
+ export declare function createDefaultLoadEngineV2Settings(): LoadEngineV2Settings;
137
+ export declare function fnv1a32(value: string): number;
138
+ export declare function planFixedDeadlines(rate: number, intervalNs: bigint, durationNs: bigint): bigint[];
139
+ export declare function planFixedIterationDeadlines(rate: number, intervalNs: bigint, iterations: number): bigint[];
140
+ export declare function planRampingInjectionDeadlines(rate: number, intervalNs: bigint, durationNs: bigint): bigint[];
141
+ export declare function planRampingConstantDeadlines(copies: number, durationNs: bigint): bigint[];
142
+ export declare function planRandomInjectionDeadlines(minRate: number, maxRate: number, intervalNs: bigint, durationNs: bigint, seed: number): bigint[];
143
+ export declare function xorshift32(input: number): number;
144
+ export declare function loadEngineV2FixedDeadlineNs(ordinal: bigint, rate: number, intervalNs: bigint): bigint;
145
+ export declare function loadEngineV2FixedArrivalCount(rate: number, intervalNs: bigint, durationNs: bigint): bigint;
146
+ export declare function loadEngineV2LatenessToleranceNs(rate: number, intervalNs: bigint): bigint;
147
+ export declare function classifyLoadEngineV2Arrival(nowNs: bigint, deadlineNs: bigint, toleranceNs: bigint, permitAvailable: boolean): LoadEngineV2ArrivalDecision;