fix(metrics): fix metrics

This commit is contained in:
Juergen Kunz
2025-06-23 09:35:37 +00:00
parent 22418cd65e
commit 8df0333dc3
4 changed files with 251 additions and 4 deletions

View File

@ -123,6 +123,11 @@ export class HttpProxyBridge {
// Send initial chunk if present
if (initialChunk) {
// Count the initial chunk bytes
record.bytesReceived += initialChunk.length;
if (this.smartProxy.metricsCollector) {
this.smartProxy.metricsCollector.recordBytes(record.id, initialChunk.length, 0);
}
proxySocket.write(initialChunk);
}
@ -132,20 +137,18 @@ export class HttpProxyBridge {
setupBidirectionalForwarding(underlyingSocket, proxySocket, {
onClientData: (chunk) => {
// Update stats if needed
// Update stats - this is the ONLY place bytes are counted for HttpProxy connections
if (record) {
record.bytesReceived += chunk.length;
// Also record in metrics collector for throughput tracking
if (this.smartProxy.metricsCollector) {
this.smartProxy.metricsCollector.recordBytes(record.id, chunk.length, 0);
}
}
},
onServerData: (chunk) => {
// Update stats if needed
// Update stats - this is the ONLY place bytes are counted for HttpProxy connections
if (record) {
record.bytesSent += chunk.length;
// Also record in metrics collector for throughput tracking
if (this.smartProxy.metricsCollector) {
this.smartProxy.metricsCollector.recordBytes(record.id, 0, chunk.length);
}

View File

@ -347,6 +347,12 @@ export class RouteConnectionHandler {
}
const alert = Buffer.from([0x15, 0x03, 0x03, 0x00, 0x02, 0x01, 0x70]);
try {
// Count the alert bytes being sent
record.bytesSent += alert.length;
if (this.smartProxy.metricsCollector) {
this.smartProxy.metricsCollector.recordBytes(record.id, 0, alert.length);
}
socket.cork();
socket.write(alert);
socket.uncork();
@ -1208,6 +1214,9 @@ export class RouteConnectionHandler {
const proxyHeader = ProxyProtocolParser.generate(proxyInfo);
// Note: PROXY protocol headers are sent to the backend, not to the client
// They are internal protocol overhead and shouldn't be counted in client-facing metrics
// Send PROXY protocol header first
await new Promise<void>((resolve, reject) => {
targetSocket.write(proxyHeader, (err) => {