@platformatic/control 3.41.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/lib/errors.js CHANGED
@@ -98,6 +98,11 @@ export const FailedToStopProfiling = createError(
98
98
  'Failed to stop profiling for service "%s": %s'
99
99
  )
100
100
 
101
+ export const FailedToTakeHeapSnapshot = createError(
102
+ `${ERROR_PREFIX}_FAILED_TO_TAKE_HEAP_SNAPSHOT`,
103
+ 'Failed to take heap snapshot for service "%s": %s'
104
+ )
105
+
101
106
  export const FailedToAddApplications = createError(
102
107
  `${ERROR_PREFIX}_FAILED_TO_ADD_APPLICATIONS`,
103
108
  'Failed to add applications: %s'
package/lib/index.js CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  FailedToStopProfiling,
27
27
  FailedToStopRuntime,
28
28
  FailedToStreamRuntimeLogs,
29
+ FailedToTakeHeapSnapshot,
29
30
  ProfilingAlreadyStarted,
30
31
  ProfilingNotStarted,
31
32
  RuntimeNotFound
@@ -382,6 +383,36 @@ export class RuntimeApiClient {
382
383
  return await body.arrayBuffer()
383
384
  }
384
385
 
386
+ async takeApplicationHeapSnapshot (pid, applicationId) {
387
+ const client = this.#getUndiciClient(pid)
388
+
389
+ const { statusCode, body } = await client.request({
390
+ path: `/api/v1/applications/${applicationId}/heap-snapshot`,
391
+ method: 'POST'
392
+ })
393
+
394
+ if (statusCode !== 200) {
395
+ const error = await body.text()
396
+ let jsonError
397
+ try {
398
+ jsonError = JSON.parse(error)
399
+ } catch {
400
+ // No-op
401
+ }
402
+
403
+ const message = jsonError?.message || error
404
+ const code = jsonError?.code
405
+
406
+ if (code === 'PLT_RUNTIME_APPLICATION_NOT_FOUND' || code === 'PLT_RUNTIME_APPLICATION_WORKER_NOT_FOUND') {
407
+ throw new ApplicationNotFound(message)
408
+ }
409
+
410
+ throw new FailedToTakeHeapSnapshot(applicationId, message)
411
+ }
412
+
413
+ return body
414
+ }
415
+
385
416
  async reloadRuntime (pid, options = {}) {
386
417
  const runtime = await this.getMatchingRuntime({ pid })
387
418
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "3.41.0",
3
+ "version": "3.42.0",
4
4
  "description": "Platformatic Control",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "split2": "^4.2.0",
24
24
  "tsd": "^0.33.0",
25
25
  "typescript": "^5.5.4",
26
- "@platformatic/runtime": "3.41.0",
27
- "@platformatic/service": "3.41.0"
26
+ "@platformatic/service": "3.42.0",
27
+ "@platformatic/runtime": "3.42.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "@fastify/error": "^4.0.0",
@@ -34,7 +34,7 @@
34
34
  "table": "^6.8.1",
35
35
  "undici": "^7.0.0",
36
36
  "ws": "^8.16.0",
37
- "@platformatic/foundation": "3.41.0"
37
+ "@platformatic/foundation": "3.42.0"
38
38
  },
39
39
  "tsd": {
40
40
  "directory": "test/types"