@gravito/ripple 4.0.0 → 4.0.1

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.
Files changed (91) hide show
  1. package/dist/atlas/src/DB.d.ts +51 -4
  2. package/dist/atlas/src/config/index.d.ts +1 -1
  3. package/dist/atlas/src/config/loadConfig.d.ts +0 -7
  4. package/dist/atlas/src/connection/Connection.d.ts +4 -0
  5. package/dist/atlas/src/connection/ConnectionManager.d.ts +75 -6
  6. package/dist/atlas/src/connection/ReplicaConnectionPool.d.ts +54 -0
  7. package/dist/atlas/src/drivers/MySQLDriver.d.ts +16 -3
  8. package/dist/atlas/src/drivers/PostgresDriver.d.ts +15 -2
  9. package/dist/atlas/src/index.d.ts +15 -3
  10. package/dist/atlas/src/observability/AtlasMetrics.d.ts +22 -0
  11. package/dist/atlas/src/orm/Repository.d.ts +247 -0
  12. package/dist/atlas/src/orm/index.d.ts +1 -0
  13. package/dist/atlas/src/orm/model/Model.d.ts +11 -2
  14. package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +14 -0
  15. package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +5 -0
  16. package/dist/atlas/src/orm/model/decorators.d.ts +29 -0
  17. package/dist/atlas/src/orm/model/index.d.ts +1 -1
  18. package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +1 -0
  19. package/dist/atlas/src/pool/AdaptivePoolManager.d.ts +98 -0
  20. package/dist/atlas/src/pool/PoolHealthChecker.d.ts +91 -0
  21. package/dist/atlas/src/pool/PoolStrategy.d.ts +129 -0
  22. package/dist/atlas/src/pool/PoolWarmer.d.ts +92 -0
  23. package/dist/atlas/src/query/QueryBuilder.d.ts +71 -1
  24. package/dist/atlas/src/query/RelationshipResolver.d.ts +23 -0
  25. package/dist/atlas/src/schema/MigrationGenerator.d.ts +45 -0
  26. package/dist/atlas/src/schema/SchemaDiff.d.ts +73 -0
  27. package/dist/atlas/src/schema/TypeGenerator.d.ts +57 -0
  28. package/dist/atlas/src/schema/TypeWriter.d.ts +42 -0
  29. package/dist/atlas/src/sharding/ShardingManager.d.ts +59 -0
  30. package/dist/atlas/src/types/index.d.ts +83 -1
  31. package/dist/atlas/src/utils/CursorEncoding.d.ts +63 -0
  32. package/dist/core/src/ConfigManager.d.ts +39 -0
  33. package/dist/core/src/Container/RequestScopeManager.d.ts +62 -0
  34. package/dist/core/src/Container/RequestScopeMetrics.d.ts +144 -0
  35. package/dist/core/src/Container.d.ts +45 -0
  36. package/dist/core/src/ErrorHandler.d.ts +3 -0
  37. package/dist/core/src/HookManager.d.ts +95 -0
  38. package/dist/core/src/PlanetCore.d.ts +89 -0
  39. package/dist/core/src/RequestContext.d.ts +97 -0
  40. package/dist/core/src/ServiceProvider.d.ts +22 -0
  41. package/dist/core/src/adapters/PhotonAdapter.d.ts +4 -0
  42. package/dist/core/src/adapters/bun/BunContext.d.ts +4 -0
  43. package/dist/core/src/cli/queue-commands.d.ts +6 -0
  44. package/dist/core/src/engine/AOTRouter.d.ts +6 -1
  45. package/dist/core/src/engine/FastContext.d.ts +23 -0
  46. package/dist/core/src/engine/Gravito.d.ts +0 -1
  47. package/dist/core/src/engine/MinimalContext.d.ts +21 -0
  48. package/dist/core/src/engine/types.d.ts +3 -0
  49. package/dist/core/src/error-handling/RequestScopeErrorContext.d.ts +126 -0
  50. package/dist/core/src/events/BackpressureManager.d.ts +215 -0
  51. package/dist/core/src/events/DeadLetterQueue.d.ts +75 -1
  52. package/dist/core/src/events/EventBackend.d.ts +2 -1
  53. package/dist/core/src/events/EventOptions.d.ts +99 -4
  54. package/dist/core/src/events/EventPriorityQueue.d.ts +105 -6
  55. package/dist/core/src/events/FlowControlStrategy.d.ts +109 -0
  56. package/dist/core/src/events/MessageQueueBridge.d.ts +184 -0
  57. package/dist/core/src/events/PriorityEscalationManager.d.ts +82 -0
  58. package/dist/core/src/events/RetryScheduler.d.ts +104 -0
  59. package/dist/core/src/events/WorkerPool.d.ts +98 -0
  60. package/dist/core/src/events/WorkerPoolConfig.d.ts +153 -0
  61. package/dist/core/src/events/WorkerPoolMetrics.d.ts +65 -0
  62. package/dist/core/src/events/aggregation/AggregationWindow.d.ts +77 -0
  63. package/dist/core/src/events/aggregation/DeduplicationManager.d.ts +135 -0
  64. package/dist/core/src/events/aggregation/EventAggregationManager.d.ts +108 -0
  65. package/dist/core/src/events/aggregation/EventBatcher.d.ts +99 -0
  66. package/dist/core/src/events/aggregation/types.d.ts +117 -0
  67. package/dist/core/src/events/index.d.ts +11 -0
  68. package/dist/core/src/events/observability/OTelEventMetrics.d.ts +92 -0
  69. package/dist/core/src/events/observability/StreamWorkerMetrics.d.ts +76 -0
  70. package/dist/core/src/events/observability/index.d.ts +4 -0
  71. package/dist/core/src/events/types.d.ts +59 -0
  72. package/dist/core/src/health/HealthProvider.d.ts +67 -0
  73. package/dist/core/src/http/types.d.ts +19 -0
  74. package/dist/core/src/index.d.ts +13 -1
  75. package/dist/core/src/observability/Metrics.d.ts +244 -0
  76. package/dist/core/src/observability/QueueDashboard.d.ts +136 -0
  77. package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +34 -0
  78. package/dist/index.js +403 -40
  79. package/dist/index.js.map +11 -9
  80. package/dist/photon/src/index.d.ts +5 -0
  81. package/dist/photon/src/middleware/ratelimit-redis.d.ts +50 -0
  82. package/dist/photon/src/middleware/ratelimit.d.ts +4 -0
  83. package/dist/ripple/src/RippleServer.d.ts +0 -1
  84. package/dist/ripple/src/engines/UWebSocketsEngine.d.ts +97 -0
  85. package/dist/ripple/src/engines/WsEngine.d.ts +69 -0
  86. package/dist/ripple/src/engines/index.d.ts +4 -0
  87. package/dist/ripple/src/serializers/ISerializer.d.ts +1 -1
  88. package/dist/ripple/src/serializers/JsonSerializer.d.ts +1 -1
  89. package/dist/ripple/src/serializers/ProtobufSerializer.d.ts +6 -3
  90. package/dist/ripple/src/types.d.ts +11 -0
  91. package/package.json +3 -2
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Event aggregation manager (FS-102)
3
+ *
4
+ * Coordinates deduplication and batching for optimal event processing:
5
+ * - Event deduplication (pattern-based or idempotency-key based)
6
+ * - Micro-batching (time and size dual-trigger)
7
+ * - Backpressure-aware window adjustment
8
+ * - Complete statistics tracking
9
+ *
10
+ * Ported from: examples/flash-sale-fullstack/src/cache/events/EventAggregator.ts
11
+ */
12
+ import type { BackpressureManager } from '../BackpressureManager';
13
+ import type { EventTask } from '../types';
14
+ import { AggregationWindow } from './AggregationWindow';
15
+ import { DeduplicationManager } from './DeduplicationManager';
16
+ import { EventBatcher } from './EventBatcher';
17
+ import type { AggregationConfig, AggregationStats } from './types';
18
+ /**
19
+ * Event aggregation manager.
20
+ */
21
+ export declare class EventAggregationManager {
22
+ private deduplicator;
23
+ private batcher;
24
+ private window;
25
+ private config;
26
+ private backpressureManager?;
27
+ private submitToQueueFn?;
28
+ private disabled;
29
+ /**
30
+ * Create an event aggregation manager.
31
+ */
32
+ constructor(config?: Partial<AggregationConfig>);
33
+ /**
34
+ * Set backpressure manager for window adjustment.
35
+ * FS-103:Also sets BackpressureManager on AggregationWindow for feedback loop.
36
+ */
37
+ setBackpressureManager(backpressure: BackpressureManager): void;
38
+ /**
39
+ * Set the actual queue submission function.
40
+ */
41
+ setSubmitToQueueFn(fn: (tasks: EventTask[]) => Promise<void>): void;
42
+ /**
43
+ * Submit an event for aggregation.
44
+ *
45
+ * Returns true if accepted, false if rejected due to backpressure.
46
+ */
47
+ submit(task: EventTask): Promise<boolean>;
48
+ /**
49
+ * Submit multiple events.
50
+ */
51
+ submitBatch(tasks: EventTask[]): Promise<number>;
52
+ /**
53
+ * Flush current batch to queue.
54
+ */
55
+ flush(): Promise<EventTask[]>;
56
+ /**
57
+ * Get aggregation statistics.
58
+ */
59
+ getStats(): AggregationStats;
60
+ /**
61
+ * Reset statistics.
62
+ */
63
+ resetStats(): void;
64
+ /**
65
+ * Clear aggregation state.
66
+ */
67
+ clear(): void;
68
+ /**
69
+ * Check if there are pending events.
70
+ */
71
+ hasPending(): boolean;
72
+ /**
73
+ * Get pending event count.
74
+ */
75
+ getPendingCount(): number;
76
+ /**
77
+ * Disable the aggregation manager.
78
+ */
79
+ disable(): void;
80
+ /**
81
+ * Enable the aggregation manager.
82
+ */
83
+ enable(): void;
84
+ /**
85
+ * Check if aggregation manager is enabled.
86
+ */
87
+ isEnabled(): boolean;
88
+ /**
89
+ * Shutdown the aggregation manager.
90
+ */
91
+ shutdown(): Promise<EventTask[]>;
92
+ /**
93
+ * Submit deduplicated events to queue.
94
+ */
95
+ private submitToQueue;
96
+ /**
97
+ * Get deduplication manager (for testing).
98
+ */
99
+ __getDeduplicator(): DeduplicationManager;
100
+ /**
101
+ * Get event batcher (for testing).
102
+ */
103
+ __getBatcher(): EventBatcher;
104
+ /**
105
+ * Get aggregation window (for testing).
106
+ */
107
+ __getWindow(): AggregationWindow;
108
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Event batcher for microbatching optimization (FS-102)
3
+ *
4
+ * Implements dual-trigger batching:
5
+ * - Time window trigger (default 50ms)
6
+ * - Batch size trigger (default 50 events)
7
+ *
8
+ * Expected improvements: 10-15% throughput increase
9
+ *
10
+ * Ported from: examples/flash-sale-fullstack/src/cache/events/BatchSubmitter.ts
11
+ */
12
+ import type { EventTask } from '../types';
13
+ import type { BatchStats } from './types';
14
+ /**
15
+ * Event batcher for optimizing submission throughput.
16
+ */
17
+ export declare class EventBatcher {
18
+ private queue;
19
+ private readonly batchSize;
20
+ private readonly flushIntervalMs;
21
+ private flushTimer;
22
+ private stats;
23
+ private submitFn;
24
+ /**
25
+ * Create an event batcher.
26
+ *
27
+ * @param batchSize - Batch size threshold (default 50)
28
+ * @param flushIntervalMs - Time window (ms, default 50)
29
+ * @param submitFn - Function to submit batches
30
+ */
31
+ constructor(batchSize: number | undefined, flushIntervalMs: number | undefined, submitFn: (tasks: EventTask[]) => Promise<void>);
32
+ /**
33
+ * Enqueue an event.
34
+ *
35
+ * Automatically triggers flush if:
36
+ * 1. Batch size is reached
37
+ * 2. Time window expires
38
+ */
39
+ enqueue(task: EventTask): Promise<void>;
40
+ /**
41
+ * Enqueue multiple events.
42
+ */
43
+ enqueueBatch(tasks: EventTask[]): Promise<void>;
44
+ /**
45
+ * Flush queued events.
46
+ *
47
+ * @param auto - Whether this is an auto-triggered flush
48
+ * @returns Array of flushed events
49
+ */
50
+ flush(auto?: boolean): Promise<EventTask[]>;
51
+ /**
52
+ * Get statistics.
53
+ */
54
+ getStats(): BatchStats;
55
+ /**
56
+ * Get pending event count.
57
+ */
58
+ getPendingCount(): number;
59
+ /**
60
+ * Check if there are pending events.
61
+ */
62
+ hasPending(): boolean;
63
+ /**
64
+ * Clear the queue.
65
+ */
66
+ clear(): void;
67
+ /**
68
+ * Reset statistics.
69
+ */
70
+ resetStats(): void;
71
+ /**
72
+ * Stop the batcher and flush remaining events.
73
+ */
74
+ stop(): Promise<EventTask[]>;
75
+ /**
76
+ * Start time-window timer.
77
+ */
78
+ private startTimer;
79
+ /**
80
+ * Clear timer.
81
+ */
82
+ private clearTimer;
83
+ /**
84
+ * Adjust batch size.
85
+ */
86
+ setBatchSize(newSize: number): void;
87
+ /**
88
+ * Adjust flush interval.
89
+ */
90
+ setFlushInterval(_newIntervalMs: number): void;
91
+ /**
92
+ * Get batch size.
93
+ */
94
+ getBatchSize(): number;
95
+ /**
96
+ * Get flush interval.
97
+ */
98
+ getFlushInterval(): number;
99
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Event aggregation and deduplication types (FS-102)
3
+ * @internal
4
+ */
5
+ import { BackpressureState } from '../BackpressureManager';
6
+ /**
7
+ * Deduplication statistics.
8
+ */
9
+ export interface DeduplicationStats {
10
+ /** Total events submitted */
11
+ totalEvents: number;
12
+ /** Events after deduplication */
13
+ deduplicatedEvents: number;
14
+ /** Events removed by deduplication */
15
+ removedCount: number;
16
+ /** Number of patterns aggregated */
17
+ patternsAggregated: number;
18
+ /** Deduplication rate (%) */
19
+ deduplicationRate: number;
20
+ }
21
+ /**
22
+ * Batch submission statistics.
23
+ */
24
+ export interface BatchStats {
25
+ /** Total batches submitted */
26
+ totalBatches: number;
27
+ /** Total events submitted */
28
+ totalEvents: number;
29
+ /** Average batch size */
30
+ averageBatchSize: number;
31
+ /** Average batch latency (ms) */
32
+ averageBatchLatency: number;
33
+ /** Last flush timestamp */
34
+ lastFlushTime: number;
35
+ /** Pending events in queue */
36
+ pendingEvents: number;
37
+ /** Auto-triggered flushes */
38
+ autoFlushCount: number;
39
+ /** Manual flushes */
40
+ manualFlushCount: number;
41
+ }
42
+ /**
43
+ * Aggregation window statistics.
44
+ */
45
+ export interface WindowStats {
46
+ /** Current window size (ms) */
47
+ currentWindowMs: number;
48
+ /** Minimum window size (ms) */
49
+ minWindowMs: number;
50
+ /** Maximum window size (ms) */
51
+ maxWindowMs: number;
52
+ /** Last window adjustment reason */
53
+ lastAdjustmentReason?: string;
54
+ /** Window adjustment count */
55
+ adjustmentCount: number;
56
+ }
57
+ /**
58
+ * Complete aggregation statistics.
59
+ */
60
+ export interface AggregationStats {
61
+ deduplication: DeduplicationStats;
62
+ batching: BatchStats;
63
+ window: WindowStats;
64
+ timestamp: number;
65
+ }
66
+ /**
67
+ * Aggregation configuration options.
68
+ */
69
+ export interface AggregationConfig {
70
+ /** Enable aggregation (default: false) */
71
+ enabled: boolean;
72
+ /** Window size in milliseconds (default: 200) */
73
+ windowMs?: number;
74
+ /** Batch size threshold (default: 50) */
75
+ batchSize?: number;
76
+ /** Deduplication strategy */
77
+ deduplication?: 'pattern' | 'idempotencyKey' | 'off';
78
+ /** Deduplication pattern (string or function) */
79
+ pattern?: string | ((args: unknown) => string);
80
+ /** Merge priority when deduplicating */
81
+ mergePriority?: 'highest' | 'earliest' | 'latest';
82
+ /** Enable background cleanup (default: true) */
83
+ enableCleanup?: boolean;
84
+ /** Cleanup interval (ms, default: 5 minutes) */
85
+ cleanupIntervalMs?: number;
86
+ /** TTL for deduplication entries (ms, default: 10 minutes) */
87
+ ttlMs?: number;
88
+ }
89
+ /**
90
+ * Default aggregation configuration.
91
+ */
92
+ export declare const DEFAULT_AGGREGATION_CONFIG: Required<AggregationConfig>;
93
+ /**
94
+ * Priority order for merge decisions.
95
+ */
96
+ export declare const PRIORITY_ORDER: Record<string, number>;
97
+ /**
98
+ * Backpressure-aware window configuration.
99
+ */
100
+ export interface WindowAdjustmentConfig {
101
+ /** Window for NORMAL backpressure state */
102
+ normalMs: number;
103
+ /** Window for WARNING backpressure state */
104
+ warningMs: number;
105
+ /** Window for CRITICAL backpressure state */
106
+ criticalMs: number;
107
+ /** Window for OVERFLOW backpressure state */
108
+ overflowMs: number;
109
+ }
110
+ /**
111
+ * Default window adjustment configuration based on backpressure.
112
+ */
113
+ export declare const DEFAULT_WINDOW_ADJUSTMENT: WindowAdjustmentConfig;
114
+ /**
115
+ * Get suggested window size based on backpressure state.
116
+ */
117
+ export declare function getSuggestedWindow(state: BackpressureState, config?: WindowAdjustmentConfig): number;
@@ -2,6 +2,8 @@
2
2
  * Event system exports for async event dispatch.
3
3
  * @packageDocumentation
4
4
  */
5
+ export type { BackpressureConfig, BackpressureDecision, BackpressureMetricsSnapshot, } from './BackpressureManager';
6
+ export { BackpressureManager, BackpressureState } from './BackpressureManager';
5
7
  export type { CircuitBreakerOptions } from './CircuitBreaker';
6
8
  export { CircuitBreaker, CircuitBreakerState } from './CircuitBreaker';
7
9
  export type { DLQEntry, DLQFilter } from './DeadLetterQueue';
@@ -10,5 +12,14 @@ export * from './EventBackend';
10
12
  export type { EventOptions } from './EventOptions';
11
13
  export { DEFAULT_EVENT_OPTIONS } from './EventOptions';
12
14
  export { EventPriorityQueue } from './EventPriorityQueue';
15
+ export type { FlowControlContext, FlowControlStrategy } from './FlowControlStrategy';
16
+ export { CompositeStrategy, createDefaultStrategies, PriorityRebalanceStrategy, QueueDepthStrategy, RateLimitStrategy, StarvationProtectionStrategy, } from './FlowControlStrategy';
17
+ export type { EventStatus, MessageQueueBridgeConfig } from './MessageQueueBridge';
18
+ export { MessageQueueBridge } from './MessageQueueBridge';
13
19
  export * from './observability';
20
+ export type { QueueStats, RetrySchedulerConfig } from './RetryScheduler';
21
+ export { RetryScheduler } from './RetryScheduler';
14
22
  export type { BackpressureStrategy, EventQueueConfig, EventTask } from './types';
23
+ export { WorkerPool } from './WorkerPool';
24
+ export type { WorkerPoolConfig, WorkerPoolStats, WorkerStats } from './WorkerPoolConfig';
25
+ export { WorkerPoolMetrics } from './WorkerPoolMetrics';
@@ -18,6 +18,7 @@ import type { CircuitBreakerMetricsRecorder } from '../CircuitBreaker';
18
18
  * Returns the current queue depths for each priority level.
19
19
  */
20
20
  export type QueueDepthCallback = () => {
21
+ critical: number;
21
22
  high: number;
22
23
  normal: number;
23
24
  low: number;
@@ -72,6 +73,16 @@ export declare class OTelEventMetrics implements CircuitBreakerMetricsRecorder {
72
73
  private readonly cbSuccessesCounter;
73
74
  private readonly cbTransitionsCounter;
74
75
  private readonly cbOpenDurationHistogram;
76
+ private readonly backpressureRejectionsCounter;
77
+ private readonly backpressureStateGauge;
78
+ private readonly backpressureDegradationsCounter;
79
+ private backpressureStateValue;
80
+ private readonly dlqEntriesCounter;
81
+ private readonly dlqDepthGauge;
82
+ private readonly dlqRequeueCounter;
83
+ private readonly retryAttemptsCounter;
84
+ private dlqDepthCallback?;
85
+ private readonly priorityEscalationCounter;
75
86
  private queueDepthCallback?;
76
87
  private circuitBreakerStateCallbacks;
77
88
  private recordedCircuitBreakerStates;
@@ -237,4 +248,85 @@ export declare class OTelEventMetrics implements CircuitBreakerMetricsRecorder {
237
248
  * Clear all circuit breaker state callbacks.
238
249
  */
239
250
  clearCircuitBreakerCallbacks(): void;
251
+ /**
252
+ * Record a backpressure rejection event.
253
+ *
254
+ * @param eventName - Event name
255
+ * @param priority - Event priority
256
+ * @param reason - Rejection reason
257
+ */
258
+ recordBackpressureRejection(eventName: string, priority: string, reason: string): void;
259
+ /**
260
+ * Record a backpressure state change event.
261
+ *
262
+ * @param state - New backpressure state (NORMAL, WARNING, CRITICAL, OVERFLOW)
263
+ */
264
+ recordBackpressureState(state: string): void;
265
+ /**
266
+ * Record a backpressure degradation event.
267
+ *
268
+ * @param eventName - Event name
269
+ * @param fromPriority - Original priority
270
+ * @param toPriority - Degraded priority
271
+ */
272
+ recordBackpressureDegradation(eventName: string, fromPriority: string, toPriority: string): void;
273
+ /**
274
+ * Record an event added to Dead Letter Queue.
275
+ *
276
+ * @param eventName - Event name
277
+ * @param source - Source of DLQ entry (retry_exhausted, circuit_breaker, backpressure_overflow)
278
+ */
279
+ recordDLQEntry(eventName: string, source: string): void;
280
+ /**
281
+ * Set the callback for DLQ depth observable gauge.
282
+ *
283
+ * @param callback - Function returning current DLQ depth
284
+ */
285
+ setDLQDepthCallback(callback: () => number): void;
286
+ /**
287
+ * Record a DLQ requeue attempt.
288
+ *
289
+ * @param eventName - Event name
290
+ * @param result - Result of requeue (success or failure)
291
+ */
292
+ recordDLQRequeue(eventName: string, result: 'success' | 'failure'): void;
293
+ /**
294
+ * Record an event retry attempt.
295
+ *
296
+ * @param eventName - Event name
297
+ * @param attemptNumber - Attempt number
298
+ */
299
+ recordRetryAttempt(eventName: string, attemptNumber: number): void;
300
+ /**
301
+ * Record a priority escalation event.
302
+ *
303
+ * @param eventName - Event name
304
+ * @param fromPriority - Original priority
305
+ * @param toPriority - Escalated priority
306
+ */
307
+ recordPriorityEscalation(eventName: string, fromPriority: string, toPriority: string): void;
308
+ /**
309
+ * Record event deduplication (FS-102).
310
+ *
311
+ * @param eventName - Event name
312
+ * @param deduplicatedCount - Number of events after deduplication
313
+ * @param totalCount - Total number of events before deduplication
314
+ */
315
+ recordDeduplication(eventName: string, deduplicatedCount: number, totalCount: number): void;
316
+ /**
317
+ * Record batch submission (FS-102).
318
+ *
319
+ * @param eventName - Event name
320
+ * @param batchSize - Size of submitted batch
321
+ * @param windowMs - Aggregation window size
322
+ */
323
+ recordBatch(eventName: string, batchSize: number, windowMs: number): void;
324
+ /**
325
+ * Record window adjustment (FS-102).
326
+ *
327
+ * @param oldWindowMs - Previous window size
328
+ * @param newWindowMs - New window size
329
+ * @param reason - Adjustment reason
330
+ */
331
+ recordWindowAdjustment(oldWindowMs: number, newWindowMs: number, reason: string): void;
240
332
  }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Worker Pool Metrics Recorder for OpenTelemetry integration.
3
+ *
4
+ * Tracks Worker Pool statistics and emits OpenTelemetry metrics.
5
+ *
6
+ * @internal
7
+ */
8
+ import type { Meter } from '@opentelemetry/api';
9
+ /**
10
+ * Worker job status for metrics.
11
+ */
12
+ export declare enum WorkerJobStatus {
13
+ COMPLETED = "completed",
14
+ FAILED = "failed"
15
+ }
16
+ /**
17
+ * Stream Worker Metrics Recorder.
18
+ *
19
+ * Collects and records metrics related to Worker Pool execution:
20
+ * - Pool size and utilization
21
+ * - Job execution duration
22
+ * - Job success/failure counts
23
+ * - Queue depth
24
+ */
25
+ export declare class StreamWorkerMetrics {
26
+ private meter;
27
+ private jobDurationHistogram?;
28
+ private jobCounterCompleted?;
29
+ constructor(meter: Meter);
30
+ /**
31
+ * Initialize OpenTelemetry metrics.
32
+ */
33
+ private initializeMetrics;
34
+ /**
35
+ * Record job execution duration.
36
+ *
37
+ * @param durationSeconds - Duration in seconds
38
+ * @param status - Job status (completed or failed)
39
+ * @param queue - Queue name
40
+ */
41
+ recordJobDuration(durationSeconds: number, status: WorkerJobStatus, queue?: string): void;
42
+ /**
43
+ * Record pool size change.
44
+ *
45
+ * @param poolSize - Current pool size
46
+ * @param callback - Optional callback to fetch pool size dynamically
47
+ */
48
+ setPoolSizeProvider(callback: () => number): void;
49
+ private poolSizeCallback?;
50
+ /**
51
+ * Get current pool size.
52
+ */
53
+ getPoolSize(): number;
54
+ /**
55
+ * Record queue depth change.
56
+ *
57
+ * @param depth - Current queue depth
58
+ * @param callback - Optional callback to fetch queue depth dynamically
59
+ */
60
+ setQueueDepthProvider(callback: () => number): void;
61
+ private queueDepthCallback?;
62
+ /**
63
+ * Get current queue depth.
64
+ */
65
+ getQueueDepth(): number;
66
+ }
67
+ /**
68
+ * Worker Metrics Recorder interface for dependency injection.
69
+ */
70
+ export interface WorkerMetricsRecorder {
71
+ recordJobDuration(durationSeconds: number, status: WorkerJobStatus, queue?: string): void;
72
+ setPoolSizeProvider(callback: () => number): void;
73
+ setQueueDepthProvider(callback: () => number): void;
74
+ getPoolSize(): number;
75
+ getQueueDepth(): number;
76
+ }
@@ -18,3 +18,7 @@ export { type ObservabilityConfig, ObservableHookManager } from './ObservableHoo
18
18
  * @public
19
19
  */
20
20
  export { OTelEventMetrics, type QueueDepthCallback } from './OTelEventMetrics';
21
+ /**
22
+ * @public
23
+ */
24
+ export { StreamWorkerMetrics, WorkerJobStatus, type WorkerMetricsRecorder, } from './StreamWorkerMetrics';
@@ -1,4 +1,5 @@
1
1
  import type { ActionCallback } from '../HookManager';
2
+ import type { BackpressureConfig } from './BackpressureManager';
2
3
  import type { EventOptions } from './EventOptions';
3
4
  /**
4
5
  * Event task for priority queue processing.
@@ -29,6 +30,12 @@ export interface EventTask {
29
30
  * Timestamp when the event was created.
30
31
  */
31
32
  createdAt: number;
33
+ /**
34
+ * Timestamp when the event was enqueued (added to the queue).
35
+ * Used for priority escalation calculations.
36
+ * @internal
37
+ */
38
+ enqueuedAt: number;
32
39
  /**
33
40
  * Partition key for ordering (if applicable).
34
41
  */
@@ -72,4 +79,56 @@ export interface EventQueueConfig {
72
79
  * @default 'reject'
73
80
  */
74
81
  strategy?: BackpressureStrategy;
82
+ /**
83
+ * Advanced backpressure management configuration.
84
+ * When enabled, provides state-based flow control with multi-strategy support.
85
+ * If not provided, falls back to simple strategy-based backpressure.
86
+ * @default undefined (disabled, uses simple strategy)
87
+ */
88
+ backpressure?: BackpressureConfig;
89
+ }
90
+ /**
91
+ * Multi-priority queue depth snapshot (FS-103)
92
+ * Represents the current queue depth for each priority level.
93
+ * @internal
94
+ */
95
+ export interface MultiPriorityQueueDepth {
96
+ /** Queue depth for CRITICAL priority events */
97
+ critical: number;
98
+ /** Queue depth for HIGH priority events */
99
+ high: number;
100
+ /** Queue depth for NORMAL priority events */
101
+ normal: number;
102
+ /** Queue depth for LOW priority events */
103
+ low: number;
104
+ /** Total queue depth across all priorities */
105
+ total: number;
106
+ }
107
+ /**
108
+ * Window adjustment record for backpressure feedback (FS-103)
109
+ * Records when and why the aggregation window was adjusted.
110
+ * @internal
111
+ */
112
+ export interface WindowAdjustment {
113
+ /** Timestamp of the adjustment */
114
+ timestamp: number;
115
+ /** Previous window size in milliseconds */
116
+ from: number;
117
+ /** New window size in milliseconds */
118
+ to: number;
119
+ /** Backpressure state that triggered the adjustment */
120
+ reason: string;
121
+ }
122
+ /**
123
+ * Dead letter queue routing decision (FS-103)
124
+ * Determines whether an event should be routed to the DLQ.
125
+ * @internal
126
+ */
127
+ export interface DeadLetterDecision {
128
+ /** Whether the event should be routed to DLQ */
129
+ shouldRoute: boolean;
130
+ /** Reason for the decision (if applicable) */
131
+ reason?: string;
132
+ /** Suggested retry strategy */
133
+ retryStrategy?: 'immediate' | 'delayed' | 'dlq-only';
75
134
  }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @fileoverview HealthProvider - Cloud-native health checks
3
+ *
4
+ * Provides liveness and readiness probes for Kubernetes and cloud deployments
5
+ *
6
+ * @module @gravito/core/health
7
+ * @since 2.2.0
8
+ */
9
+ import type { Container } from '../Container';
10
+ import type { PlanetCore } from '../PlanetCore';
11
+ import { ServiceProvider } from '../ServiceProvider';
12
+ /**
13
+ * Health check result
14
+ * @public
15
+ */
16
+ export interface HealthCheckResult {
17
+ /** Health status */
18
+ status: 'healthy' | 'unhealthy';
19
+ /** Optional message */
20
+ message?: string;
21
+ }
22
+ /**
23
+ * Health check function interface
24
+ * @public
25
+ */
26
+ export interface HealthCheck {
27
+ /** Unique name for this check */
28
+ name: string;
29
+ /** Check function that returns health status */
30
+ check(): Promise<HealthCheckResult>;
31
+ }
32
+ /**
33
+ * HealthProvider - Provides /health/liveness and /health/readiness endpoints
34
+ *
35
+ * - Liveness: Always returns 200 OK (just checks if server is running)
36
+ * - Readiness: Returns 200 if all checks are healthy, 503 otherwise
37
+ *
38
+ * @public
39
+ */
40
+ export declare class HealthProvider extends ServiceProvider {
41
+ private checks;
42
+ register(container: Container): void;
43
+ /**
44
+ * Register a health check
45
+ *
46
+ * @param check - The health check to register
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const health = core.container.make<HealthProvider>('health')
51
+ * health.registerCheck({
52
+ * name: 'database',
53
+ * check: async () => {
54
+ * try {
55
+ * await db.ping()
56
+ * return { status: 'healthy' }
57
+ * } catch {
58
+ * return { status: 'unhealthy', message: 'DB unreachable' }
59
+ * }
60
+ * }
61
+ * })
62
+ * ```
63
+ */
64
+ registerCheck(check: HealthCheck): void;
65
+ boot(core: PlanetCore): void;
66
+ }
67
+ export default HealthProvider;