Skip to content

Commit

Permalink
feat: integrated HbarLimitService instance into MetricService class
Browse files Browse the repository at this point in the history
Signed-off-by: Logan Nguyen <logan.nguyen@swirldslabs.com>
  • Loading branch information
quiet-node committed Sep 30, 2024
1 parent b8d83c2 commit f8c554e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/relay/src/lib/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class RelayImpl implements Relay {
hbarLimiter,
register,
this.eventEmitter,
hbarLimitService,
);

this.ethImpl = new EthImpl(
Expand Down
11 changes: 11 additions & 0 deletions packages/relay/src/lib/services/metricService/metricService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Histogram, Registry } from 'prom-client';
import { MirrorNodeClient, SDKClient } from '../../clients';
import { formatRequestIdMessage } from '../../../formatters';
import { ITransactionRecordMetric, IExecuteQueryEventPayload, IExecuteTransactionEventPayload } from '../../types';
import { HbarLimitService } from '../hbarLimitService';

export default class MetricService {
/**
Expand Down Expand Up @@ -85,6 +86,14 @@ export default class MetricService {
*/
private readonly eventEmitter: EventEmitter;

/**
* An instance of the HbarLimitService that tracks hbar expenses and limits.
* @private
* @readonly
* @type {HbarLimitService}
*/
private readonly hbarLimitService: HbarLimitService;

/**
* Constructs an instance of the MetricService responsible for tracking and recording various metrics
* related to Hedera network interactions and resource usage.
Expand All @@ -103,12 +112,14 @@ export default class MetricService {
hbarLimiter: HbarLimit,
register: Registry,
eventEmitter: EventEmitter,
hbarLimitService: HbarLimitService,
) {
this.logger = logger;
this.sdkClient = sdkClient;
this.hbarLimiter = hbarLimiter;
this.eventEmitter = eventEmitter;
this.mirrorNodeClient = mirrorNodeClient;
this.hbarLimitService = hbarLimitService;
this.consensusNodeClientHistogramCost = this.initCostMetric(register);
this.consensusNodeClientHistogramGasFee = this.initGasMetric(register);

Expand Down
10 changes: 9 additions & 1 deletion packages/relay/tests/lib/sdkClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,15 @@ describe('SdkClient', async function () {
instance,
);

metricService = new MetricService(logger, sdkClient, mirrorNodeClient, hbarLimiter, registry, eventEmitter);
metricService = new MetricService(
logger,
sdkClient,
mirrorNodeClient,
hbarLimiter,
registry,
eventEmitter,
hbarLimitService,
);
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,15 @@ describe('Metric Service', function () {
hbarLimitService,
);
// Init new MetricService instance
metricService = new MetricService(logger, sdkClient, mirrorNodeClient, hbarLimiter, registry, eventEmitter);
metricService = new MetricService(
logger,
sdkClient,
mirrorNodeClient,
hbarLimiter,
registry,
eventEmitter,
hbarLimitService,
);
});

afterEach(() => {
Expand Down

0 comments on commit f8c554e

Please sign in to comment.