@platformatic/basic 3.29.0 → 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/config.d.ts CHANGED
@@ -25,6 +25,8 @@ export interface PlatformaticBasicConfig {
25
25
  maxMemory?: number;
26
26
  cooldown?: number;
27
27
  gracePeriod?: number;
28
+ scaleUpELU?: number;
29
+ scaleDownELU?: number;
28
30
  [k: string]: unknown;
29
31
  };
30
32
  workersRestartDelay?: number | string;
@@ -357,13 +359,7 @@ export interface PlatformaticBasicConfig {
357
359
  maxWorkers?: number;
358
360
  cooldownSec?: number;
359
361
  gracePeriod?: number;
360
- /**
361
- * @deprecated
362
- */
363
362
  scaleUpELU?: number;
364
- /**
365
- * @deprecated
366
- */
367
363
  scaleDownELU?: number;
368
364
  /**
369
365
  * @deprecated
@@ -427,6 +423,8 @@ export interface PlatformaticBasicConfig {
427
423
  static?: number;
428
424
  minimum?: number;
429
425
  maximum?: number;
426
+ scaleUpELU?: number;
427
+ scaleDownELU?: number;
430
428
  [k: string]: unknown;
431
429
  };
432
430
  health?: {
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.0",
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.0",
29
- "@platformatic/metrics": "3.29.0",
30
- "@platformatic/telemetry": "3.29.0",
31
- "@platformatic/itc": "3.29.0"
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.0.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",
@@ -94,6 +94,16 @@
94
94
  "maximum": {
95
95
  "type": "number",
96
96
  "minimum": 0
97
+ },
98
+ "scaleUpELU": {
99
+ "type": "number",
100
+ "minimum": 0,
101
+ "maximum": 1
102
+ },
103
+ "scaleDownELU": {
104
+ "type": "number",
105
+ "minimum": 0,
106
+ "maximum": 1
97
107
  }
98
108
  }
99
109
  }
@@ -373,6 +383,16 @@
373
383
  "gracePeriod": {
374
384
  "type": "number",
375
385
  "minimum": 0
386
+ },
387
+ "scaleUpELU": {
388
+ "type": "number",
389
+ "minimum": 0,
390
+ "maximum": 1
391
+ },
392
+ "scaleDownELU": {
393
+ "type": "number",
394
+ "minimum": 0,
395
+ "maximum": 1
376
396
  }
377
397
  }
378
398
  }
@@ -1405,14 +1425,12 @@
1405
1425
  "scaleUpELU": {
1406
1426
  "type": "number",
1407
1427
  "minimum": 0,
1408
- "maximum": 1,
1409
- "deprecated": true
1428
+ "maximum": 1
1410
1429
  },
1411
1430
  "scaleDownELU": {
1412
1431
  "type": "number",
1413
1432
  "minimum": 0,
1414
- "maximum": 1,
1415
- "deprecated": true
1433
+ "maximum": 1
1416
1434
  },
1417
1435
  "timeWindowSec": {
1418
1436
  "type": "number",
@@ -1613,6 +1631,16 @@
1613
1631
  "maximum": {
1614
1632
  "type": "number",
1615
1633
  "minimum": 0
1634
+ },
1635
+ "scaleUpELU": {
1636
+ "type": "number",
1637
+ "minimum": 0,
1638
+ "maximum": 1
1639
+ },
1640
+ "scaleDownELU": {
1641
+ "type": "number",
1642
+ "minimum": 0,
1643
+ "maximum": 1
1616
1644
  }
1617
1645
  }
1618
1646
  }