@platformatic/metrics 3.72.0 → 4.0.0-alpha.1
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/index.js +2 -11
- package/package.json +4 -4
- package/test/index.test.js +25 -6
package/index.js
CHANGED
|
@@ -197,9 +197,6 @@ export function collectHttpClientMetrics (registry) {
|
|
|
197
197
|
name: 'http_client_request_duration_seconds',
|
|
198
198
|
help: 'outgoing HTTP client request duration in seconds',
|
|
199
199
|
labelNames: ['method', 'status_code', 'dispatcher_stats_url', 'error_type'],
|
|
200
|
-
collect: function () {
|
|
201
|
-
process.nextTick(() => this.reset())
|
|
202
|
-
},
|
|
203
200
|
registers: [registry]
|
|
204
201
|
})
|
|
205
202
|
|
|
@@ -271,17 +268,11 @@ function collectHttpServerMetrics (registry, metricsConfig) {
|
|
|
271
268
|
getCustomLabels,
|
|
272
269
|
histogram: {
|
|
273
270
|
name: 'http_request_all_duration_seconds',
|
|
274
|
-
help: 'request duration in seconds summary for all requests'
|
|
275
|
-
collect: function () {
|
|
276
|
-
process.nextTick(() => this.reset())
|
|
277
|
-
}
|
|
271
|
+
help: 'request duration in seconds summary for all requests'
|
|
278
272
|
},
|
|
279
273
|
summary: {
|
|
280
274
|
name: 'http_request_all_summary_seconds',
|
|
281
|
-
help: 'request duration in seconds histogram for all requests'
|
|
282
|
-
collect: function () {
|
|
283
|
-
process.nextTick(() => this.reset())
|
|
284
|
-
}
|
|
275
|
+
help: 'request duration in seconds histogram for all requests'
|
|
285
276
|
}
|
|
286
277
|
})
|
|
287
278
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/metrics",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "Platformatic Capability Metrics",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"homepage": "https://github.com/platformatic/platformatic#readme",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@platformatic/globals": "3.72.0",
|
|
19
18
|
"@platformatic/http-metrics": "^0.3.0",
|
|
20
19
|
"@platformatic/promotel": "^0.2.0",
|
|
21
|
-
"@platformatic/prom-client": "^1.0.0"
|
|
20
|
+
"@platformatic/prom-client": "^1.0.0",
|
|
21
|
+
"@platformatic/globals": "4.0.0-alpha.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"cleaner-spec-reporter": "^0.5.0",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"neostandard": "^0.12.0"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=24.20.0"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"test": "node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js",
|
package/test/index.test.js
CHANGED
|
@@ -138,7 +138,26 @@ test('httpMetrics observes outgoing HTTP client request errors', async t => {
|
|
|
138
138
|
assert.strictEqual(count.labels.error_type, 'UND_ERR_SOCKET')
|
|
139
139
|
})
|
|
140
140
|
|
|
141
|
-
test('httpMetrics histogram
|
|
141
|
+
test('httpMetrics client histogram is not reset after metric collection', async t => {
|
|
142
|
+
const result = await collectMetrics('test-service', 1, { httpMetrics: true, httpClientMetrics: true })
|
|
143
|
+
t.after(() => clearRegistry(result.registry))
|
|
144
|
+
|
|
145
|
+
const request = { method: 'GET', origin: 'http://dependency.internal', path: '/' }
|
|
146
|
+
channel('undici:request:create').publish({ request })
|
|
147
|
+
channel('undici:request:headers').publish({ request, response: { statusCode: 200 } })
|
|
148
|
+
channel('undici:request:trailers').publish({ request })
|
|
149
|
+
|
|
150
|
+
await result.registry.metrics()
|
|
151
|
+
|
|
152
|
+
await nextTick()
|
|
153
|
+
|
|
154
|
+
const metrics = await result.registry.getMetricsAsJSON()
|
|
155
|
+
const histogram = metrics.find(m => m.name === 'http_client_request_duration_seconds')
|
|
156
|
+
const count = histogram.values.find(v => v.metricName === 'http_client_request_duration_seconds_count')
|
|
157
|
+
assert.strictEqual(count.value, 1, 'client histogram count should be preserved')
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('httpMetrics histogram is not reset after metric collection', async t => {
|
|
142
161
|
const result = await collectMetrics('test-service', 1, { httpMetrics: true })
|
|
143
162
|
t.after(() => clearRegistry(result.registry))
|
|
144
163
|
|
|
@@ -163,11 +182,11 @@ test('httpMetrics histogram resets after metric collection', async t => {
|
|
|
163
182
|
|
|
164
183
|
const sum = histogramAfter.values.find(v => v.metricName === 'http_request_all_duration_seconds_sum')
|
|
165
184
|
const count = histogramAfter.values.find(v => v.metricName === 'http_request_all_duration_seconds_count')
|
|
166
|
-
assert.
|
|
167
|
-
assert.strictEqual(count
|
|
185
|
+
assert.ok(Math.abs(sum.value - 0.6) < 1e-9, 'histogram sum should be preserved')
|
|
186
|
+
assert.strictEqual(count.value, 3, 'histogram count should be preserved')
|
|
168
187
|
})
|
|
169
188
|
|
|
170
|
-
test('httpMetrics summary
|
|
189
|
+
test('httpMetrics summary is not reset after metric collection', async t => {
|
|
171
190
|
const result = await collectMetrics('test-service', 1, { httpMetrics: true })
|
|
172
191
|
t.after(() => clearRegistry(result.registry))
|
|
173
192
|
|
|
@@ -192,8 +211,8 @@ test('httpMetrics summary resets after metric collection', async t => {
|
|
|
192
211
|
|
|
193
212
|
const sum = summaryAfter.values.find(v => v.metricName === 'http_request_all_summary_seconds_sum')
|
|
194
213
|
const count = summaryAfter.values.find(v => v.metricName === 'http_request_all_summary_seconds_count')
|
|
195
|
-
assert.
|
|
196
|
-
assert.strictEqual(count
|
|
214
|
+
assert.ok(Math.abs(sum.value - 0.75) < 1e-9, 'summary sum should be preserved')
|
|
215
|
+
assert.strictEqual(count.value, 3, 'summary count should be preserved')
|
|
197
216
|
})
|
|
198
217
|
|
|
199
218
|
// Tests for buildCustomLabelsConfig
|