From ac5e084eaf2691592006113d14723bde6677da61 Mon Sep 17 00:00:00 2001 From: Kalin Krustev Date: Thu, 12 Dec 2024 16:37:03 +0200 Subject: [PATCH] fix: remove errorCount prefix (#178) --- package-lock.json | 8 ++++---- package.json | 2 +- src/metrics.ts | 8 +++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 89c8aa9..2e342ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ }, "devDependencies": { "@hapi/hapi": "^21.3.12", - "@types/node": "^22.10.1", + "@types/node": "^22.10.2", "@types/tape": "^5.6.5", "audit-ci": "^7.1.0", "debug": "4.4.0", @@ -1133,9 +1133,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.10.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", - "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", + "version": "22.10.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz", + "integrity": "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index d47fb72..c7dcdcf 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ }, "devDependencies": { "@hapi/hapi": "^21.3.12", - "@types/node": "^22.10.1", + "@types/node": "^22.10.2", "@types/tape": "^5.6.5", "audit-ci": "^7.1.0", "debug": "4.4.0", diff --git a/src/metrics.ts b/src/metrics.ts index 63a81ca..09477d1 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -92,6 +92,7 @@ class Metrics { client.AggregatorRegistry.setRegistries(this.getDefaultRegister()) return false } + this.getDefaultRegister().clear() this._options = options // map the options to the normalised options specific to the prom-client const normalisedOptions: normalisedMetricOptionsType = { @@ -122,7 +123,8 @@ class Metrics { this.getCounter( 'errorCount', 'Error count', - ['code', 'system', 'operation', 'step'] + ['code', 'system', 'operation', 'step'], + false ) } @@ -170,13 +172,13 @@ class Metrics { } } - getCounter = (name: string, help?: string, labelNames?: string[]): client.Counter => { + getCounter = (name: string, help?: string, labelNames?: string[], prefix: boolean = true): client.Counter => { try { if (this._counters[name] != null) { return this._counters[name] } this._counters[name] = new client.Counter({ - name: `${this.getOptions().prefix}${name}`, + name: `${prefix ? this.getOptions().prefix : ''}${name}`, help: (help != null ? help : `${name}_counter`), labelNames })