Skip to content

Commit ed75bc1

Browse files
committed
feat: edit rpc_relay_eth_executions and rpc_websocket_connection_duration_seconds_bucket metrics (#3860)
Signed-off-by: nikolay <[email protected]>
1 parent 07893b0 commit ed75bc1

File tree

8 files changed

+8
-52
lines changed

8 files changed

+8
-52
lines changed

packages/relay/src/lib/eth.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,6 @@ export class EthImpl implements Eth {
268268
if (callDataSize >= constants.FUNCTION_SELECTOR_CHAR_LENGTH) {
269269
this.eventEmitter.emit(constants.EVENTS.ETH_EXECUTION, {
270270
method: constants.ETH_ESTIMATE_GAS,
271-
functionSelector: callData!.substring(0, constants.FUNCTION_SELECTOR_CHAR_LENGTH),
272-
from: transaction.from || '',
273-
to: transaction.to || '',
274271
requestDetails: requestDetails,
275272
});
276273
}
@@ -986,9 +983,6 @@ export class EthImpl implements Eth {
986983

987984
this.eventEmitter.emit(constants.EVENTS.ETH_EXECUTION, {
988985
method: 'eth_call',
989-
functionSelector: callData?.substring(0, constants.FUNCTION_SELECTOR_CHAR_LENGTH) || '',
990-
from: call.from || '',
991-
to: call.to || '',
992986
requestDetails: requestDetails,
993987
});
994988

packages/relay/src/lib/services/ethService/transactionService/TransactionService.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,22 +331,11 @@ export class TransactionService implements ITransactionService {
331331

332332
/**
333333
* Emits an Ethereum execution event with transaction details
334-
* @param parsedTx The parsed transaction object
335-
* @param originalCallerAddress The address of the original caller
336-
* @param toAddress The destination address
337334
* @param requestDetails The request details for logging and tracking
338335
*/
339-
private emitEthExecutionEvent(
340-
parsedTx: EthersTransaction,
341-
originalCallerAddress: string,
342-
toAddress: string,
343-
requestDetails: RequestDetails,
344-
): void {
336+
private emitEthExecutionEvent(requestDetails: RequestDetails): void {
345337
this.eventEmitter.emit(constants.EVENTS.ETH_EXECUTION, {
346338
method: constants.ETH_SEND_RAW_TRANSACTION,
347-
functionSelector: parsedTx.data?.substring(0, constants.FUNCTION_SELECTOR_CHAR_LENGTH) || '',
348-
from: originalCallerAddress,
349-
to: toAddress,
350339
requestDetails: requestDetails,
351340
});
352341
}
@@ -560,9 +549,8 @@ export class TransactionService implements ITransactionService {
560549

561550
const requestIdPrefix = requestDetails.formattedRequestId;
562551
const originalCallerAddress = parsedTx.from?.toString() || '';
563-
const toAddress = parsedTx.to?.toString() || '';
564552

565-
this.emitEthExecutionEvent(parsedTx, originalCallerAddress, toAddress, requestDetails);
553+
this.emitEthExecutionEvent(requestDetails);
566554

567555
const { txSubmitted, submittedTransactionId, error } = await this.submitTransaction(
568556
transactionBuffer,

packages/relay/src/lib/services/metricService/metricService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default class MetricService {
117117
});
118118

119119
this.eventEmitter.on(constants.EVENTS.ETH_EXECUTION, (args: IEthExecutionEventPayload) => {
120-
this.ethExecutionsCounter.labels(args.method, args.functionSelector, args.from, args.to).inc();
120+
this.ethExecutionsCounter.labels(args.method).inc();
121121
});
122122
}
123123

@@ -262,7 +262,7 @@ export default class MetricService {
262262
return new Counter({
263263
name: metricCounterName,
264264
help: `Relay ${metricCounterName} function`,
265-
labelNames: ['method', 'function', 'from', 'to'],
265+
labelNames: ['method'],
266266
registers: [register],
267267
});
268268
}

packages/relay/src/lib/types/events.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,5 @@ export interface IExecuteQueryEventPayload {
2727

2828
export interface IEthExecutionEventPayload {
2929
method: string;
30-
functionSelector: string;
31-
from: string;
32-
to: string;
3330
requestDetails: RequestDetails;
3431
}

packages/relay/tests/lib/services/metricService/metricService.spec.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,9 @@ describe('Metric Service', function () {
322322

323323
describe('ethExecutionsCounter', () => {
324324
const mockedMethod = 'eth_sendRawTransaction';
325-
const mockedFunctionSelector = '0x12345678';
326-
const mockedFrom = '0x1234567890123456789012345678901234567890';
327-
const mockedTo = '0x0987654321098765432109876543210987654321';
328325

329326
const mockedEthExecutionEventPayload = {
330327
method: mockedMethod,
331-
functionSelector: mockedFunctionSelector,
332-
from: mockedFrom,
333-
to: mockedTo,
334328
requestDetails,
335329
};
336330

@@ -339,28 +333,15 @@ describe('Metric Service', function () {
339333
const counterBefore = await metricService['ethExecutionsCounter'].get();
340334

341335
// Find the initial value for our specific labels, or use 0 if not found
342-
const initialValue =
343-
counterBefore.values.find(
344-
(metric) =>
345-
metric.labels.method === mockedMethod &&
346-
metric.labels.function === mockedFunctionSelector &&
347-
metric.labels.from === mockedFrom &&
348-
metric.labels.to === mockedTo,
349-
)?.value || 0;
336+
const initialValue = counterBefore.values.find((metric) => metric.labels.method === mockedMethod)?.value || 0;
350337

351338
eventEmitter.emit(constants.EVENTS.ETH_EXECUTION, mockedEthExecutionEventPayload);
352339

353340
// Get the counter after emitting the event
354341
const counterAfter = await metricService['ethExecutionsCounter'].get();
355342

356343
// Find the value for our specific labels after the event
357-
const metricValue = counterAfter.values.find(
358-
(metric) =>
359-
metric.labels.method === mockedMethod &&
360-
metric.labels.function === mockedFunctionSelector &&
361-
metric.labels.from === mockedFrom &&
362-
metric.labels.to === mockedTo,
363-
)?.value;
344+
const metricValue = counterAfter.values.find((metric) => metric.labels.method === mockedMethod)?.value;
364345

365346
expect(metricValue).to.eq(initialValue + 1);
366347
});

packages/ws-server/src/utils/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const WS_CONSTANTS = {
3636
connectionDuration: {
3737
name: 'rpc_websocket_connection_duration_seconds',
3838
help: 'Histogram of WebSocket connection duration in seconds',
39-
labelNames: ['connectionID'],
4039
buckets: [1, 5, 10, 30, 60, 300, 600, 1800, 3600, 7200, 18000, 43200, 86400], // s (seconds)
4140
},
4241
messageDuration: {

packages/ws-server/src/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const handleConnectionClose = async (
4848
const durationInSeconds = endTime[0] + endTime[1] / 1e9; // Convert duration to seconds
4949

5050
// Update the connection duration histogram with the calculated duration
51-
wsMetricRegistry.getHistogram('connectionDuration').labels(ctx.websocket.id).observe(durationInSeconds);
51+
wsMetricRegistry.getHistogram('connectionDuration').observe(durationInSeconds);
5252

5353
// terminate connection
5454
ctx.websocket.terminate();

packages/ws-server/tests/unit/utils.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,7 @@ describe('Utilities unit tests', async function () {
183183
});
184184

185185
it('should update the connection duration histogram', async () => {
186-
const labelsStub = wsMetricRegistryStub.getHistogram('connectionDuration').labels as sinon.SinonStub;
187-
const observeSpy = labelsStub().observe as sinon.SinonSpy;
188-
189-
expect(labelsStub.calledWith(ctxStub.websocket.id)).to.be.true;
186+
const observeSpy = wsMetricRegistryStub.getHistogram('connectionDuration').observe as sinon.SinonSpy;
190187
expect(observeSpy.calledOnce).to.be.true;
191188
});
192189

0 commit comments

Comments
 (0)