(now: number, maxQueueSize: number)
| 120 | }); |
| 121 | |
| 122 | const snapshot = (now: number, maxQueueSize: number) => { |
| 123 | let oldestConnectionAgeMs = 0; |
| 124 | let stalledConnections = 0; |
| 125 | let ageBuckets = emptyAgeBuckets(); |
| 126 | const colos = new Set<string>(); |
| 127 | const scriptVersions = new Set<string>(); |
| 128 | |
| 129 | for (const connection of activeSse.values()) { |
| 130 | const ageMs = now - connection.startedAt; |
| 131 | oldestConnectionAgeMs = Math.max(oldestConnectionAgeMs, ageMs); |
| 132 | if (now - connection.lastWriteAt > STALLED_WRITE_MS) stalledConnections += 1; |
| 133 | ageBuckets = bucketAge(ageBuckets, ageMs); |
| 134 | if (connection.colo) colos.add(connection.colo); |
| 135 | if (connection.scriptVersion) scriptVersions.add(connection.scriptVersion); |
| 136 | } |
| 137 | const sortedColos = Array.from(colos).sort(); |
| 138 | const sortedScriptVersions = Array.from(scriptVersions).sort(); |
| 139 | |
| 140 | return { |
| 141 | activeSseConnections: activeSse.size, |
| 142 | ageBuckets, |
| 143 | oldestConnectionAgeMs, |
| 144 | totalBytesForwarded, |
| 145 | stalledConnections, |
| 146 | stalledWriteThresholdMs: STALLED_WRITE_MS, |
| 147 | colo: sortedColos[0] ?? "", |
| 148 | colos: sortedColos, |
| 149 | scriptVersion: sortedScriptVersions[0] ?? "", |
| 150 | scriptVersions: sortedScriptVersions, |
| 151 | otel: otelSnapshot(maxQueueSize), |
| 152 | }; |
| 153 | }; |
| 154 | |
| 155 | const emitSnapshot = (event: string, now: number, maxQueueSize: number): void => { |
| 156 | lastSnapshotEmittedAt = now; |
no test coverage detected