Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions packages/relay/src/lib/services/metricService/metricService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ export default class MetricService {
executionMode: constants.EXECUTION_MODE.TRANSACTION,
transactionId,
txConstructorName,
callerName,
cost: transactionFee,
gasUsed,
interactingEntity,
Expand All @@ -174,7 +173,6 @@ export default class MetricService {
executionMode: constants.EXECUTION_MODE.RECORD,
transactionId,
txConstructorName,
callerName,
cost: txRecordChargeAmount,
gasUsed: 0,
interactingEntity,
Expand All @@ -196,7 +194,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.
Expand All @@ -206,22 +203,20 @@ export default class MetricService {
executionMode,
transactionId,
txConstructorName,
callerName,
cost,
gasUsed,
interactingEntity,
status,
requestDetails,
originalCallerAddress,
}: IExecuteQueryEventPayload): Promise<void> => {
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`,
);
}

await this.hbarLimitService.addExpense(cost, originalCallerAddress ?? '', requestDetails);
this.captureMetrics(executionMode, txConstructorName, status, cost, gasUsed, callerName, interactingEntity);
this.captureMetrics(executionMode, txConstructorName, status, cost, gasUsed);
};

/**
Expand All @@ -235,7 +230,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],
});
}
Expand All @@ -251,7 +246,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],
});
}
Expand All @@ -275,21 +270,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);
};

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/relay/src/lib/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand All @@ -108,17 +106,13 @@ 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);
}

const transactionFeeMetricObject = metricObjects.values.find((metric) => {
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);
};

Expand Down Expand Up @@ -281,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,
Expand Down
Loading