@platformatic/runtime 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/runtime.js CHANGED
@@ -710,6 +710,56 @@ export class Runtime extends EventEmitter {
710
710
  }
711
711
  }
712
712
 
713
+ /**
714
+ * Updates the metrics configuration at runtime without restarting the runtime or workers.
715
+ *
716
+ * This method allows you to:
717
+ * - Enable or disable metrics collection
718
+ * - Change Prometheus server settings (port, endpoint, authentication)
719
+ * - Update custom labels for metrics
720
+ *
721
+ * @example
722
+ * // Enable metrics with custom port
723
+ * await runtime.updateMetricsConfig({
724
+ * enabled: true,
725
+ * port: 9091,
726
+ * labels: { environment: 'production' }
727
+ * })
728
+ *
729
+ * // Disable metrics
730
+ * await runtime.updateMetricsConfig({ enabled: false })
731
+ */
732
+ async updateMetricsConfig (metricsConfig) {
733
+ if (this.#prometheusServer) {
734
+ await this.#prometheusServer.close()
735
+ this.#prometheusServer = null
736
+ }
737
+
738
+ this.#config.metrics = metricsConfig
739
+ this.#metricsLabelName = metricsConfig?.applicationLabel || 'applicationId'
740
+
741
+ if (metricsConfig.enabled !== false) {
742
+ this.#prometheusServer = await startPrometheusServer(this, metricsConfig)
743
+ }
744
+
745
+ const promises = []
746
+ for (const worker of this.#workers.values()) {
747
+ if (worker[kWorkerStatus] === 'started') {
748
+ promises.push(sendViaITC(worker, 'updateMetricsConfig', metricsConfig))
749
+ }
750
+ }
751
+
752
+ const results = await Promise.allSettled(promises)
753
+ for (const result of results) {
754
+ if (result.status === 'rejected') {
755
+ this.logger.error({ err: result.reason }, 'Cannot update metrics config on worker')
756
+ }
757
+ }
758
+
759
+ this.logger.info({ metricsConfig }, 'Metrics configuration updated')
760
+ return { success: true, config: metricsConfig }
761
+ }
762
+
713
763
  // TODO: Remove in next major version
714
764
  startCollectingMetrics () {
715
765
  this.logger.warn(
@@ -92,6 +92,13 @@ export class Controller extends EventEmitter {
92
92
  }
93
93
  }
94
94
 
95
+ async updateMetricsConfig (metricsConfig) {
96
+ this.#context.metricsConfig = metricsConfig
97
+ if (this.capability && typeof this.capability.updateMetricsConfig === 'function') {
98
+ await this.capability.updateMetricsConfig(metricsConfig)
99
+ }
100
+ }
101
+
95
102
  // Note: capability's init() is executed within start
96
103
  async init () {
97
104
  try {
package/lib/worker/itc.js CHANGED
@@ -2,8 +2,8 @@ import { ensureLoggableError, executeInParallel, executeWithTimeout, kTimeout }
2
2
  import { ITC } from '@platformatic/itc'
3
3
  import { Unpromise } from '@watchable/unpromise'
4
4
  import { once } from 'node:events'
5
- import repl from 'node:repl'
6
5
  import { Duplex } from 'node:stream'
6
+ import { createRequire } from 'node:module'
7
7
  import { parentPort, workerData } from 'node:worker_threads'
8
8
  import {
9
9
  ApplicationExitedError,
@@ -176,6 +176,13 @@ export function setupITC (controller, application, dispatcher, sharedContext) {
176
176
  await updateUndiciInterceptors(undiciConfig)
177
177
  },
178
178
 
179
+ async updateMetricsConfig (metricsConfig) {
180
+ if (controller && typeof controller.updateMetricsConfig === 'function') {
181
+ await controller.updateMetricsConfig(metricsConfig)
182
+ }
183
+ return { success: true }
184
+ },
185
+
179
186
  async updateWorkersCount (data) {
180
187
  const { workers } = data
181
188
  workerData.applicationConfig.workers = workers
@@ -266,6 +273,14 @@ export function setupITC (controller, application, dispatcher, sharedContext) {
266
273
  },
267
274
 
268
275
  startRepl (port) {
276
+ // We are loading the repl module dynamically here to avoid loading it
277
+ // when not needed (since it pulls in domain, which is quite expensive
278
+ // as it monkey patches EventEmitter).
279
+ // We must use local require() instead of import
280
+ // because dynamic import() is async and the
281
+ // startRepl handler is sync.
282
+ const repl = createRequire(import.meta.url)('node:repl')
283
+
269
284
  // Create a duplex stream that wraps the MessagePort
270
285
  const replStream = new Duplex({
271
286
  read () {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "3.29.1",
3
+ "version": "3.30.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -35,14 +35,14 @@
35
35
  "typescript": "^5.5.4",
36
36
  "undici-oidc-interceptor": "^0.5.0",
37
37
  "why-is-node-running": "^2.2.2",
38
- "@platformatic/composer": "3.29.1",
39
- "@platformatic/db": "3.29.1",
40
- "@platformatic/node": "3.29.1",
41
- "@platformatic/gateway": "3.29.1",
42
- "@platformatic/service": "3.29.1",
43
- "@platformatic/sql-graphql": "3.29.1",
44
- "@platformatic/sql-mapper": "3.29.1",
45
- "@platformatic/wattpm-pprof-capture": "3.29.1"
38
+ "@platformatic/composer": "3.30.0",
39
+ "@platformatic/db": "3.30.0",
40
+ "@platformatic/gateway": "3.30.0",
41
+ "@platformatic/node": "3.30.0",
42
+ "@platformatic/sql-graphql": "3.30.0",
43
+ "@platformatic/sql-mapper": "3.30.0",
44
+ "@platformatic/service": "3.30.0",
45
+ "@platformatic/wattpm-pprof-capture": "3.30.0"
46
46
  },
47
47
  "dependencies": {
48
48
  "@fastify/accepts": "^5.0.0",
@@ -58,7 +58,7 @@
58
58
  "cron": "^4.1.0",
59
59
  "debounce": "^2.0.0",
60
60
  "fastest-levenshtein": "^1.0.16",
61
- "fastify": "^5.0.0",
61
+ "fastify": "^5.7.0",
62
62
  "graphql": "^16.8.1",
63
63
  "help-me": "^5.0.0",
64
64
  "minimist": "^1.2.8",
@@ -71,12 +71,12 @@
71
71
  "undici": "^7.0.0",
72
72
  "undici-thread-interceptor": "^1.0.0",
73
73
  "ws": "^8.16.0",
74
- "@platformatic/basic": "3.29.1",
75
- "@platformatic/generators": "3.29.1",
76
- "@platformatic/itc": "3.29.1",
77
- "@platformatic/foundation": "3.29.1",
78
- "@platformatic/metrics": "3.29.1",
79
- "@platformatic/telemetry": "3.29.1"
74
+ "@platformatic/foundation": "3.30.0",
75
+ "@platformatic/basic": "3.30.0",
76
+ "@platformatic/generators": "3.30.0",
77
+ "@platformatic/itc": "3.30.0",
78
+ "@platformatic/telemetry": "3.30.0",
79
+ "@platformatic/metrics": "3.30.0"
80
80
  },
81
81
  "engines": {
82
82
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.29.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.30.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Runtime Config",
5
5
  "type": "object",