@platformatic/control 3.71.1-alpha.0 → 4.0.0-alpha.1

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.d.ts CHANGED
@@ -21,6 +21,8 @@ export declare const FailedToGetRuntimeHistoryLogs: (value: string) => FastifyEr
21
21
  export declare const FailedToGetRuntimeAllLogs: (value: string) => FastifyError
22
22
  export declare const FailedToGetRuntimeLogIndexes: (value: string) => FastifyError
23
23
  export declare const FailedToGetRuntimeMetrics: (value: string) => FastifyError
24
+ export declare const FailedToGetRuntimeMemory: (value: string) => FastifyError
25
+ export declare const FailedToGetRuntimeWorkersScaler: (value: string) => FastifyError
24
26
  export declare const FailedToStartProfiling: (value: string) => FastifyError
25
27
  export declare const FailedToStopProfiling: (value: string) => FastifyError
26
28
  export declare const FailedToAddApplications: (value: string) => FastifyError
package/lib/errors.js CHANGED
@@ -53,11 +53,6 @@ export const FailedToReloadRuntime = createError(
53
53
  'Failed to reload the runtime %s.'
54
54
  )
55
55
 
56
- export const FailedToGetRuntimeConfig = createError(
57
- `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_CONFIG`,
58
- 'Failed to get runtime config %s.'
59
- )
60
-
61
56
  export const FailedToGetRuntimeApplicationEnv = createError(
62
57
  `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_APPLICATION_ENV`,
63
58
  'Failed to get runtime application environment variables %s.'
@@ -88,6 +83,16 @@ export const FailedToGetRuntimeMetrics = createError(
88
83
  'Failed to get runtime metrics %s.'
89
84
  )
90
85
 
86
+ export const FailedToGetRuntimeMemory = createError(
87
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_MEMORY`,
88
+ 'Failed to get runtime memory %s.'
89
+ )
90
+
91
+ export const FailedToGetRuntimeWorkersScaler = createError(
92
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_WORKERS_SCALER`,
93
+ 'Failed to get runtime workers scaler %s.'
94
+ )
95
+
91
96
  export const ProfilingAlreadyStarted = createError(
92
97
  `${ERROR_PREFIX}_PROFILING_ALREADY_STARTED`,
93
98
  'Profiling is already started for service "%s".'
package/lib/index.d.ts CHANGED
@@ -23,16 +23,26 @@ export interface RuntimeApplicationBase {
23
23
  status: string
24
24
  }
25
25
 
26
+ export type ServingState = 'listening' | 'mesh-only' | 'background' | 'inactive'
27
+
26
28
  export interface RuntimeApplication {
27
29
  id: string
28
30
  type: string
29
31
  status: string
32
+ /** How the application serves, as opposed to whether it runs. Absent when it is not started. */
33
+ servingState?: ServingState
30
34
  version: string
31
35
  localUrl: string
32
- entrypoint: boolean
33
- url?: string
36
+ url: string | null
37
+ urls: string[]
34
38
  workers?: number
35
- dependencies: Runtime
39
+ dependencies: string[]
40
+ path?: string
41
+ sourceMaps?: boolean
42
+ /** v3 only: the path to the application's configuration file. v4 reports configPath. */
43
+ config?: string
44
+ /** v4 only: the configuration file the loader decided on, absent for an inline definition. */
45
+ configPath?: string
36
46
  }
37
47
 
38
48
  export interface Runtime {
@@ -43,15 +53,18 @@ export interface Runtime {
43
53
  execPath: string
44
54
  nodeVersion: string
45
55
  projectDir: string
56
+ /** The configuration file the loader decided on. Null when the runtime was built from an object. */
57
+ configPath: string | null
58
+ /** The autoload declaration, with its path resolved. Null when the project does not autoload. */
59
+ autoload: { path: string, exclude?: string[], mappings?: Record<string, unknown> } | null
46
60
  packageName: string | null
47
61
  packageVersion: string | null
48
- url: string | null
49
62
  platformaticVersion: string
63
+ urls: Record<string, string>
50
64
  startTime?: number
51
65
  }
52
66
 
53
67
  export interface RuntimeApplications {
54
- entrypoint: string
55
68
  production: boolean
56
69
  applications: (RuntimeApplication | RuntimeApplicationBase)[]
57
70
  }
@@ -89,6 +102,59 @@ export interface Metric {
89
102
  aggregator: string
90
103
  }
91
104
 
105
+ export interface WorkersScalerMetric {
106
+ threshold: number | null
107
+ lastProcessedTs: number
108
+ level: number | null
109
+ trendPerSecond: number
110
+ }
111
+
112
+ export interface WorkersScalerWorkerMetric {
113
+ lastSampleTs: number
114
+ lastValue: number
115
+ firstSampleTs: number
116
+ intervalMs: number
117
+ values: number[]
118
+ }
119
+
120
+ export interface WorkersScalerPendingStart {
121
+ scaleAt: number
122
+ decisionAt: number
123
+ expectedCount: number
124
+ }
125
+
126
+ export interface WorkersScalerApplication {
127
+ id: string
128
+ targetCount: number
129
+ liveCount: number
130
+ minimum: number
131
+ maximum: number
132
+ initTimeoutMs: number
133
+ horizonMs: number
134
+ pending: WorkersScalerPendingStart[]
135
+ metrics: Record<string, WorkersScalerMetric>
136
+ workers: {
137
+ id: string
138
+ startTime: number
139
+ metrics: Record<string, WorkersScalerWorkerMetric>
140
+ }[]
141
+ }
142
+
143
+ export interface WorkersScaler {
144
+ version: number
145
+ now: number
146
+ processIntervalMs: number
147
+ maxTotalWorkers: number
148
+ memoryLimit: number
149
+ applications: WorkersScalerApplication[]
150
+ }
151
+
152
+ export interface RuntimeMemory {
153
+ scope: 'host' | 'cgroup-v1' | 'cgroup-v2'
154
+ used: number
155
+ total: number
156
+ }
157
+
92
158
  export interface LogIndexes {
93
159
  pid: number
94
160
  indexes: number[]
@@ -97,14 +163,12 @@ export interface LogIndexes {
97
163
  export interface RuntimeSchedulerJob {
98
164
  name: string
99
165
  cron: string
100
- source: 'config' | 'application'
166
+ source: 'application'
101
167
  paused: boolean
102
168
  maxRetries: number
103
169
  lastExecutedAt: string | null
104
170
  lastStatus: 'success' | 'failed' | null
105
171
  nextRunAt: string | null
106
- callbackUrl?: string
107
- method?: string
108
172
  applicationId?: string
109
173
  scheduleId?: string
110
174
  tasks?: string[]
@@ -125,11 +189,6 @@ export class RuntimeApiClient {
125
189
  pauseRuntimeSchedulerJob (pid: number, name: string): Promise<RuntimeSchedulerJob>
126
190
  resumeRuntimeSchedulerJob (pid: number, name: string): Promise<RuntimeSchedulerJob>
127
191
  runRuntimeSchedulerJob (pid: number, name: string): Promise<RuntimeSchedulerRunResult>
128
- getRuntimeConfig (
129
- pid: number
130
- ): Promise<
131
- Record<string, unknown> & { path?: string; configFile?: string; configPath?: string; server?: { path?: string } }
132
- >
133
192
  getRuntimeApplicationConfig (pid: number, applicationId?: string): Promise<Record<string, unknown>>
134
193
  getRuntimeEnv (pid: number): Promise<Record<string, string>>
135
194
  getRuntimeOpenapi (pid: number, applicationId: string): Promise<Record<string, unknown>>
@@ -141,7 +200,8 @@ export class RuntimeApiClient {
141
200
  pid: number,
142
201
  options?: T
143
202
  ): Promise<T extends { format: 'text' } ? string : Metric[]>
144
- getRuntimeLiveMetricsStream (pid: number): WebSocketStream
203
+ getRuntimeMemory (pid: number): Promise<RuntimeMemory>
204
+ getRuntimeWorkersScaler (pid: number): Promise<WorkersScaler | null>
145
205
  getRuntimeLiveLogsStream (pid: number, startLogIndex?: number): WebSocketStream
146
206
  getRuntimeLogsStream (pid: number, logsId: string, options?: { runtimePID?: number }): Promise<ReadableBody>
147
207
  getRuntimeAllLogsStream (pid: number, options?: { runtimePID?: number }): Promise<ReadableBody>
package/lib/index.js CHANGED
@@ -13,12 +13,13 @@ import {
13
13
  FailedToGetRuntimeApplicationConfig,
14
14
  FailedToGetRuntimeApplicationEnv,
15
15
  FailedToGetRuntimeApplications,
16
- FailedToGetRuntimeConfig,
17
16
  FailedToGetRuntimeEnv,
18
17
  FailedToGetRuntimeHistoryLogs,
19
18
  FailedToGetRuntimeLogIndexes,
20
19
  FailedToGetRuntimeMetadata,
21
20
  FailedToGetRuntimeMetrics,
21
+ FailedToGetRuntimeMemory,
22
+ FailedToGetRuntimeWorkersScaler,
22
23
  FailedToGetRuntimeOpenapi,
23
24
  FailedToGetRuntimeScheduler,
24
25
  FailedToReloadRuntime,
@@ -239,23 +240,6 @@ export class RuntimeApiClient {
239
240
  return body.json()
240
241
  }
241
242
 
242
- async getRuntimeConfig (pid, metadata = false) {
243
- const client = this.#getUndiciClient(pid)
244
-
245
- const { statusCode, body } = await client.request({
246
- path: `/api/v1/config?metadata=${metadata ? 'true' : 'false'}`,
247
- method: 'GET'
248
- })
249
-
250
- if (statusCode !== 200) {
251
- const error = await body.text()
252
- throw new FailedToGetRuntimeConfig(error)
253
- }
254
-
255
- const runtimeConfig = await body.json()
256
- return runtimeConfig
257
- }
258
-
259
243
  async getRuntimeApplicationConfig (pid, applicationId) {
260
244
  const client = this.#getUndiciClient(pid)
261
245
 
@@ -587,15 +571,42 @@ export class RuntimeApiClient {
587
571
  return metrics
588
572
  }
589
573
 
590
- getRuntimeLiveMetricsStream (pid) {
591
- const socketPath = this.#getSocketPathFromPid(pid)
574
+ async getRuntimeMemory (pid) {
575
+ const client = this.#getUndiciClient(pid)
592
576
 
593
- const protocol = platform() === 'win32' ? 'ws+unix:' : 'ws+unix://'
594
- const webSocketUrl = protocol + socketPath + ':/api/v1/metrics/live'
595
- const webSocketStream = new WebSocketStream(webSocketUrl)
596
- this.#webSockets.add(webSocketStream.ws)
577
+ const { statusCode, body } = await client.request({
578
+ path: '/api/v1/memory',
579
+ method: 'GET'
580
+ })
597
581
 
598
- return webSocketStream
582
+ if (statusCode !== 200) {
583
+ const error = await body.text()
584
+ throw new FailedToGetRuntimeMemory(error)
585
+ }
586
+
587
+ return body.json()
588
+ }
589
+
590
+ // Resolves to null when the runtime does not run the dynamic workers scaler.
591
+ async getRuntimeWorkersScaler (pid) {
592
+ const client = this.#getUndiciClient(pid)
593
+
594
+ const { statusCode, body } = await client.request({
595
+ path: '/api/v1/workers/scaler',
596
+ method: 'GET'
597
+ })
598
+
599
+ if (statusCode === 404) {
600
+ await body.dump()
601
+ return null
602
+ }
603
+
604
+ if (statusCode !== 200) {
605
+ const error = await body.text()
606
+ throw new FailedToGetRuntimeWorkersScaler(error)
607
+ }
608
+
609
+ return body.json()
599
610
  }
600
611
 
601
612
  getRuntimeLiveLogsStream (pid) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "3.71.1-alpha.0",
3
+ "version": "4.0.0-alpha.1",
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
  "tstyche": "^7.0.0",
25
25
  "typescript": "~6.0.3",
26
- "@platformatic/runtime": "3.71.1-alpha.0",
27
- "@platformatic/service": "3.71.1-alpha.0"
26
+ "@platformatic/runtime": "4.0.0-alpha.1",
27
+ "@platformatic/service": "4.0.0-alpha.1"
28
28
  },
29
29
  "dependencies": {
30
30
  "@fastify/error": "^4.0.0",
@@ -32,12 +32,12 @@
32
32
  "pino": "^9.9.0",
33
33
  "pino-pretty": "^13.0.0",
34
34
  "table": "^6.8.1",
35
- "undici": "^7.27.2",
35
+ "undici": "^8.5.0",
36
36
  "ws": "^8.16.0",
37
- "@platformatic/foundation": "3.71.1-alpha.0"
37
+ "@platformatic/foundation": "4.0.0-alpha.1"
38
38
  },
39
39
  "engines": {
40
- "node": ">=22.19.0"
40
+ "node": ">=24.20.0"
41
41
  },
42
42
  "scripts": {
43
43
  "test": "npm run test:types && node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",