@hkube/metrics 1.0.42 → 1.0.45

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.
@@ -34,26 +34,30 @@ jobs:
34
34
  with:
35
35
  github-token: ${{ secrets.GITHUB_TOKEN }}
36
36
  publish:
37
- if: github.ref == 'refs/heads/master'
38
- needs: test
39
- runs-on: ubuntu-latest
40
- steps:
41
- - uses: actions/checkout@v2
42
- - name: setup git
43
- run: |
44
- git config --local user.email "action@github.com"
45
- git config --local user.name "GitHub Action"
46
- - name: version
47
- run: |
48
- git checkout -f -b version-branch
49
- npm version patch --no-commit-hooks -m "$(git log -1 --pretty=%B) .... bump version [skip ci]"
50
- git push origin version-branch:master --follow-tags
51
- - uses: actions/setup-node@v1
52
- with:
53
- node-version: 14
54
- - name: Publish
55
- run: |
56
- npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
57
- npm publish --ignore-scripts
58
- env:
59
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
37
+ if: github.ref == 'refs/heads/master'
38
+ needs: test
39
+ runs-on: ubuntu-latest
40
+ #Needed for OIDC - Npm repo publishing
41
+ permissions:
42
+ id-token: write
43
+ contents: write
44
+ steps:
45
+ - uses: actions/checkout@v2
46
+ - name: setup git
47
+ run: |
48
+ git config --local user.email "action@github.com"
49
+ git config --local user.name "GitHub Action"
50
+ - name: version
51
+ run: |
52
+ git checkout -f -b version-branch
53
+ npm version patch --no-commit-hooks -m "$(git log -1 --pretty=%B) .... bump version [skip ci]"
54
+ git push origin version-branch:master --follow-tags
55
+ - uses: actions/setup-node@v4 # Use v4 for OIDC support
56
+ with:
57
+ node-version: 24 # Use a modern Node version
58
+ registry-url: https://registry.npmjs.org
59
+ scope: '@hkube'
60
+ - name: Enable provenance
61
+ run: npm config set provenance true
62
+ - name: Publish to npm
63
+ run: NODE_AUTH_TOKEN="" npm publish --access public --loglevel verbose
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/lib/schema.js CHANGED
@@ -121,7 +121,8 @@ const tracerSchema = {
121
121
  logSpans: { type: 'boolean' },
122
122
  agentHost: { type: 'string', default: 'localhost' },
123
123
  agentPort: { type: ['number', 'string'], default: 6832 },
124
- flushIntervalMs: { type: 'number' }
124
+ queueSize: { type: 'number', default: 2000 },
125
+ flushIntervalMs: { type: 'number', default: 1000 }
125
126
  },
126
127
  default: {},
127
128
  additionalProperties: false
package/lib/tracer.js CHANGED
@@ -121,6 +121,19 @@ class Tracer {
121
121
  return span;
122
122
  }
123
123
 
124
+ close() {
125
+ return new Promise((resolve) => {
126
+ if (!this._tracer) {
127
+ resolve();
128
+ return;
129
+ }
130
+ this._tracer.close(() => {
131
+ this._tracer = null;
132
+ resolve();
133
+ });
134
+ });
135
+ }
136
+
124
137
  get parentRelationships() {
125
138
  return parentRelationships;
126
139
  }
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@hkube/metrics",
3
- "version": "1.0.42",
3
+ "version": "1.0.45",
4
4
  "description": "",
5
5
  "main": "index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/kube-HPC/metrics.hkube.git"
9
+ },
6
10
  "scripts": {
7
11
  "test": "NODE_ENV=test node_modules/mocha/bin/mocha test --colors --recursive --exit",
8
12
  "test-travis": "NODE_ENV=test ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec test --exit",
@@ -69,6 +69,26 @@ describe('Tracer', () => {
69
69
  const moreTracer = await tracer.createTracer('moreTracer', {});
70
70
  expect(moreTracer._tracer._serviceName).to.equal('moreTracer');
71
71
  });
72
+
73
+ it('should close tracer', async () => {
74
+ await tracer.init({
75
+ tracerConfig: {
76
+ serviceName: 'test',
77
+ },
78
+ tracerOptions: {
79
+ reporter: new InMemoryReporter()
80
+ }
81
+
82
+ });
83
+ expect(tracer._tracer).to.exist;
84
+ await tracer.close();
85
+ expect(tracer._tracer).to.not.exist;
86
+ });
87
+
88
+ it('should close without tracer', async () => {
89
+ await tracer.close();
90
+ expect(tracer._tracer).to.not.exist;
91
+ });
72
92
  });
73
93
  describe('Span', () => {
74
94
  it('should throw without options', async () => {