@platformatic/runtime 3.40.0 → 3.42.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.d.ts CHANGED
@@ -27,7 +27,7 @@ export interface ApplicationsCommands {
27
27
  help: Record<string, string | (() => string)>
28
28
  }
29
29
 
30
- export module errors {
30
+ export namespace errors {
31
31
  export const RuntimeExitedError: () => FastifyError
32
32
  export const UnknownRuntimeAPICommandError: (command: string) => FastifyError
33
33
  export const ApplicationNotFoundError: (id: string) => FastifyError
@@ -47,7 +47,7 @@ export module errors {
47
47
  export const NodeInspectorFlagsNotSupportedError: () => FastifyError
48
48
  }
49
49
 
50
- export module symbols {
50
+ export namespace symbols {
51
51
  export declare const kConfig: unique symbol
52
52
  export declare const kId: unique symbol
53
53
  export declare const kFullId: unique symbol
@@ -214,6 +214,15 @@ export async function managementApiPlugin (app, opts) {
214
214
  reply.type('application/octet-stream').code(200).send(profileData)
215
215
  })
216
216
 
217
+ app.post('/applications/:id/heap-snapshot', async (request, reply) => {
218
+ const { id } = request.params
219
+ app.log.debug('take heap snapshot', { id })
220
+
221
+ const stream = await runtime.takeApplicationHeapSnapshot(id)
222
+ reply.type('application/octet-stream').send(stream)
223
+ return reply
224
+ })
225
+
217
226
  app.get('/metrics', { logLevel: 'debug' }, async (req, reply) => {
218
227
  const config = await runtime.getRuntimeConfig()
219
228
 
package/lib/runtime.js CHANGED
@@ -19,6 +19,7 @@ import { STATUS_CODES } from 'node:http'
19
19
  import { createRequire } from 'node:module'
20
20
  import { availableParallelism } from 'node:os'
21
21
  import { dirname, isAbsolute, join } from 'node:path'
22
+ import { Readable } from 'node:stream'
22
23
  import { setImmediate as immediate, setTimeout as sleep } from 'node:timers/promises'
23
24
  import { pathToFileURL } from 'node:url'
24
25
  import { Worker } from 'node:worker_threads'
@@ -736,6 +737,30 @@ export class Runtime extends EventEmitter {
736
737
  return sendViaITC(service, 'stopProfiling', options)
737
738
  }
738
739
 
740
+ async takeApplicationHeapSnapshot (id, ensureStarted = true) {
741
+ const service = await this.#getApplicationById(id, ensureStarted)
742
+
743
+ const { port1, port2 } = new MessageChannel()
744
+
745
+ const readable = new Readable({ read () {} })
746
+
747
+ port2.on('message', (message) => {
748
+ if (message.type === 'chunk') {
749
+ readable.push(message.chunk)
750
+ } else if (message.type === 'error') {
751
+ readable.destroy(new Error(message.message))
752
+ port2.close()
753
+ } else if (message.type === 'end') {
754
+ readable.push(null)
755
+ port2.close()
756
+ }
757
+ })
758
+
759
+ await sendViaITC(service, 'takeHeapSnapshot', port1, [port1])
760
+
761
+ return readable
762
+ }
763
+
739
764
  async startApplicationRepl (id, ensureStarted = true) {
740
765
  const service = await this.#getApplicationById(id, ensureStarted)
741
766
 
package/lib/worker/itc.js CHANGED
@@ -342,6 +342,28 @@ export function setupITC (controller, application, dispatcher, sharedContext) {
342
342
  messaging.addSource(channel)
343
343
  },
344
344
 
345
+ takeHeapSnapshot (port) {
346
+ const { Session } = createRequire(import.meta.url)('node:inspector')
347
+ const session = new Session()
348
+ session.connect()
349
+
350
+ session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
351
+ port.postMessage({ type: 'chunk', chunk: m.params.chunk })
352
+ })
353
+
354
+ session.post('HeapProfiler.takeHeapSnapshot', null, (err) => {
355
+ session.disconnect()
356
+ if (err) {
357
+ port.postMessage({ type: 'error', message: err.message })
358
+ } else {
359
+ port.postMessage({ type: 'end' })
360
+ }
361
+ port.close()
362
+ })
363
+
364
+ return { started: true }
365
+ },
366
+
345
367
  startRepl (port) {
346
368
  // Check if running in subprocess mode - forward through ChildManager
347
369
  const childManager = controller.capability?.getChildManager?.()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "3.40.0",
3
+ "version": "3.42.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.40.0",
39
- "@platformatic/service": "3.40.0",
40
- "@platformatic/gateway": "3.40.0",
41
- "@platformatic/db": "3.40.0",
42
- "@platformatic/sql-mapper": "3.40.0",
43
- "@platformatic/wattpm-pprof-capture": "3.40.0",
44
- "@platformatic/sql-graphql": "3.40.0",
45
- "@platformatic/node": "3.40.0"
38
+ "@platformatic/composer": "3.42.0",
39
+ "@platformatic/db": "3.42.0",
40
+ "@platformatic/gateway": "3.42.0",
41
+ "@platformatic/node": "3.42.0",
42
+ "@platformatic/service": "3.42.0",
43
+ "@platformatic/sql-graphql": "3.42.0",
44
+ "@platformatic/sql-mapper": "3.42.0",
45
+ "@platformatic/wattpm-pprof-capture": "3.42.0"
46
46
  },
47
47
  "dependencies": {
48
48
  "@fastify/accepts": "^5.0.0",
@@ -63,7 +63,7 @@
63
63
  "graphql": "^16.8.1",
64
64
  "help-me": "^5.0.0",
65
65
  "minimist": "^1.2.8",
66
- "pino": "^9.9.0",
66
+ "pino": "^10.1.0",
67
67
  "pino-opentelemetry-transport": "^2.0.0",
68
68
  "pino-pretty": "^13.0.0",
69
69
  "semgrator": "^0.3.0",
@@ -72,12 +72,12 @@
72
72
  "undici": "^7.0.0",
73
73
  "undici-thread-interceptor": "^1.3.1",
74
74
  "ws": "^8.16.0",
75
- "@platformatic/foundation": "3.40.0",
76
- "@platformatic/generators": "3.40.0",
77
- "@platformatic/basic": "3.40.0",
78
- "@platformatic/itc": "3.40.0",
79
- "@platformatic/metrics": "3.40.0",
80
- "@platformatic/telemetry": "3.40.0"
75
+ "@platformatic/foundation": "3.42.0",
76
+ "@platformatic/itc": "3.42.0",
77
+ "@platformatic/basic": "3.42.0",
78
+ "@platformatic/generators": "3.42.0",
79
+ "@platformatic/telemetry": "3.42.0",
80
+ "@platformatic/metrics": "3.42.0"
81
81
  },
82
82
  "engines": {
83
83
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.40.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/3.42.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Runtime Config",
5
5
  "type": "object",