@platformatic/runtime 3.0.0-alpha.4 → 3.0.0-alpha.6
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 +10 -7
- package/eslint.config.js +2 -4
- package/index.d.ts +11 -11
- package/index.js +35 -46
- package/lib/config.js +80 -102
- package/lib/dependencies.js +27 -29
- package/lib/errors.js +65 -99
- package/lib/generator.js +160 -164
- package/lib/logger.js +6 -8
- package/lib/management-api.js +36 -39
- package/lib/prom-server.js +10 -14
- package/lib/runtime.js +752 -715
- package/lib/scheduler.js +13 -15
- package/lib/schema.js +11 -8
- package/lib/shared-http-cache.js +5 -9
- package/lib/upgrade.js +5 -9
- package/lib/utils.js +6 -14
- package/lib/version.js +7 -0
- package/lib/versions/v1.36.0.js +2 -4
- package/lib/versions/v1.5.0.js +2 -4
- package/lib/versions/v2.0.0.js +3 -5
- package/lib/versions/v3.0.0.js +16 -0
- package/lib/worker/{app.js → controller.js} +46 -56
- package/lib/worker/http-cache.js +11 -14
- package/lib/worker/interceptors.js +14 -18
- package/lib/worker/itc.js +74 -74
- package/lib/worker/main.js +45 -49
- package/lib/worker/messaging.js +23 -27
- package/lib/worker/round-robin-map.js +23 -19
- package/lib/worker/shared-context.js +2 -6
- package/lib/worker/symbols.js +12 -29
- package/package.json +21 -21
- package/schema.json +254 -20
package/lib/management-api.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const ws = require('ws')
|
|
1
|
+
import fastifyAccepts from '@fastify/accepts'
|
|
2
|
+
import fastifyWebsocket from '@fastify/websocket'
|
|
3
|
+
import { createDirectory, safeRemove } from '@platformatic/foundation'
|
|
4
|
+
import fastify from 'fastify'
|
|
5
|
+
import { platform, tmpdir } from 'node:os'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { createWebSocketStream } from 'ws'
|
|
9
8
|
|
|
10
9
|
const PLATFORMATIC_TMP_DIR = join(tmpdir(), 'platformatic', 'runtimes')
|
|
11
10
|
|
|
12
|
-
async function managementApiPlugin (app, opts) {
|
|
13
|
-
app.register(
|
|
11
|
+
export async function managementApiPlugin (app, opts) {
|
|
12
|
+
app.register(fastifyAccepts)
|
|
14
13
|
|
|
15
14
|
const runtime = opts.runtime
|
|
16
15
|
|
|
@@ -32,62 +31,62 @@ async function managementApiPlugin (app, opts) {
|
|
|
32
31
|
})
|
|
33
32
|
|
|
34
33
|
app.post('/stop', async () => {
|
|
35
|
-
app.log.debug('stop
|
|
34
|
+
app.log.debug('stop applications')
|
|
36
35
|
await runtime.close()
|
|
37
36
|
})
|
|
38
37
|
|
|
39
38
|
app.post('/restart', async () => {
|
|
40
|
-
app.log.debug('restart
|
|
39
|
+
app.log.debug('restart applications')
|
|
41
40
|
await runtime.restart()
|
|
42
41
|
})
|
|
43
42
|
|
|
44
|
-
app.get('/
|
|
45
|
-
return runtime.
|
|
43
|
+
app.get('/applications', async () => {
|
|
44
|
+
return runtime.getApplications()
|
|
46
45
|
})
|
|
47
46
|
|
|
48
|
-
app.get('/
|
|
47
|
+
app.get('/applications/:id', async request => {
|
|
49
48
|
const { id } = request.params
|
|
50
|
-
app.log.debug('get
|
|
51
|
-
return runtime.
|
|
49
|
+
app.log.debug('get application details', { id })
|
|
50
|
+
return runtime.getApplicationDetails(id)
|
|
52
51
|
})
|
|
53
52
|
|
|
54
|
-
app.get('/
|
|
53
|
+
app.get('/applications/:id/config', async request => {
|
|
55
54
|
const { id } = request.params
|
|
56
|
-
app.log.debug('get
|
|
57
|
-
return runtime.
|
|
55
|
+
app.log.debug('get application config', { id })
|
|
56
|
+
return runtime.getApplicationConfig(id)
|
|
58
57
|
})
|
|
59
58
|
|
|
60
|
-
app.get('/
|
|
59
|
+
app.get('/applications/:id/env', async request => {
|
|
61
60
|
const { id } = request.params
|
|
62
|
-
app.log.debug('get
|
|
63
|
-
return runtime.
|
|
61
|
+
app.log.debug('get application config', { id })
|
|
62
|
+
return runtime.getApplicationEnv(id)
|
|
64
63
|
})
|
|
65
64
|
|
|
66
|
-
app.get('/
|
|
65
|
+
app.get('/applications/:id/openapi-schema', async request => {
|
|
67
66
|
const { id } = request.params
|
|
68
67
|
app.log.debug('get openapi-schema', { id })
|
|
69
|
-
return runtime.
|
|
68
|
+
return runtime.getApplicationOpenapiSchema(id)
|
|
70
69
|
})
|
|
71
70
|
|
|
72
|
-
app.get('/
|
|
71
|
+
app.get('/applications/:id/graphql-schema', async request => {
|
|
73
72
|
const { id } = request.params
|
|
74
73
|
app.log.debug('get graphql-schema', { id })
|
|
75
|
-
return runtime.
|
|
74
|
+
return runtime.getApplicationGraphqlSchema(id)
|
|
76
75
|
})
|
|
77
76
|
|
|
78
|
-
app.post('/
|
|
77
|
+
app.post('/applications/:id/start', async request => {
|
|
79
78
|
const { id } = request.params
|
|
80
|
-
app.log.debug('start
|
|
81
|
-
await runtime.
|
|
79
|
+
app.log.debug('start application', { id })
|
|
80
|
+
await runtime.startApplication(id)
|
|
82
81
|
})
|
|
83
82
|
|
|
84
|
-
app.post('/
|
|
83
|
+
app.post('/applications/:id/stop', async request => {
|
|
85
84
|
const { id } = request.params
|
|
86
|
-
app.log.debug('stop
|
|
87
|
-
await runtime.
|
|
85
|
+
app.log.debug('stop application', { id })
|
|
86
|
+
await runtime.stopApplication(id)
|
|
88
87
|
})
|
|
89
88
|
|
|
90
|
-
app.all('/
|
|
89
|
+
app.all('/applications/:id/proxy/*', async (request, reply) => {
|
|
91
90
|
const { id, '*': requestUrl } = request.params
|
|
92
91
|
app.log.debug('proxy request', { id, requestUrl })
|
|
93
92
|
|
|
@@ -149,11 +148,11 @@ async function managementApiPlugin (app, opts) {
|
|
|
149
148
|
})
|
|
150
149
|
|
|
151
150
|
app.get('/logs/live', { websocket: true }, async (socket, req) => {
|
|
152
|
-
runtime.addLoggerDestination(
|
|
151
|
+
runtime.addLoggerDestination(createWebSocketStream(socket))
|
|
153
152
|
})
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
async function startManagementApi (runtime, root) {
|
|
155
|
+
export async function startManagementApi (runtime, root) {
|
|
157
156
|
const runtimePID = process.pid
|
|
158
157
|
|
|
159
158
|
try {
|
|
@@ -170,7 +169,7 @@ async function startManagementApi (runtime, root) {
|
|
|
170
169
|
}
|
|
171
170
|
|
|
172
171
|
const managementApi = fastify()
|
|
173
|
-
managementApi.register(
|
|
172
|
+
managementApi.register(fastifyWebsocket)
|
|
174
173
|
managementApi.register(managementApiPlugin, { runtime, prefix: '/api/v1' })
|
|
175
174
|
|
|
176
175
|
managementApi.addHook('onClose', async () => {
|
|
@@ -190,5 +189,3 @@ async function startManagementApi (runtime, root) {
|
|
|
190
189
|
process.exit(1)
|
|
191
190
|
}
|
|
192
191
|
}
|
|
193
|
-
|
|
194
|
-
module.exports = { startManagementApi, managementApiPlugin }
|
package/lib/prom-server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import fastifyAccepts from '@fastify/accepts'
|
|
2
|
+
import fastifyBasicAuth from '@fastify/basic-auth'
|
|
3
|
+
import fastify from 'fastify'
|
|
4
4
|
|
|
5
5
|
const DEFAULT_HOSTNAME = '0.0.0.0'
|
|
6
6
|
const DEFAULT_PORT = 9090
|
|
@@ -67,7 +67,7 @@ async function checkLiveness (runtime) {
|
|
|
67
67
|
return { response, status }
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
async function startPrometheusServer (runtime, opts) {
|
|
70
|
+
export async function startPrometheusServer (runtime, opts) {
|
|
71
71
|
if (opts.enabled === false) {
|
|
72
72
|
return
|
|
73
73
|
}
|
|
@@ -77,19 +77,19 @@ async function startPrometheusServer (runtime, opts) {
|
|
|
77
77
|
const auth = opts.auth ?? null
|
|
78
78
|
|
|
79
79
|
const promServer = fastify({ name: 'Prometheus server' })
|
|
80
|
-
promServer.register(
|
|
80
|
+
promServer.register(fastifyAccepts)
|
|
81
81
|
|
|
82
82
|
let onRequestHook
|
|
83
83
|
if (auth) {
|
|
84
84
|
const { username, password } = auth
|
|
85
85
|
|
|
86
|
-
await promServer.register(
|
|
86
|
+
await promServer.register(fastifyBasicAuth, {
|
|
87
87
|
validate: function (user, pass, req, reply, done) {
|
|
88
88
|
if (username !== user || password !== pass) {
|
|
89
89
|
return reply.code(401).send({ message: 'Unauthorized' })
|
|
90
90
|
}
|
|
91
91
|
return done()
|
|
92
|
-
}
|
|
92
|
+
}
|
|
93
93
|
})
|
|
94
94
|
onRequestHook = promServer.basicAuth
|
|
95
95
|
}
|
|
@@ -129,7 +129,7 @@ async function startPrometheusServer (runtime, opts) {
|
|
|
129
129
|
reply.type('text/plain')
|
|
130
130
|
}
|
|
131
131
|
return (await runtime.getMetrics(reqType)).metrics
|
|
132
|
-
}
|
|
132
|
+
}
|
|
133
133
|
})
|
|
134
134
|
|
|
135
135
|
if (opts.readiness !== false) {
|
|
@@ -167,7 +167,7 @@ async function startPrometheusServer (runtime, opts) {
|
|
|
167
167
|
reply.status(failStatusCode).send(failBody)
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
-
}
|
|
170
|
+
}
|
|
171
171
|
})
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -206,14 +206,10 @@ async function startPrometheusServer (runtime, opts) {
|
|
|
206
206
|
reply.status(failStatusCode).send(readiness?.body || failBody)
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
}
|
|
209
|
+
}
|
|
210
210
|
})
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
await promServer.listen({ port, host })
|
|
214
214
|
return promServer
|
|
215
215
|
}
|
|
216
|
-
|
|
217
|
-
module.exports = {
|
|
218
|
-
startPrometheusServer,
|
|
219
|
-
}
|