@platformatic/metrics 2.69.0 → 2.70.0

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 CHANGED
@@ -12,9 +12,6 @@ async function collectMetrics (serviceId, workerId, metricsConfig = {}, registry
12
12
  registry = new Registry()
13
13
  }
14
14
 
15
- const httpRequestCallbacks = []
16
- const httpResponseCallbacks = []
17
-
18
15
  const labels = { ...metricsConfig.labels, serviceId }
19
16
  if (workerId >= 0) {
20
17
  labels.workerId = workerId
@@ -28,51 +25,25 @@ async function collectMetrics (serviceId, workerId, metricsConfig = {}, registry
28
25
  }
29
26
 
30
27
  if (metricsConfig.httpMetrics) {
31
- {
32
- const { startTimer, endTimer } = collectHttpMetrics(registry, {
33
- customLabels: ['telemetry_id'],
34
- getCustomLabels: req => {
35
- const telemetryId = req.headers?.['x-plt-telemetry-id'] ?? 'unknown'
36
- return { telemetry_id: telemetryId }
37
- }
38
- })
39
- httpRequestCallbacks.push(startTimer)
40
- httpResponseCallbacks.push(endTimer)
41
- }
42
-
43
- {
44
- // TODO: check if it's a nodejs environment
45
- // Needed for the Meraki metrics
46
- const { startTimer, endTimer } = collectHttpMetrics(registry, {
47
- customLabels: ['telemetry_id'],
48
- getCustomLabels: req => {
49
- const telemetryId = req.headers?.['x-plt-telemetry-id'] ?? 'unknown'
50
- return { telemetry_id: telemetryId }
51
- },
52
- histogram: {
53
- name: 'http_request_all_duration_seconds',
54
- help: 'request duration in seconds summary for all requests',
55
- collect: function () {
56
- process.nextTick(() => this.reset())
57
- }
58
- },
59
- summary: {
60
- name: 'http_request_all_summary_seconds',
61
- help: 'request duration in seconds histogram for all requests',
62
- collect: function () {
63
- process.nextTick(() => this.reset())
64
- }
65
- }
66
- })
67
- httpRequestCallbacks.push(startTimer)
68
- httpResponseCallbacks.push(endTimer)
69
- }
28
+ collectHttpMetrics(registry, {
29
+ customLabels: ['telemetry_id'],
30
+ getCustomLabels: req => {
31
+ const telemetryId = req.headers?.['x-plt-telemetry-id'] ?? 'unknown'
32
+ return { telemetry_id: telemetryId }
33
+ },
34
+ histogram: {
35
+ name: 'http_request_all_duration_seconds',
36
+ help: 'request duration in seconds summary for all requests'
37
+ },
38
+ summary: {
39
+ name: 'http_request_all_summary_seconds',
40
+ help: 'request duration in seconds histogram for all requests'
41
+ }
42
+ })
70
43
  }
71
44
 
72
45
  return {
73
46
  registry,
74
- startHttpTimer: options => httpRequestCallbacks.forEach(cb => cb(options)),
75
- endHttpTimer: options => httpResponseCallbacks.forEach(cb => cb(options))
76
47
  }
77
48
  }
78
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/metrics",
3
- "version": "2.69.0",
3
+ "version": "2.70.0",
4
4
  "description": "Platformatic Stackable Metrics",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
package/test/helper.js CHANGED
@@ -124,15 +124,7 @@ const expectedMetrics = [
124
124
  {
125
125
  name: 'http_request_all_duration_seconds',
126
126
  type: 'histogram'
127
- },
128
- {
129
- name: 'http_request_duration_seconds',
130
- type: 'histogram'
131
- },
132
- {
133
- name: 'http_request_summary_seconds',
134
- type: 'summary'
135
- },
127
+ }
136
128
  ]
137
129
 
138
130
  function assertMetric (metrics, metric) {
@@ -148,31 +140,31 @@ function assertMetric (metrics, metric) {
148
140
 
149
141
  function assertSummary (metrics, metric) {
150
142
  assert.ok(metrics.includes(`${metric.name}{quantile="0.01"`))
151
- assert.ok(metrics.includes('http_request_summary_seconds{quantile="0.01"'))
152
- assert.ok(metrics.includes('http_request_summary_seconds{quantile="0.05"'))
153
- assert.ok(metrics.includes('http_request_summary_seconds{quantile="0.5"'))
154
- assert.ok(metrics.includes('http_request_summary_seconds{quantile="0.9"'))
155
- assert.ok(metrics.includes('http_request_summary_seconds{quantile="0.95"'))
156
- assert.ok(metrics.includes('http_request_summary_seconds{quantile="0.99"'))
157
- assert.ok(metrics.includes('http_request_summary_seconds{quantile="0.999"'))
158
- assert.ok(metrics.includes('http_request_summary_seconds_sum{'))
159
- assert.ok(metrics.includes('http_request_summary_seconds_count{'))
143
+ assert.ok(metrics.includes('http_request_all_summary_seconds{quantile="0.01"'))
144
+ assert.ok(metrics.includes('http_request_all_summary_seconds{quantile="0.05"'))
145
+ assert.ok(metrics.includes('http_request_all_summary_seconds{quantile="0.5"'))
146
+ assert.ok(metrics.includes('http_request_all_summary_seconds{quantile="0.9"'))
147
+ assert.ok(metrics.includes('http_request_all_summary_seconds{quantile="0.95"'))
148
+ assert.ok(metrics.includes('http_request_all_summary_seconds{quantile="0.99"'))
149
+ assert.ok(metrics.includes('http_request_all_summary_seconds{quantile="0.999"'))
150
+ assert.ok(metrics.includes('http_request_all_summary_seconds_sum{'))
151
+ assert.ok(metrics.includes('http_request_all_summary_seconds_count{'))
160
152
  }
161
153
 
162
154
  function assertHistogram (metrics, metric) {
163
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="0.005"'))
164
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="0.01"'))
165
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="0.025"'))
166
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="0.05"'))
167
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="0.1"'))
168
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="0.25"'))
169
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="0.5"'))
170
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="1"'))
171
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="2.5"'))
172
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="5"'))
173
- assert.ok(metrics.includes('http_request_duration_seconds_bucket{le="10"'))
174
- assert.ok(metrics.includes('http_request_duration_seconds_sum{'))
175
- assert.ok(metrics.includes('http_request_duration_seconds_count{'))
155
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="0.005"'))
156
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="0.01"'))
157
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="0.025"'))
158
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="0.05"'))
159
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="0.1"'))
160
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="0.25"'))
161
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="0.5"'))
162
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="1"'))
163
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="2.5"'))
164
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="5"'))
165
+ assert.ok(metrics.includes('http_request_all_duration_seconds_bucket{le="10"'))
166
+ assert.ok(metrics.includes('http_request_all_duration_seconds_sum{'))
167
+ assert.ok(metrics.includes('http_request_all_duration_seconds_count{'))
176
168
  }
177
169
 
178
170
  module.exports = {
@@ -8,8 +8,6 @@ test('returns expected structure', async () => {
8
8
  const result = await collectMetrics('test-service', 1, {})
9
9
 
10
10
  assert.ok(result.registry)
11
- assert.equal(typeof result.startHttpTimer, 'function')
12
- assert.equal(typeof result.endHttpTimer, 'function')
13
11
  })
14
12
 
15
13
  test('accepts custom registry', async () => {