@platformatic/control 3.72.0 → 4.0.0-alpha.2

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,9 @@ 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 FailedToUpdateRuntimeMetrics: (value: string) => FastifyError
25
+ export declare const FailedToGetRuntimeMemory: (value: string) => FastifyError
26
+ export declare const FailedToGetRuntimeWorkersScaler: (value: string) => FastifyError
24
27
  export declare const FailedToStartProfiling: (value: string) => FastifyError
25
28
  export declare const FailedToStopProfiling: (value: string) => FastifyError
26
29
  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,21 @@ export const FailedToGetRuntimeMetrics = createError(
88
83
  'Failed to get runtime metrics %s.'
89
84
  )
90
85
 
86
+ export const FailedToUpdateRuntimeMetrics = createError(
87
+ `${ERROR_PREFIX}_FAILED_TO_UPDATE_RUNTIME_METRICS`,
88
+ 'Failed to update runtime metrics configuration %s.'
89
+ )
90
+
91
+ export const FailedToGetRuntimeMemory = createError(
92
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_MEMORY`,
93
+ 'Failed to get runtime memory %s.'
94
+ )
95
+
96
+ export const FailedToGetRuntimeWorkersScaler = createError(
97
+ `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_WORKERS_SCALER`,
98
+ 'Failed to get runtime workers scaler %s.'
99
+ )
100
+
91
101
  export const ProfilingAlreadyStarted = createError(
92
102
  `${ERROR_PREFIX}_PROFILING_ALREADY_STARTED`,
93
103
  '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[]
@@ -116,6 +180,81 @@ export interface RuntimeSchedulerRunResult {
116
180
  executedAt: string
117
181
  }
118
182
 
183
+ export interface RuntimeMetricsAuth {
184
+ username: string
185
+ password: string
186
+ }
187
+
188
+ export interface RuntimeMetricsCertificatePath {
189
+ path?: string
190
+ }
191
+
192
+ export type RuntimeMetricsCertificate = string | RuntimeMetricsCertificatePath
193
+
194
+ export interface RuntimeMetricsHttps {
195
+ allowHTTP1?: boolean
196
+ key: RuntimeMetricsCertificate | RuntimeMetricsCertificate[]
197
+ cert: RuntimeMetricsCertificate | RuntimeMetricsCertificate[]
198
+ requestCert?: boolean
199
+ rejectUnauthorized?: boolean
200
+ }
201
+
202
+ export interface RuntimeMetricsProbeResponse {
203
+ statusCode?: number
204
+ body?: string
205
+ }
206
+
207
+ export interface RuntimeMetricsProbe {
208
+ endpoint?: string
209
+ success?: RuntimeMetricsProbeResponse
210
+ fail?: RuntimeMetricsProbeResponse
211
+ }
212
+
213
+ export interface RuntimeMetricsExporter {
214
+ enabled?: boolean | string
215
+ endpoint: string
216
+ interval?: number | string
217
+ headers?: Record<string, string>
218
+ }
219
+
220
+ export interface RuntimeMetricsOtlpExporter extends RuntimeMetricsExporter {
221
+ serviceName?: string
222
+ serviceVersion?: string
223
+ }
224
+
225
+ export interface RuntimeMetricsHttpLabel {
226
+ name: string
227
+ header: string
228
+ default?: string
229
+ }
230
+
231
+ export interface RuntimeMetricsConfig {
232
+ enabled?: boolean | string
233
+ port?: number | string
234
+ hostname?: string
235
+ endpoint?: string
236
+ https?: RuntimeMetricsHttps
237
+ auth?: RuntimeMetricsAuth
238
+ labels?: Record<string, string>
239
+ applicationLabel?: string
240
+ httpClientMetrics?: boolean | string
241
+ readiness?: boolean | RuntimeMetricsProbe
242
+ liveness?: boolean | RuntimeMetricsProbe
243
+ healthChecksTimeouts?: number | string
244
+ plugins?: string[]
245
+ timeout?: number | string
246
+ otlpExporter?: RuntimeMetricsOtlpExporter
247
+ opentelemetry?: RuntimeMetricsExporter
248
+ httpCustomLabels?: RuntimeMetricsHttpLabel[]
249
+ }
250
+
251
+ export type RuntimeMetricsConfigUpdate = Omit<RuntimeMetricsConfig, 'enabled'> & { enabled?: boolean }
252
+
253
+ export interface RuntimeMetricsConfigUpdateResult {
254
+ success: boolean
255
+ config: RuntimeMetricsConfig
256
+ }
257
+
119
258
  export class RuntimeApiClient {
120
259
  getMatchingRuntime (options?: { pid?: string; name?: string }): Promise<Runtime>
121
260
  getRuntimes (): Promise<Runtime[]>
@@ -125,11 +264,6 @@ export class RuntimeApiClient {
125
264
  pauseRuntimeSchedulerJob (pid: number, name: string): Promise<RuntimeSchedulerJob>
126
265
  resumeRuntimeSchedulerJob (pid: number, name: string): Promise<RuntimeSchedulerJob>
127
266
  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
267
  getRuntimeApplicationConfig (pid: number, applicationId?: string): Promise<Record<string, unknown>>
134
268
  getRuntimeEnv (pid: number): Promise<Record<string, string>>
135
269
  getRuntimeOpenapi (pid: number, applicationId: string): Promise<Record<string, unknown>>
@@ -141,7 +275,12 @@ export class RuntimeApiClient {
141
275
  pid: number,
142
276
  options?: T
143
277
  ): Promise<T extends { format: 'text' } ? string : Metric[]>
144
- getRuntimeLiveMetricsStream (pid: number): WebSocketStream
278
+ getRuntimeMemory (pid: number): Promise<RuntimeMemory>
279
+ updateRuntimeMetricsConfig (
280
+ pid: number,
281
+ metricsConfig: RuntimeMetricsConfigUpdate
282
+ ): Promise<RuntimeMetricsConfigUpdateResult>
283
+ getRuntimeWorkersScaler (pid: number): Promise<WorkersScaler | null>
145
284
  getRuntimeLiveLogsStream (pid: number, startLogIndex?: number): WebSocketStream
146
285
  getRuntimeLogsStream (pid: number, logsId: string, options?: { runtimePID?: number }): Promise<ReadableBody>
147
286
  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,
@@ -29,6 +30,7 @@ import {
29
30
  FailedToStreamRuntimeLogs,
30
31
  FailedToTakeHeapSnapshot,
31
32
  FailedToUpdateRuntimeScheduler,
33
+ FailedToUpdateRuntimeMetrics,
32
34
  ProfilingAlreadyStarted,
33
35
  ProfilingNotStarted,
34
36
  RuntimeNotFound
@@ -239,23 +241,6 @@ export class RuntimeApiClient {
239
241
  return body.json()
240
242
  }
241
243
 
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
244
  async getRuntimeApplicationConfig (pid, applicationId) {
260
245
  const client = this.#getUndiciClient(pid)
261
246
 
@@ -587,15 +572,58 @@ export class RuntimeApiClient {
587
572
  return metrics
588
573
  }
589
574
 
590
- getRuntimeLiveMetricsStream (pid) {
591
- const socketPath = this.#getSocketPathFromPid(pid)
575
+ async updateRuntimeMetricsConfig (pid, metricsConfig) {
576
+ const client = this.#getUndiciClient(pid)
577
+ const { statusCode, body } = await client.request({
578
+ path: '/api/v1/metrics',
579
+ method: 'PATCH',
580
+ headers: { 'content-type': 'application/json' },
581
+ body: JSON.stringify(metricsConfig)
582
+ })
592
583
 
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)
584
+ if (statusCode !== 200) {
585
+ throw new FailedToUpdateRuntimeMetrics(await body.text())
586
+ }
597
587
 
598
- return webSocketStream
588
+ return body.json()
589
+ }
590
+
591
+ async getRuntimeMemory (pid) {
592
+ const client = this.#getUndiciClient(pid)
593
+
594
+ const { statusCode, body } = await client.request({
595
+ path: '/api/v1/memory',
596
+ method: 'GET'
597
+ })
598
+
599
+ if (statusCode !== 200) {
600
+ const error = await body.text()
601
+ throw new FailedToGetRuntimeMemory(error)
602
+ }
603
+
604
+ return body.json()
605
+ }
606
+
607
+ // Resolves to null when the runtime does not run the dynamic workers scaler.
608
+ async getRuntimeWorkersScaler (pid) {
609
+ const client = this.#getUndiciClient(pid)
610
+
611
+ const { statusCode, body } = await client.request({
612
+ path: '/api/v1/workers/scaler',
613
+ method: 'GET'
614
+ })
615
+
616
+ if (statusCode === 404) {
617
+ await body.dump()
618
+ return null
619
+ }
620
+
621
+ if (statusCode !== 200) {
622
+ const error = await body.text()
623
+ throw new FailedToGetRuntimeWorkersScaler(error)
624
+ }
625
+
626
+ return body.json()
599
627
  }
600
628
 
601
629
  getRuntimeLiveLogsStream (pid) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "3.72.0",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "Platformatic Control",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -16,28 +16,28 @@
16
16
  },
17
17
  "homepage": "https://github.com/platformatic/platformatic#readme",
18
18
  "devDependencies": {
19
- "@platformatic/runtime": "3.72.0",
20
- "@platformatic/service": "3.72.0",
21
19
  "cleaner-spec-reporter": "^0.5.0",
22
20
  "eslint": "9",
23
21
  "execa": "^9.0.0",
24
22
  "neostandard": "^0.12.0",
25
23
  "split2": "^4.2.0",
26
24
  "tstyche": "^7.0.0",
27
- "typescript": "~6.0.3"
25
+ "typescript": "~6.0.3",
26
+ "@platformatic/runtime": "4.0.0-alpha.2",
27
+ "@platformatic/service": "4.0.0-alpha.2"
28
28
  },
29
29
  "dependencies": {
30
30
  "@fastify/error": "^4.0.0",
31
- "@platformatic/foundation": "3.72.0",
32
31
  "help-me": "^5.0.0",
33
32
  "pino": "^9.9.0",
34
33
  "pino-pretty": "^13.0.0",
35
34
  "table": "^6.8.1",
36
- "undici": "^7.27.2",
37
- "ws": "^8.16.0"
35
+ "undici": "^8.5.0",
36
+ "ws": "^8.16.0",
37
+ "@platformatic/foundation": "4.0.0-alpha.2"
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",
package/.npmignore DELETED
@@ -1,2 +0,0 @@
1
- test
2
- coverage