@hkube/metrics 1.0.42 → 1.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/counter.js CHANGED
@@ -24,6 +24,16 @@ class CounterMeasure {
24
24
  remove() {
25
25
  client.register.removeSingleMetric(this._name + COUNTER_POSTFIX);
26
26
  }
27
+ removeEntriesByLabel(labelName, labelValue) {
28
+ const keysToDelete = [];
29
+ const hashKeys = Object.keys(this._requestCounter.hashMap);
30
+ hashKeys.forEach((key) => {
31
+ if (this._requestCounter.hashMap[key].labels[labelName] === labelValue) {
32
+ keysToDelete.push(key);
33
+ }
34
+ });
35
+ keysToDelete.forEach(key => delete this._requestCounter.hashMap[key]);
36
+ }
27
37
  }
28
38
 
29
39
  module.exports = CounterMeasure;
package/lib/gauge.js CHANGED
@@ -36,6 +36,16 @@ class GaugeMeasure {
36
36
  remove() {
37
37
  client.register.removeSingleMetric(this._name + GAUGE_POSTFIX);
38
38
  }
39
+ removeEntriesByLabel(labelName, labelValue) {
40
+ const keysToDelete = [];
41
+ const hashKeys = Object.keys(this._requestGauge.hashMap);
42
+ hashKeys.forEach((key) => {
43
+ if (this._requestGauge.hashMap[key].labels[labelName] === labelValue) {
44
+ keysToDelete.push(key);
45
+ }
46
+ });
47
+ keysToDelete.forEach(key => delete this._requestGauge.hashMap[key]);
48
+ }
39
49
  }
40
50
 
41
51
  module.exports = GaugeMeasure;
package/lib/metrics.js CHANGED
@@ -8,6 +8,7 @@ const GaugeMeasure = require('./gauge');
8
8
  const { addTimeMeasureSchema, addCounterMeasureSchema, addTimeMeasureSummarySchema } = require('./schema');
9
9
  const router = require('./router');
10
10
  const RestServer = require('@hkube/rest-server');
11
+ const promUtils = require('prom-client/lib/util.js');
11
12
 
12
13
  const {
13
14
  beforeRoutesMiddlewares,
@@ -167,6 +168,23 @@ class Metrics {
167
168
  this._metrics.delete(this.prefix + name);
168
169
  }
169
170
  }
171
+
172
+ /**
173
+ * remove all entries in the specified metrics, that are assosiated with the specified jobId
174
+ * @param {*} options
175
+ * @param {string} options.labelName
176
+ * @param {string} options.labelValue
177
+ * @param {string[]} options.metricsToRemove array of metric names to remove
178
+ */
179
+ removeMeasureEntries(options) {
180
+ const { labelName, labelValue, metricsToRemove } = options;
181
+ metricsToRemove.forEach((metricName) => {
182
+ const measureInstance = this.get(metricName);
183
+ if (measureInstance) {
184
+ measureInstance.removeEntriesByLabel(labelName, labelValue);
185
+ }
186
+ });
187
+ }
170
188
  }
171
189
 
172
190
  module.exports = new Metrics();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkube/metrics",
3
- "version": "1.0.42",
3
+ "version": "1.0.43",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {