Skip to content

Commit

Permalink
fixup! fixup! chore: add active users counter per rate limiter duration
Browse files Browse the repository at this point in the history
Signed-off-by: Nadezhda Popova <[email protected]>
  • Loading branch information
nadezhdapopovaa committed Nov 6, 2024
1 parent 9ae5db5 commit 602c959
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
18 changes: 14 additions & 4 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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],
});
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
12 changes: 0 additions & 12 deletions packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 602c959

Please sign in to comment.