@platformatic/runtime 2.47.0 → 2.49.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/config.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
7
 
8
- export type HttpsSchemasPlatformaticDevPlatformaticRuntime2470Json = {
8
+ export type HttpsSchemasPlatformaticDevPlatformaticRuntime2490Json = {
9
9
  [k: string]: unknown;
10
10
  } & {
11
11
  $schema?: string;
@@ -173,6 +173,21 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime2470Json = {
173
173
  labels?: {
174
174
  [k: string]: string;
175
175
  };
176
+ readiness?:
177
+ | boolean
178
+ | {
179
+ endpoint?: string;
180
+ success?: {
181
+ statusCode?: number;
182
+ body?: string;
183
+ };
184
+ fail?: {
185
+ statusCode?: number;
186
+ body?: string;
187
+ };
188
+ };
189
+ additionalProperties?: never;
190
+ [k: string]: unknown;
176
191
  };
177
192
  telemetry?: OpenTelemetry;
178
193
  inspectorOptions?: {
@@ -2,13 +2,33 @@
2
2
 
3
3
  const fastify = require('fastify')
4
4
 
5
+ const DEFAULT_HOSTNAME = '0.0.0.0'
6
+ const DEFAULT_PORT = 9090
7
+ const DEFAULT_METRICS_ENDPOINT = '/metrics'
8
+ const DEFAULT_READINESS_ENDPOINT = '/ready'
9
+ const DEFAULT_READINESS_SUCCESS_STATUS_CODE = 200
10
+ const DEFAULT_READINESS_SUCCESS_BODY = 'OK'
11
+ const DEFAULT_READINESS_FAIL_STATUS_CODE = 500
12
+ const DEFAULT_READINESS_FAIL_BODY = 'ERR'
13
+
14
+ async function checkReadiness (runtime) {
15
+ const workers = await runtime.getWorkers()
16
+
17
+ for (const worker of Object.values(workers)) {
18
+ if (worker.status !== 'started') {
19
+ return false
20
+ }
21
+ }
22
+ return true
23
+ }
24
+
5
25
  async function startPrometheusServer (runtime, opts) {
6
26
  if (opts.enabled === false) {
7
27
  return
8
28
  }
9
- const host = opts.hostname ?? '0.0.0.0'
10
- const port = opts.port ?? 9090
11
- const metricsEndpoint = opts.endpoint ?? '/metrics'
29
+ const host = opts.hostname ?? DEFAULT_HOSTNAME
30
+ const port = opts.port ?? DEFAULT_PORT
31
+ const metricsEndpoint = opts.endpoint ?? DEFAULT_METRICS_ENDPOINT
12
32
  const auth = opts.auth ?? null
13
33
 
14
34
  const promServer = fastify({ name: 'Prometheus server' })
@@ -40,6 +60,32 @@ async function startPrometheusServer (runtime, opts) {
40
60
  },
41
61
  })
42
62
 
63
+ if (opts.readiness !== false) {
64
+ const successStatusCode = opts.readiness?.success?.statusCode ?? DEFAULT_READINESS_SUCCESS_STATUS_CODE
65
+ const successBody = opts.readiness?.success?.body ?? DEFAULT_READINESS_SUCCESS_BODY
66
+ const failStatusCode = opts.readiness?.fail?.statusCode ?? DEFAULT_READINESS_FAIL_STATUS_CODE
67
+ const failBody = opts.readiness?.fail?.body ?? DEFAULT_READINESS_FAIL_BODY
68
+
69
+ promServer.route({
70
+ url: opts.readiness?.endpoint ?? DEFAULT_READINESS_ENDPOINT,
71
+ method: 'GET',
72
+ logLevel: 'warn',
73
+ handler: async (req, reply) => {
74
+ reply.type('text/plain')
75
+
76
+ const ready = await checkReadiness(runtime)
77
+
78
+ if (ready) {
79
+ reply.status(successStatusCode)
80
+ return successBody
81
+ } else {
82
+ reply.status(failStatusCode)
83
+ return failBody
84
+ }
85
+ },
86
+ })
87
+ }
88
+
43
89
  await promServer.listen({ port, host })
44
90
  return promServer
45
91
  }
package/lib/runtime.js CHANGED
@@ -66,7 +66,7 @@ class Runtime extends EventEmitter {
66
66
  #loggerDestination
67
67
  #metrics
68
68
  #metricsTimeout
69
- #status
69
+ #status // starting, started, stopping, stopped, closed
70
70
  #meshInterceptor
71
71
  #dispatcher
72
72
  #managementApi
package/lib/schema.js CHANGED
@@ -380,9 +380,37 @@ const platformaticRuntimeSchema = {
380
380
  labels: {
381
381
  type: 'object',
382
382
  additionalProperties: { type: 'string' }
383
- }
384
- },
385
- additionalProperties: false
383
+ },
384
+ readiness: {
385
+ anyOf: [
386
+ { type: 'boolean' },
387
+ {
388
+ type: 'object',
389
+ properties: {
390
+ endpoint: { type: 'string' },
391
+ success: {
392
+ type: 'object',
393
+ properties: {
394
+ statusCode: { type: 'number' },
395
+ body: { type: 'string' }
396
+ },
397
+ additionalProperties: false
398
+ },
399
+ fail: {
400
+ type: 'object',
401
+ properties: {
402
+ statusCode: { type: 'number' },
403
+ body: { type: 'string' }
404
+ },
405
+ additionalProperties: false
406
+ }
407
+ },
408
+ additionalProperties: false
409
+ }
410
+ ]
411
+ },
412
+ additionalProperties: false
413
+ }
386
414
  }
387
415
  ]
388
416
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "2.47.0",
3
+ "version": "2.49.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -37,12 +37,12 @@
37
37
  "typescript": "^5.5.4",
38
38
  "undici-oidc-interceptor": "^0.5.0",
39
39
  "why-is-node-running": "^2.2.2",
40
- "@platformatic/composer": "2.47.0",
41
- "@platformatic/db": "2.47.0",
42
- "@platformatic/node": "2.47.0",
43
- "@platformatic/service": "2.47.0",
44
- "@platformatic/sql-mapper": "2.47.0",
45
- "@platformatic/sql-graphql": "2.47.0"
40
+ "@platformatic/composer": "2.49.0",
41
+ "@platformatic/db": "2.49.0",
42
+ "@platformatic/service": "2.49.0",
43
+ "@platformatic/node": "2.49.0",
44
+ "@platformatic/sql-graphql": "2.49.0",
45
+ "@platformatic/sql-mapper": "2.49.0"
46
46
  },
47
47
  "dependencies": {
48
48
  "@fastify/accepts": "^5.0.0",
@@ -76,13 +76,13 @@
76
76
  "undici": "^7.0.0",
77
77
  "undici-thread-interceptor": "^0.13.1",
78
78
  "ws": "^8.16.0",
79
- "@platformatic/basic": "2.47.0",
80
- "@platformatic/generators": "2.47.0",
81
- "@platformatic/config": "2.47.0",
82
- "@platformatic/itc": "2.47.0",
83
- "@platformatic/ts-compiler": "2.47.0",
84
- "@platformatic/telemetry": "2.47.0",
85
- "@platformatic/utils": "2.47.0"
79
+ "@platformatic/basic": "2.49.0",
80
+ "@platformatic/config": "2.49.0",
81
+ "@platformatic/generators": "2.49.0",
82
+ "@platformatic/itc": "2.49.0",
83
+ "@platformatic/telemetry": "2.49.0",
84
+ "@platformatic/ts-compiler": "2.49.0",
85
+ "@platformatic/utils": "2.49.0"
86
86
  },
87
87
  "scripts": {
88
88
  "test": "npm run lint && borp --concurrency=1 --timeout=300000 && tsd",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.47.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.49.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1153,9 +1153,49 @@
1153
1153
  "additionalProperties": {
1154
1154
  "type": "string"
1155
1155
  }
1156
- }
1157
- },
1158
- "additionalProperties": false
1156
+ },
1157
+ "readiness": {
1158
+ "anyOf": [
1159
+ {
1160
+ "type": "boolean"
1161
+ },
1162
+ {
1163
+ "type": "object",
1164
+ "properties": {
1165
+ "endpoint": {
1166
+ "type": "string"
1167
+ },
1168
+ "success": {
1169
+ "type": "object",
1170
+ "properties": {
1171
+ "statusCode": {
1172
+ "type": "number"
1173
+ },
1174
+ "body": {
1175
+ "type": "string"
1176
+ }
1177
+ },
1178
+ "additionalProperties": false
1179
+ },
1180
+ "fail": {
1181
+ "type": "object",
1182
+ "properties": {
1183
+ "statusCode": {
1184
+ "type": "number"
1185
+ },
1186
+ "body": {
1187
+ "type": "string"
1188
+ }
1189
+ },
1190
+ "additionalProperties": false
1191
+ }
1192
+ },
1193
+ "additionalProperties": false
1194
+ }
1195
+ ]
1196
+ },
1197
+ "additionalProperties": false
1198
+ }
1159
1199
  }
1160
1200
  ]
1161
1201
  },