Skip to content

Commit 94328ad

Browse files
authored
Add logic to clear metric from registry before create (#229)
In some test suites we recreate client instances causes failures when registering a metric - Add logic to clear metrics from registry before creating Signed-off-by: Nana-EC <[email protected]>
1 parent dcb9172 commit 94328ad

File tree

4 files changed

+106
-94
lines changed

4 files changed

+106
-94
lines changed

packages/relay/src/lib/clients/mirrorNodeClient.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ export class MirrorNodeClient {
123123
this.logger = logger;
124124
this.register = register;
125125

126+
// clear and create metric in registry
127+
const metricHistogramName = 'rpc_relay_mirror_response';
128+
register.removeSingleMetric(metricHistogramName);
126129
this.mirrorResponseHistogram = new Histogram({
127-
name: 'rpc_relay_mirror_response',
130+
name: metricHistogramName,
128131
help: 'Mirror node response method statusCode latency histogram',
129132
labelNames: ['method', 'statusCode'],
130133
registers: [register]
@@ -291,19 +294,19 @@ export class MirrorNodeClient {
291294
const queryParamObject = {};
292295
this.setQueryParam(queryParamObject, 'timestamp', timestamp);
293296
const queryParams = this.getQueryParams(queryParamObject);
294-
return this.request(`${MirrorNodeClient.GET_NETWORK_EXCHANGERATE_ENDPOINT}${queryParams}`,
295-
MirrorNodeClient.GET_NETWORK_EXCHANGERATE_ENDPOINT,
296-
[400, 404]);
297+
return this.request(`${MirrorNodeClient.GET_NETWORK_EXCHANGERATE_ENDPOINT}${queryParams}`,
298+
MirrorNodeClient.GET_NETWORK_EXCHANGERATE_ENDPOINT,
299+
[400, 404]);
297300
}
298301

299302
public async getNetworkFees(timestamp?: string, order?: string) {
300303
const queryParamObject = {};
301304
this.setQueryParam(queryParamObject, 'timestamp', timestamp);
302305
this.setQueryParam(queryParamObject, 'order', order);
303306
const queryParams = this.getQueryParams(queryParamObject);
304-
return this.request(`${MirrorNodeClient.GET_NETWORK_FEES_ENDPOINT}${queryParams}`,
305-
MirrorNodeClient.GET_NETWORK_FEES_ENDPOINT,
306-
[400, 404]);
307+
return this.request(`${MirrorNodeClient.GET_NETWORK_FEES_ENDPOINT}${queryParams}`,
308+
MirrorNodeClient.GET_NETWORK_FEES_ENDPOINT,
309+
[400, 404]);
307310
}
308311

309312
private static getContractResultsByAddressPath(address: string) {

packages/relay/src/lib/clients/sdkClient.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,21 @@ export class SDKClient {
8080
this.clientMain = clientMain;
8181
this.logger = logger;
8282
this.register = register;
83+
84+
// clear and create metrics in registry
85+
const metricHistogramName = 'rpc_relay_consensusnode_response';
86+
register.removeSingleMetric(metricHistogramName);
8387
this.consensusNodeClientHistorgram = new Histogram({
84-
name: 'rpc_relay_consensusnode_response',
88+
name: metricHistogramName,
8589
help: 'Relay consensusnode mode type status cost histogram',
8690
labelNames: ['mode', 'type', 'status'],
8791
registers: [register]
8892
});
8993

94+
const metricGaugeName = 'rpc_relay_operator_balance';
95+
register.removeSingleMetric(metricHistogramName);
9096
this.operatorAccountGauge = new Gauge({
91-
name: 'rpc_relay_operator_balance',
97+
name: metricGaugeName,
9298
help: 'Relay operator balance gauge',
9399
labelNames: ['mode', 'type'],
94100
registers: [register],

0 commit comments

Comments
 (0)