@platformatic/basic 3.29.1 → 3.30.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/lib/capability.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  kMetadata,
8
8
  kTimeout
9
9
  } from '@platformatic/foundation'
10
- import { client, collectMetrics, ensureMetricsGroup, setupOtlpExporter } from '@platformatic/metrics'
10
+ import { clearRegistry, client, collectMetrics, ensureMetricsGroup, setupOtlpExporter } from '@platformatic/metrics'
11
11
  import { parseCommandString } from 'execa'
12
12
  import { spawn } from 'node:child_process'
13
13
  import { tracingChannel } from 'node:diagnostics_channel'
@@ -155,6 +155,37 @@ export class BaseCapability extends EventEmitter {
155
155
  // No-op by default
156
156
  }
157
157
 
158
+ async updateMetricsConfig (metricsConfig) {
159
+ // Transform applicationLabel to idLabel (same transformation as in worker/main.js)
160
+ const normalizedConfig = {
161
+ ...metricsConfig,
162
+ idLabel: metricsConfig.applicationLabel || 'applicationId'
163
+ }
164
+ this.context.metricsConfig = normalizedConfig
165
+
166
+ // If running in subprocess mode, send the update to the child process
167
+ if (this.childManager && this.clientWs) {
168
+ await this.childManager.send(this.clientWs, 'updateMetricsConfig', {
169
+ applicationId: this.applicationId,
170
+ workerId: this.workerId,
171
+ metricsConfig: normalizedConfig
172
+ })
173
+ return
174
+ }
175
+
176
+ if (this.metricsRegistry) {
177
+ // We must clear the registry to stop prom-client from collecting metrics in the background,
178
+ // and because prom-client doesn't support changing labels on existing metrics.
179
+ // This will lose all previously collected metrics.
180
+ clearRegistry(this.metricsRegistry)
181
+
182
+ if (metricsConfig.enabled !== false) {
183
+ this.#metricsCollected = false
184
+ await this._collectMetrics()
185
+ }
186
+ }
187
+ }
188
+
158
189
  start () {
159
190
  throw new Error('BaseCapability.start must be overriden by the subclasses')
160
191
  }
@@ -5,7 +5,7 @@ import {
5
5
  ensureLoggableError
6
6
  } from '@platformatic/foundation'
7
7
  import { ITC } from '@platformatic/itc/lib/index.js'
8
- import { client, collectMetrics } from '@platformatic/metrics'
8
+ import { clearRegistry, client, collectMetrics } from '@platformatic/metrics'
9
9
  import diagnosticChannel, { tracingChannel } from 'node:diagnostics_channel'
10
10
  import { EventEmitter, once } from 'node:events'
11
11
  import { readFile } from 'node:fs/promises'
@@ -84,6 +84,9 @@ export class ChildProcess extends ITC {
84
84
  collectMetrics: (...args) => {
85
85
  return this.#collectMetrics(...args)
86
86
  },
87
+ updateMetricsConfig: (...args) => {
88
+ return this.#updateMetricsConfig(...args)
89
+ },
87
90
  getMetrics: (...args) => {
88
91
  return this.#getMetrics(...args)
89
92
  },
@@ -221,6 +224,15 @@ export class ChildProcess extends ITC {
221
224
  this.#setHttpCacheMetrics()
222
225
  }
223
226
 
227
+ async #updateMetricsConfig ({ applicationId, workerId, metricsConfig }) {
228
+ clearRegistry(this.#metricsRegistry)
229
+
230
+ if (metricsConfig.enabled !== false) {
231
+ await collectMetrics(applicationId, workerId, metricsConfig, this.#metricsRegistry)
232
+ this.#setHttpCacheMetrics()
233
+ }
234
+ }
235
+
224
236
  #setHttpCacheMetrics () {
225
237
  const { client, registry } = globalThis.platformatic.prometheus
226
238
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/basic",
3
- "version": "3.29.1",
3
+ "version": "3.30.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -25,16 +25,16 @@
25
25
  "split2": "^4.2.0",
26
26
  "undici": "^7.0.0",
27
27
  "ws": "^8.18.0",
28
- "@platformatic/foundation": "3.29.1",
29
- "@platformatic/itc": "3.29.1",
30
- "@platformatic/telemetry": "3.29.1",
31
- "@platformatic/metrics": "3.29.1"
28
+ "@platformatic/foundation": "3.30.0",
29
+ "@platformatic/itc": "3.30.0",
30
+ "@platformatic/metrics": "3.30.0",
31
+ "@platformatic/telemetry": "3.30.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "cleaner-spec-reporter": "^0.5.0",
35
35
  "eslint": "9",
36
36
  "express": "^4.19.2",
37
- "fastify": "^5.0.0",
37
+ "fastify": "^5.7.0",
38
38
  "get-port": "^7.1.0",
39
39
  "json-schema-to-typescript": "^15.0.0",
40
40
  "neostandard": "^0.12.0",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/basic/3.29.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/basic/3.30.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Basic Config",
5
5
  "type": "object",