Skip to content

Commit a3bbd68

Browse files
ebadiereNana-EC
andauthored
fix: Added metrics around the HBar rate limiter to better track the (… (#2672)
fix: Added metrics around the HBar rate limiter to better track the (#2657) * fix: Added metrics around the HBar rate limiter to better track the HBar rate limiting. * Update packages/relay/src/lib/hbarlimiter/index.ts * fix: Removed the shouldLimit called counter. --------- Signed-off-by: ebadiere <[email protected]> Signed-off-by: Eric Badiere <[email protected]> Co-authored-by: Nana Essilfie-Conduah <[email protected]>
1 parent 2b43748 commit a3bbd68

File tree

1 file changed

+14
-2
lines changed
  • packages/relay/src/lib/hbarlimiter

1 file changed

+14
-2
lines changed

packages/relay/src/lib/hbarlimiter/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Hedera JSON RPC Relay
44
*
5-
* Copyright (C) 2023 Hedera Hashgraph, LLC
5+
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
*/
2020

2121
import { Logger } from 'pino';
22-
import { Registry, Counter } from 'prom-client';
22+
import { Registry, Counter, Gauge } from 'prom-client';
2323

2424
export default class HbarLimit {
2525
private enabled: boolean = false;
@@ -29,6 +29,7 @@ export default class HbarLimit {
2929
private reset: number;
3030
private logger: Logger;
3131
private hbarLimitCounter: Counter;
32+
private hbarLimitRemainingGauge: Gauge;
3233
private readonly register: Registry;
3334

3435
constructor(logger: Logger, currentDateNow: number, total: number, duration: number, register: Registry) {
@@ -52,6 +53,16 @@ export default class HbarLimit {
5253
registers: [register],
5354
labelNames: ['mode', 'methodName'],
5455
});
56+
this.hbarLimitCounter.inc(0);
57+
58+
const rateLimiterRemainingGaugeName = 'rpc_relay_hbar_rate_remaining';
59+
register.removeSingleMetric(rateLimiterRemainingGaugeName);
60+
this.hbarLimitRemainingGauge = new Gauge({
61+
name: rateLimiterRemainingGaugeName,
62+
help: 'Relay Hbar rate limit remaining budget',
63+
registers: [register],
64+
});
65+
this.hbarLimitRemainingGauge.set(this.remainingBudget);
5566
}
5667

5768
/**
@@ -89,6 +100,7 @@ export default class HbarLimit {
89100
this.resetLimiter(currentDateNow);
90101
}
91102
this.remainingBudget -= cost;
103+
this.hbarLimitRemainingGauge.set(this.remainingBudget);
92104
}
93105

94106
/**

0 commit comments

Comments
 (0)