From 602c959077db8c4d47e99a122028916a0f85d4e1 Mon Sep 17 00:00:00 2001 From: Nadezhda Popova Date: Wed, 6 Nov 2024 11:15:04 +0200 Subject: [PATCH] fixup! fixup! chore: add active users counter per rate limiter duration Signed-off-by: Nadezhda Popova --- packages/relay/src/lib/eth.ts | 18 ++++++++++++++---- packages/server/src/server.ts | 12 ------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/relay/src/lib/eth.ts b/packages/relay/src/lib/eth.ts index 936680c29..610997dd5 100644 --- a/packages/relay/src/lib/eth.ts +++ b/packages/relay/src/lib/eth.ts @@ -234,6 +234,12 @@ export class EthImpl implements Eth { */ private readonly ethExecutionsCounter: Counter; + /** + * The dailyActveUsersCounter used to track the number of daily active users. + * @private + */ + private readonly dailyActveUsersCounter: Counter; + /** * The Common Service implementation that contains logic shared by other services. */ @@ -274,7 +280,8 @@ export class EthImpl implements Eth { this.cacheService = cacheService; this.mirrorNodeClient = mirrorNodeClient; this.precheck = new Precheck(mirrorNodeClient, logger, chain); - this.ethExecutionsCounter = this.initEthExecutionCounter(registry); + this.ethExecutionsCounter = this.initCounter('rpc_relay_eth_executions', ['method', 'function'], registry); + this.dailyActveUsersCounter = this.initCounter('rpc_relay_daily_active_users', ['methodName', 'from'], registry); this.common = new CommonService(mirrorNodeClient, logger, cacheService); this.debugServiceImpl = new DebugService(mirrorNodeClient, logger, this.common); this.filterServiceImpl = new FilterService(mirrorNodeClient, logger, cacheService, this.common); @@ -285,13 +292,12 @@ export class EthImpl implements Eth { return !CommonService.blockTagIsLatestOrPendingStrict(tag) && !CommonService.isDevMode; } - private initEthExecutionCounter(register: Registry): Counter { - const metricCounterName = 'rpc_relay_eth_executions'; + private initCounter(metricCounterName: string, labelNames: string[], register: Registry): Counter { register.removeSingleMetric(metricCounterName); return new Counter({ name: metricCounterName, help: `Relay ${metricCounterName} function`, - labelNames: ['method', 'function'], + labelNames: labelNames, registers: [register], }); } @@ -1579,6 +1585,8 @@ export class EthImpl implements Eth { await this.getCurrentNetworkExchangeRateInCents(requestDetails), ); + this.dailyActveUsersCounter.labels('eth_sendRawTransaction', originalCallerAddress).inc(); + txSubmitted = true; fileId = sendRawTransactionResult!.fileId; @@ -1662,6 +1670,8 @@ export class EthImpl implements Eth { .inc(); } + this.dailyActveUsersCounter.labels('eth_call', call.from || '').inc(); + const blockNumberOrTag = await this.extractBlockNumberOrTag(blockParam, requestDetails); await this.performCallChecks(call); diff --git a/packages/server/src/server.ts b/packages/server/src/server.ts index f4b3cc0ac..f1e446a5b 100644 --- a/packages/server/src/server.ts +++ b/packages/server/src/server.ts @@ -64,15 +64,6 @@ const methodResponseHistogram = new Histogram({ buckets: [5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 20000, 30000, 40000, 50000, 60000], // ms (milliseconds) }); -const metricCounterName = 'rpc_relay_daily_active_users'; -register.removeSingleMetric(metricCounterName); -const dailyActveUsersCounter = new Counter({ - name: metricCounterName, - help: `Relay ${metricCounterName} function`, - labelNames: ['methodName', 'from'], - registers: [register], -}); - // set cors app.getKoaApp().use(cors()); @@ -220,9 +211,6 @@ const logAndHandleResponse = async (methodName: string, methodParams: any[], met )}`, ); Validator.validateParams(methodParams, methodValidations); - if (methodName === 'eth_call') { - dailyActveUsersCounter.labels(methodName, methodParams?.[0].from).inc(); - } } const response = await methodFunction(requestDetails); if (response instanceof JsonRpcError) {