From 7f218adfdcd7dce2797cd4b55e1943f719de6aee Mon Sep 17 00:00:00 2001 From: sc-crescendo Date: Fri, 25 Apr 2025 14:39:48 -0700 Subject: [PATCH 1/2] feat: added resetMetric(name) function --- README.md | 4 ++++ index.d.ts | 7 ++++++- lib/registry.js | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 348a5bff..21782eb6 100644 --- a/README.md +++ b/README.md @@ -617,3 +617,7 @@ To avoid native dependencies in this module, GC statistics for bytes reclaimed in each GC sweep are kept in a separate module: https://github.com/SimenB/node-prometheus-gc-stats. (Note that that metric may no longer be accurate now that v8 uses parallel garbage collection.) + + +## Modifications +This version includes new function resetMetric(name), which allows resetting inidividual metric by name \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 1fd1eac9..f830c349 100644 --- a/index.d.ts +++ b/index.d.ts @@ -37,7 +37,12 @@ export class Registry< /** * Reset all metrics in the registry */ - resetMetrics(): void; + resetMetrics(name: string): void; + + /** + * Reset one naed metric + */ + resetMetric(): void; /** * Register metric to register diff --git a/lib/registry.js b/lib/registry.js index dfe2c0b6..6046949b 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -165,6 +165,11 @@ class Registry { this._metrics[metric].reset(); } } + resetMetric(name) { + + this._metrics[metric].reset(); + + } get contentType() { return this._contentType; From 6bd27057516962f6b61353cfb9dd91a0c5f015ad Mon Sep 17 00:00:00 2001 From: sc-crescendo Date: Fri, 25 Apr 2025 14:48:34 -0700 Subject: [PATCH 2/2] fix: correct resetMetric declaration --- index.d.ts | 4 ++-- lib/registry.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index f830c349..0459840b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -37,12 +37,12 @@ export class Registry< /** * Reset all metrics in the registry */ - resetMetrics(name: string): void; + resetMetrics(): void; /** * Reset one naed metric */ - resetMetric(): void; + resetMetric(name: string): void; /** * Register metric to register diff --git a/lib/registry.js b/lib/registry.js index 6046949b..02077677 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -167,7 +167,7 @@ class Registry { } resetMetric(name) { - this._metrics[metric].reset(); + this._metrics[name].reset(); }