@platformatic/control 4.0.0-alpha.1 → 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,7 @@ 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
24
25
  export declare const FailedToGetRuntimeMemory: (value: string) => FastifyError
25
26
  export declare const FailedToGetRuntimeWorkersScaler: (value: string) => FastifyError
26
27
  export declare const FailedToStartProfiling: (value: string) => FastifyError
package/lib/errors.js CHANGED
@@ -83,6 +83,11 @@ export const FailedToGetRuntimeMetrics = createError(
83
83
  'Failed to get runtime metrics %s.'
84
84
  )
85
85
 
86
+ export const FailedToUpdateRuntimeMetrics = createError(
87
+ `${ERROR_PREFIX}_FAILED_TO_UPDATE_RUNTIME_METRICS`,
88
+ 'Failed to update runtime metrics configuration %s.'
89
+ )
90
+
86
91
  export const FailedToGetRuntimeMemory = createError(
87
92
  `${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_MEMORY`,
88
93
  'Failed to get runtime memory %s.'
package/lib/index.d.ts CHANGED
@@ -180,6 +180,81 @@ export interface RuntimeSchedulerRunResult {
180
180
  executedAt: string
181
181
  }
182
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
+
183
258
  export class RuntimeApiClient {
184
259
  getMatchingRuntime (options?: { pid?: string; name?: string }): Promise<Runtime>
185
260
  getRuntimes (): Promise<Runtime[]>
@@ -201,6 +276,10 @@ export class RuntimeApiClient {
201
276
  options?: T
202
277
  ): Promise<T extends { format: 'text' } ? string : Metric[]>
203
278
  getRuntimeMemory (pid: number): Promise<RuntimeMemory>
279
+ updateRuntimeMetricsConfig (
280
+ pid: number,
281
+ metricsConfig: RuntimeMetricsConfigUpdate
282
+ ): Promise<RuntimeMetricsConfigUpdateResult>
204
283
  getRuntimeWorkersScaler (pid: number): Promise<WorkersScaler | null>
205
284
  getRuntimeLiveLogsStream (pid: number, startLogIndex?: number): WebSocketStream
206
285
  getRuntimeLogsStream (pid: number, logsId: string, options?: { runtimePID?: number }): Promise<ReadableBody>
package/lib/index.js CHANGED
@@ -30,6 +30,7 @@ import {
30
30
  FailedToStreamRuntimeLogs,
31
31
  FailedToTakeHeapSnapshot,
32
32
  FailedToUpdateRuntimeScheduler,
33
+ FailedToUpdateRuntimeMetrics,
33
34
  ProfilingAlreadyStarted,
34
35
  ProfilingNotStarted,
35
36
  RuntimeNotFound
@@ -571,6 +572,22 @@ export class RuntimeApiClient {
571
572
  return metrics
572
573
  }
573
574
 
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
+ })
583
+
584
+ if (statusCode !== 200) {
585
+ throw new FailedToUpdateRuntimeMetrics(await body.text())
586
+ }
587
+
588
+ return body.json()
589
+ }
590
+
574
591
  async getRuntimeMemory (pid) {
575
592
  const client = this.#getUndiciClient(pid)
576
593
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "4.0.0-alpha.1",
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",
@@ -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": "4.0.0-alpha.1",
27
- "@platformatic/service": "4.0.0-alpha.1"
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",
@@ -34,7 +34,7 @@
34
34
  "table": "^6.8.1",
35
35
  "undici": "^8.5.0",
36
36
  "ws": "^8.16.0",
37
- "@platformatic/foundation": "4.0.0-alpha.1"
37
+ "@platformatic/foundation": "4.0.0-alpha.2"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=24.20.0"