From 2ff5dd3a3d44c1e08d7876618362e0c9779d7507 Mon Sep 17 00:00:00 2001 From: nikolay Date: Wed, 25 Jun 2025 12:08:42 +0300 Subject: [PATCH 1/3] chore: edit metrics Signed-off-by: nikolay --- .../services/metricService/metricService.ts | 24 +++++-------------- .../metricService/metricService.spec.ts | 6 ----- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/packages/relay/src/lib/services/metricService/metricService.ts b/packages/relay/src/lib/services/metricService/metricService.ts index 1bd1728de9..b4f99048c4 100644 --- a/packages/relay/src/lib/services/metricService/metricService.ts +++ b/packages/relay/src/lib/services/metricService/metricService.ts @@ -196,7 +196,6 @@ export default class MetricService { * @param {string} payload.callerName - The name of the entity calling the transaction. * @param {number} payload.cost - The cost of the transaction in tinybars. * @param {number} payload.gasUsed - The amount of gas used during the transaction. - * @param {string} payload.interactingEntity - The entity interacting with the transaction. * @param {string} payload.status - The entity interacting with the transaction. * @param {string} payload.requestDetails - The request details for logging and tracking. * @param {string | undefined} payload.originalCallerAddress - The address of the original caller making the request. @@ -209,7 +208,6 @@ export default class MetricService { callerName, cost, gasUsed, - interactingEntity, status, requestDetails, originalCallerAddress, @@ -221,7 +219,7 @@ export default class MetricService { } await this.hbarLimitService.addExpense(cost, originalCallerAddress ?? '', requestDetails); - this.captureMetrics(executionMode, txConstructorName, status, cost, gasUsed, callerName, interactingEntity); + this.captureMetrics(executionMode, txConstructorName, status, cost, gasUsed); }; /** @@ -235,7 +233,7 @@ export default class MetricService { return new Histogram({ name: metricHistogramCost, help: 'Relay consensusnode mode type status cost histogram', - labelNames: ['mode', 'type', 'status', 'caller', 'interactingEntity'], + labelNames: ['mode', 'type', 'status'], registers: [register], }); } @@ -251,7 +249,7 @@ export default class MetricService { return new Histogram({ name: metricHistogramGasFee, help: 'Relay consensusnode mode type status gas fee histogram', - labelNames: ['mode', 'type', 'status', 'caller', 'interactingEntity'], + labelNames: ['mode', 'type', 'status'], registers: [register], }); } @@ -275,21 +273,11 @@ export default class MetricService { * @param {string} status - The status of the transaction. * @param {number} cost - The cost of the transaction in tinybars. * @param {number} gas - The gas used by the transaction. - * @param {string} caller - The name of the caller executing the transaction. - * @param {string} interactingEntity - The entity interacting with the transaction. * @returns {void} */ - private captureMetrics = ( - mode: string, - type: string, - status: string, - cost: number, - gas: number, - caller: string, - interactingEntity: string, - ): void => { - this.consensusNodeClientHistogramCost.labels(mode, type, status, caller, interactingEntity).observe(cost); - this.consensusNodeClientHistogramGasFee.labels(mode, type, status, caller, interactingEntity).observe(gas); + private captureMetrics = (mode: string, type: string, status: string, cost: number, gas: number): void => { + this.consensusNodeClientHistogramCost.labels(mode, type, status).observe(cost); + this.consensusNodeClientHistogramGasFee.labels(mode, type, status).observe(gas); }; /** diff --git a/packages/relay/tests/lib/services/metricService/metricService.spec.ts b/packages/relay/tests/lib/services/metricService/metricService.spec.ts index 5f368ecf4f..77702ec14e 100644 --- a/packages/relay/tests/lib/services/metricService/metricService.spec.ts +++ b/packages/relay/tests/lib/services/metricService/metricService.spec.ts @@ -91,8 +91,6 @@ describe('Metric Service', function () { )!; expect(gasMetricObject.metricName).to.eq(metricHistogramGasFeeSumTitle); - expect(gasMetricObject.labels.caller).to.eq(mockedCallerName); - expect(gasMetricObject.labels.interactingEntity).to.eq(mockedInteractingEntity); expect(gasMetricObject.value).to.eq( mockedConsensusNodeTransactionRecord.contractFunctionResult?.gasUsed.toNumber(), ); @@ -108,8 +106,6 @@ describe('Metric Service', function () { ); }); expect(txRecordFeeMetricObject?.metricName).to.eq(metricHistogramCostSumTitle); - expect(txRecordFeeMetricObject?.labels.caller).to.eq(mockedCallerName); - expect(txRecordFeeMetricObject?.labels.interactingEntity).to.eq(mockedInteractingEntity); expect(txRecordFeeMetricObject?.value).to.eq(expectedTxRecordFee); } @@ -117,8 +113,6 @@ describe('Metric Service', function () { return metric.labels.mode === executionMode && metric.metricName === metricHistogramCostSumTitle; }); expect(transactionFeeMetricObject?.metricName).to.eq(metricHistogramCostSumTitle); - expect(transactionFeeMetricObject?.labels.caller).to.eq(mockedCallerName); - expect(transactionFeeMetricObject?.labels.interactingEntity).to.eq(mockedInteractingEntity); expect(transactionFeeMetricObject?.value).to.eq(mockedTxFee); }; From 653b07f0db87a893ebdf30336927c30fdfee5f80 Mon Sep 17 00:00:00 2001 From: nikolay Date: Wed, 25 Jun 2025 14:10:03 +0300 Subject: [PATCH 2/3] chore: resolve comments Signed-off-by: nikolay --- .../relay/src/lib/services/metricService/metricService.ts | 5 +---- packages/relay/src/lib/types/events.ts | 2 -- .../tests/lib/services/metricService/metricService.spec.ts | 2 -- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/relay/src/lib/services/metricService/metricService.ts b/packages/relay/src/lib/services/metricService/metricService.ts index b4f99048c4..195dccc6d6 100644 --- a/packages/relay/src/lib/services/metricService/metricService.ts +++ b/packages/relay/src/lib/services/metricService/metricService.ts @@ -159,7 +159,6 @@ export default class MetricService { executionMode: constants.EXECUTION_MODE.TRANSACTION, transactionId, txConstructorName, - callerName, cost: transactionFee, gasUsed, interactingEntity, @@ -174,7 +173,6 @@ export default class MetricService { executionMode: constants.EXECUTION_MODE.RECORD, transactionId, txConstructorName, - callerName, cost: txRecordChargeAmount, gasUsed: 0, interactingEntity, @@ -205,7 +203,6 @@ export default class MetricService { executionMode, transactionId, txConstructorName, - callerName, cost, gasUsed, status, @@ -214,7 +211,7 @@ export default class MetricService { }: IExecuteQueryEventPayload): Promise => { if (this.logger.isLevelEnabled('debug')) { this.logger.debug( - `${requestDetails.formattedRequestId} Capturing transaction fee charged to operator: executionMode=${executionMode} transactionId=${transactionId}, txConstructorName=${txConstructorName}, callerName=${callerName}, cost=${cost} tinybars`, + `${requestDetails.formattedRequestId} Capturing transaction fee charged to operator: executionMode=${executionMode} transactionId=${transactionId}, txConstructorName=${txConstructorName}, cost=${cost} tinybars`, ); } diff --git a/packages/relay/src/lib/types/events.ts b/packages/relay/src/lib/types/events.ts index 81f1d6cc3e..9ea618f02b 100644 --- a/packages/relay/src/lib/types/events.ts +++ b/packages/relay/src/lib/types/events.ts @@ -16,10 +16,8 @@ export interface IExecuteQueryEventPayload { executionMode: string; transactionId: string; txConstructorName: string; - callerName: string; cost: number; gasUsed: number; - interactingEntity: string; status: string; requestDetails: RequestDetails; originalCallerAddress: string | undefined; diff --git a/packages/relay/tests/lib/services/metricService/metricService.spec.ts b/packages/relay/tests/lib/services/metricService/metricService.spec.ts index 77702ec14e..799cd376c7 100644 --- a/packages/relay/tests/lib/services/metricService/metricService.spec.ts +++ b/packages/relay/tests/lib/services/metricService/metricService.spec.ts @@ -275,10 +275,8 @@ describe('Metric Service', function () { executionMode: constants.EXECUTION_MODE.QUERY, transactionId: mockedTransactionId, txConstructorName: mockedConstructorName, - callerName: mockedCallerName, cost: mockedTxFee, gasUsed: mockedGasUsed, - interactingEntity: mockedInteractingEntity, status: 'SUCCESS', requestDetails, originalCallerAddress: mockedOriginalCallerAddress, From 30cdca614bec19f4050c2c6dda266ba0ec806852 Mon Sep 17 00:00:00 2001 From: nikolay Date: Wed, 25 Jun 2025 16:53:35 +0300 Subject: [PATCH 3/3] chore: remove unused vars Signed-off-by: nikolay --- packages/relay/src/lib/clients/mirrorNodeClient.ts | 6 ++---- packages/relay/src/lib/clients/sdkClient.ts | 11 ++--------- .../src/lib/services/metricService/metricService.ts | 10 ---------- packages/relay/tests/lib/mirrorNodeClient.spec.ts | 4 +--- packages/relay/tests/lib/sdkClient.spec.ts | 2 -- 5 files changed, 5 insertions(+), 28 deletions(-) diff --git a/packages/relay/src/lib/clients/mirrorNodeClient.ts b/packages/relay/src/lib/clients/mirrorNodeClient.ts index cd96b595a4..edf4891063 100644 --- a/packages/relay/src/lib/clients/mirrorNodeClient.ts +++ b/packages/relay/src/lib/clients/mirrorNodeClient.ts @@ -1575,7 +1575,6 @@ export class MirrorNodeClient { * Retrieves and processes transaction record metrics from the mirror node based on the provided transaction ID. * * @param {string} transactionId - The ID of the transaction for which the record is being retrieved. - * @param {string} callerName - The name of the caller requesting the transaction record. * @param {string} txConstructorName - The name of the transaction constructor associated with the transaction. * @param {string} operatorAccountId - The account ID of the operator, used to calculate transaction fees. * @param {RequestDetails} requestDetails - The request details for logging and tracking. @@ -1584,7 +1583,6 @@ export class MirrorNodeClient { */ public async getTransactionRecordMetrics( transactionId: string, - callerName: string, txConstructorName: string, operatorAccountId: string, requestDetails: RequestDetails, @@ -1593,7 +1591,7 @@ export class MirrorNodeClient { if (this.logger.isLevelEnabled('debug')) { this.logger.debug( - `${formattedRequestId} Get transaction record via mirror node: transactionId=${transactionId}, txConstructorName=${txConstructorName}, callerName=${callerName}`, + `${formattedRequestId} Get transaction record via mirror node: transactionId=${transactionId}, txConstructorName=${txConstructorName}`, ); } @@ -1611,7 +1609,7 @@ export class MirrorNodeClient { ); if (!transactionRecords) { - const notFoundMessage = `No transaction record retrieved: transactionId=${transactionId}, txConstructorName=${txConstructorName}, callerName=${callerName}.`; + const notFoundMessage = `No transaction record retrieved: transactionId=${transactionId}, txConstructorName=${txConstructorName}.`; throw new MirrorNodeClientError({ message: notFoundMessage }, MirrorNodeClientError.statusCodes.NOT_FOUND); } diff --git a/packages/relay/src/lib/clients/sdkClient.ts b/packages/relay/src/lib/clients/sdkClient.ts index 09962d7f0e..1eef53c255 100644 --- a/packages/relay/src/lib/clients/sdkClient.ts +++ b/packages/relay/src/lib/clients/sdkClient.ts @@ -387,10 +387,8 @@ export class SDKClient { executionMode: constants.EXECUTION_MODE.QUERY, transactionId: query.paymentTransactionId?.toString(), txConstructorName: queryConstructorName, - callerName, cost: queryCost, gasUsed: 0, - interactingEntity, status, requestDetails, originalCallerAddress, @@ -487,11 +485,9 @@ export class SDKClient { if (transactionId?.length) { this.eventEmitter.emit(constants.EVENTS.EXECUTE_TRANSACTION, { transactionId, - callerName, requestDetails, txConstructorName, operatorAccountId: this.clientMain.operatorAccountId!.toString(), - interactingEntity, originalCallerAddress, } as IExecuteTransactionEventPayload); } @@ -558,11 +554,9 @@ export class SDKClient { if (transactionResponse.transactionId) { this.eventEmitter.emit(constants.EVENTS.EXECUTE_TRANSACTION, { transactionId: transactionResponse.transactionId.toString(), - callerName, requestDetails, txConstructorName, operatorAccountId: this.clientMain.operatorAccountId!.toString(), - interactingEntity, originalCallerAddress, } as IExecuteTransactionEventPayload); } @@ -736,7 +730,6 @@ export class SDKClient { */ public async getTransactionRecordMetrics( transactionId: string, - callerName: string, txConstructorName: string, operatorAccountId: string, requestDetails: RequestDetails, @@ -747,7 +740,7 @@ export class SDKClient { try { if (this.logger.isLevelEnabled('debug')) { this.logger.debug( - `${requestDetails.formattedRequestId} Get transaction record via consensus node: transactionId=${transactionId}, txConstructorName=${txConstructorName}, callerName=${callerName}`, + `${requestDetails.formattedRequestId} Get transaction record via consensus node: transactionId=${transactionId}, txConstructorName=${txConstructorName}`, ); } @@ -769,7 +762,7 @@ export class SDKClient { const sdkClientError = new SDKClientError(e, e.message); this.logger.warn( e, - `${requestDetails.formattedRequestId} Error raised during TransactionRecordQuery: transactionId=${transactionId}, txConstructorName=${txConstructorName}, callerName=${callerName}, recordStatus=${sdkClientError.status} (${sdkClientError.status._code}), cost=${transactionFee}, gasUsed=${gasUsed}`, + `${requestDetails.formattedRequestId} Error raised during TransactionRecordQuery: transactionId=${transactionId}, txConstructorName=${txConstructorName}, recordStatus=${sdkClientError.status} (${sdkClientError.status._code}), cost=${transactionFee}, gasUsed=${gasUsed}`, ); throw sdkClientError; } diff --git a/packages/relay/src/lib/services/metricService/metricService.ts b/packages/relay/src/lib/services/metricService/metricService.ts index 195dccc6d6..12f7ab9a51 100644 --- a/packages/relay/src/lib/services/metricService/metricService.ts +++ b/packages/relay/src/lib/services/metricService/metricService.ts @@ -136,17 +136,14 @@ export default class MetricService { * @returns {Promise} - A promise that resolves when the transaction metrics have been captured. */ public async captureTransactionMetrics({ - callerName, transactionId, txConstructorName, operatorAccountId, - interactingEntity, requestDetails, originalCallerAddress, }: IExecuteTransactionEventPayload): Promise { const transactionRecordMetrics = await this.getTransactionRecordMetrics( transactionId, - callerName, txConstructorName, operatorAccountId, requestDetails, @@ -161,7 +158,6 @@ export default class MetricService { txConstructorName, cost: transactionFee, gasUsed, - interactingEntity, status, requestDetails, originalCallerAddress, @@ -175,7 +171,6 @@ export default class MetricService { txConstructorName, cost: txRecordChargeAmount, gasUsed: 0, - interactingEntity, status, requestDetails, originalCallerAddress, @@ -191,7 +186,6 @@ export default class MetricService { * @param {string} payload.executionMode - The mode of the execution (TRANSACTION, QUERY, RECORD). * @param {string} payload.transactionId - The unique identifier for the transaction. * @param {string} payload.txConstructorName - The name of the transaction constructor. - * @param {string} payload.callerName - The name of the entity calling the transaction. * @param {number} payload.cost - The cost of the transaction in tinybars. * @param {number} payload.gasUsed - The amount of gas used during the transaction. * @param {string} payload.status - The entity interacting with the transaction. @@ -283,7 +277,6 @@ export default class MetricService { * consensus node via the SDK client or from the mirror node. * * @param {string} transactionId - The ID of the transaction for which metrics are being retrieved. - * @param {string} callerName - The name of the caller requesting the metrics. * @param {string} txConstructorName - The name of the transaction constructor. * @param {string} operatorAccountId - The account ID of the operator. * @param {RequestDetails} requestDetails - The request details for logging and tracking. @@ -291,7 +284,6 @@ export default class MetricService { */ private async getTransactionRecordMetrics( transactionId: string, - callerName: string, txConstructorName: string, operatorAccountId: string, requestDetails: RequestDetails, @@ -303,7 +295,6 @@ export default class MetricService { if (defaultToConsensusNode) { return await this.sdkClient.getTransactionRecordMetrics( transactionId, - callerName, txConstructorName, operatorAccountId, requestDetails, @@ -311,7 +302,6 @@ export default class MetricService { } else { return await this.mirrorNodeClient.getTransactionRecordMetrics( transactionId, - callerName, txConstructorName, operatorAccountId, requestDetails, diff --git a/packages/relay/tests/lib/mirrorNodeClient.spec.ts b/packages/relay/tests/lib/mirrorNodeClient.spec.ts index 14501cad34..cce22022e6 100644 --- a/packages/relay/tests/lib/mirrorNodeClient.spec.ts +++ b/packages/relay/tests/lib/mirrorNodeClient.spec.ts @@ -1576,7 +1576,6 @@ describe('MirrorNodeClient', async function () { const transactionRecordMetrics = await mirrorNodeInstance.getTransactionRecordMetrics( mockedTransactionId, - mockedCallerName, mockedConstructorName, operatorAcocuntId, requestDetails, @@ -1591,7 +1590,6 @@ describe('MirrorNodeClient', async function () { try { await mirrorNodeInstance.getTransactionRecordMetrics( mockedTransactionId, - mockedCallerName, mockedConstructorName, operatorAcocuntId, requestDetails, @@ -1599,7 +1597,7 @@ describe('MirrorNodeClient', async function () { expect.fail('should have thrown an error'); } catch (error) { - const notFoundMessage = `No transaction record retrieved: transactionId=${mockedTransactionId}, txConstructorName=${mockedConstructorName}, callerName=${mockedCallerName}.`; + const notFoundMessage = `No transaction record retrieved: transactionId=${mockedTransactionId}, txConstructorName=${mockedConstructorName}.`; const expectedError = new MirrorNodeClientError( { message: notFoundMessage }, MirrorNodeClientError.statusCodes.NOT_FOUND, diff --git a/packages/relay/tests/lib/sdkClient.spec.ts b/packages/relay/tests/lib/sdkClient.spec.ts index d0f7050001..a15bf41511 100644 --- a/packages/relay/tests/lib/sdkClient.spec.ts +++ b/packages/relay/tests/lib/sdkClient.spec.ts @@ -2808,7 +2808,6 @@ describe('SdkClient', async function () { const transactionRecordMetrics = await sdkClient.getTransactionRecordMetrics( transactionId.toString(), - mockedCallerName, mockedConstructorName, accountId.toString(), requestDetails, @@ -2827,7 +2826,6 @@ describe('SdkClient', async function () { try { await sdkClient.getTransactionRecordMetrics( transactionId.toString(), - mockedCallerName, mockedConstructorName, accountId.toString(), requestDetails,