@platformatic/runtime 2.0.0-alpha.2 → 2.0.0-alpha.21
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 +218 -0
- package/eslint.config.js +8 -0
- package/fixtures/botched-start/platformatic.runtime.json +1 -1
- package/fixtures/botched-start/services/a/platformatic.service.json +1 -1
- package/fixtures/composerApp/platformatic.composer.json +1 -1
- package/fixtures/configs/invalid-entrypoint.json +1 -1
- package/fixtures/configs/invalid-schema-type.config.json +1 -1
- package/fixtures/configs/{invalid-autoload-with-services.json → invalid-web-with-services.json} +9 -5
- package/fixtures/configs/missing-property.config.json +1 -1
- package/fixtures/configs/missing-service-config.json +1 -1
- package/fixtures/configs/monorepo-composer-no-autoload.json +2 -2
- package/fixtures/configs/monorepo-composer.json +2 -2
- package/fixtures/configs/monorepo-create-cycle.json +2 -2
- package/fixtures/configs/monorepo-missing-dependencies.json +2 -2
- package/fixtures/configs/monorepo-no-cycles.json +2 -2
- package/fixtures/configs/monorepo-openapi.json +2 -2
- package/fixtures/configs/{monorepo-hotreload-env.json → monorepo-watch-env.json} +2 -2
- package/fixtures/configs/monorepo-watch-single.json +12 -0
- package/fixtures/configs/monorepo-watch.json +24 -9
- package/fixtures/configs/monorepo-with-dependencies.json +2 -2
- package/fixtures/configs/monorepo-with-management-api-without-metrics.json +21 -0
- package/fixtures/configs/monorepo-with-management-api.json +2 -2
- package/fixtures/configs/{monorepo-hotreload.json → monorepo-with-metrics.json} +5 -4
- package/fixtures/configs/monorepo.json +2 -2
- package/fixtures/configs/no-services.config.json +1 -1
- package/fixtures/configs/no-sources.config.json +1 -1
- package/fixtures/configs/service-throws-on-start.json +1 -1
- package/fixtures/configs/service-with-env-port.json +2 -2
- package/fixtures/configs/service-with-stdio.json +12 -0
- package/fixtures/configs/{hotreload.json → watch.json} +2 -2
- package/fixtures/crash-on-bootstrap/platformatic.runtime.json +15 -0
- package/fixtures/crash-on-bootstrap/services/service-1/platformatic.service.json +14 -0
- package/fixtures/crash-on-bootstrap/services/service-1/plugin.js +5 -0
- package/fixtures/crash-on-bootstrap/services/service-2/platformatic.service.json +14 -0
- package/fixtures/crash-on-bootstrap/services/service-2/plugin.js +5 -0
- package/fixtures/dbApp/platformatic.db.json +1 -1
- package/fixtures/dbAppNoName/platformatic.db.json +1 -1
- package/fixtures/dbAppNoPackageJson/platformatic.db.json +1 -1
- package/fixtures/dbAppWithMigrationError/platformatic.db.json +1 -1
- package/fixtures/do-not-reload-dependencies/platformatic.service.json +1 -1
- package/fixtures/do-not-restart-on-crash/platformatic.runtime.json +3 -2
- package/fixtures/do-not-restart-on-crash/services/a/platformatic.service.json +8 -6
- package/fixtures/express/platformatic.runtime.json +1 -1
- package/fixtures/express/services/a/platformatic.service.json +1 -1
- package/fixtures/express/services/b/platformatic.service.json +1 -1
- package/fixtures/external-client/platformatic.service.json +1 -1
- package/fixtures/interceptors/idp.js +2 -2
- package/fixtures/interceptors/platformatic.runtime.json +1 -1
- package/fixtures/interceptors/services/a/platformatic.service.json +1 -1
- package/fixtures/interceptors-2/platformatic.runtime.json +1 -1
- package/fixtures/interceptors-2/services/a/platformatic.service.json +1 -1
- package/fixtures/leven/platformatic.runtime.json +2 -2
- package/fixtures/leven/services/deeply-spittle/platformatic.service.json +1 -1
- package/fixtures/leven/services/rainy-empire/platformatic.composer.json +1 -1
- package/fixtures/management-api/platformatic.json +8 -3
- package/fixtures/management-api/services/service-1/platformatic.json +8 -5
- package/fixtures/management-api/services/service-1/plugin.js +4 -3
- package/fixtures/management-api/services/service-2/platformatic.json +1 -1
- package/fixtures/management-api/services/service-db/platformatic.db.json +1 -1
- package/fixtures/management-api-custom-labels/platformatic.json +2 -2
- package/fixtures/management-api-custom-labels/services/service-1/platformatic.json +1 -1
- package/fixtures/management-api-custom-labels/services/service-1/plugin.js +4 -3
- package/fixtures/management-api-custom-labels/services/service-2/platformatic.json +1 -1
- package/fixtures/management-api-custom-labels/services/service-db/platformatic.db.json +1 -1
- package/fixtures/management-api-without-metrics/platformatic.json +3 -2
- package/fixtures/management-api-without-metrics/services/service-1/platformatic.json +1 -1
- package/fixtures/monorepo/composerApp/platformatic.composer.json +1 -1
- package/fixtures/monorepo/dbApp/platformatic.db.json +1 -1
- package/fixtures/monorepo/serviceApp/platformatic.service.json +3 -2
- package/fixtures/monorepo/serviceApp/with-logger/with-logger.cjs +2 -2
- package/fixtures/monorepo/serviceApp/with-logger/with-logger.d.ts +7 -7
- package/fixtures/monorepo/serviceAppWithLogger/platformatic.service.json +1 -1
- package/fixtures/monorepo/serviceAppWithLogger/plugin.js +12 -0
- package/fixtures/monorepo/serviceAppWithMultiplePlugins/platformatic.service.json +3 -2
- package/fixtures/monorepo-missing-dependencies/composer/platformatic.json +1 -1
- package/fixtures/monorepo-openapi/serviceAppWithoutOpenapi/platformatic.service.json +1 -1
- package/fixtures/monorepo-watch/service1/platformatic.service.json +1 -1
- package/fixtures/monorepo-with-dependencies/main/platformatic.json +1 -1
- package/fixtures/monorepo-with-dependencies/service-1/platformatic.json +1 -1
- package/fixtures/monorepo-with-dependencies/service-2/platformatic.json +1 -1
- package/fixtures/no-env.service.json +1 -1
- package/fixtures/preload/platformatic.runtime.json +1 -1
- package/fixtures/preload/services/a/platformatic.service.json +1 -1
- package/fixtures/prom-server/platformatic.json +2 -2
- package/fixtures/prom-server/services/service-1/platformatic.json +1 -1
- package/fixtures/prom-server/services/service-2/platformatic.json +1 -1
- package/fixtures/restart-on-crash/platformatic.runtime.json +1 -1
- package/fixtures/restart-on-crash/services/a/platformatic.service.json +8 -6
- package/fixtures/sample-runtime/package.json +3 -3
- package/fixtures/sample-runtime/platformatic.json +2 -2
- package/fixtures/sample-runtime/services/rival/package.json +2 -2
- package/fixtures/sample-runtime/services/rival/platformatic.json +1 -1
- package/fixtures/sample-runtime-with-2-services/package.json +3 -3
- package/fixtures/sample-runtime-with-2-services/platformatic.json +2 -2
- package/fixtures/sample-runtime-with-2-services/services/foobar/package.json +2 -2
- package/fixtures/sample-runtime-with-2-services/services/foobar/platformatic.json +1 -1
- package/fixtures/sample-runtime-with-2-services/services/rival/package.json +2 -2
- package/fixtures/sample-runtime-with-2-services/services/rival/platformatic.json +1 -1
- package/fixtures/server/logger-transport/platformatic.runtime.json +2 -2
- package/fixtures/server/logger-transport/services/echo/platformatic.service.json +1 -1
- package/fixtures/server/overrides-service/platformatic.runtime.json +2 -2
- package/fixtures/server/overrides-service/services/echo/platformatic.service.json +1 -1
- package/fixtures/server/runtime-server/platformatic.runtime.json +2 -2
- package/fixtures/server/runtime-server/services/echo/platformatic.service.json +1 -1
- package/fixtures/serviceAppThrowsOnStart/platformatic.service.json +1 -1
- package/fixtures/stackables/node_modules/foo/foo.js +2 -1
- package/fixtures/start-command-in-runtime.js +1 -1
- package/fixtures/stdio/platformatic.service.json +6 -0
- package/fixtures/stdio/plugin.js +24 -0
- package/fixtures/telemetry/platformatic.runtime.json +2 -2
- package/fixtures/telemetry/services/echo/platformatic.service.json +1 -1
- package/fixtures/telemetry/services/echo/routes/span.js +16 -2
- package/fixtures/telemetry/services/service-1/platformatic.service.json +19 -0
- package/fixtures/telemetry/services/service-1/routes/echo.js +7 -0
- package/fixtures/typescript/platformatic.runtime.json +2 -2
- package/fixtures/typescript/services/composer/platformatic.composer.json +1 -1
- package/fixtures/typescript/services/movies/global.d.ts +2 -3
- package/fixtures/typescript/services/movies/platformatic.db.json +1 -1
- package/fixtures/typescript/services/movies/types/Movie.d.ts +3 -3
- package/fixtures/typescript/services/movies/types/index.d.ts +6 -6
- package/fixtures/typescript/services/titles/client/client.d.ts +35 -35
- package/fixtures/typescript/services/titles/platformatic.service.json +1 -1
- package/fixtures/typescript-custom-flags/platformatic.runtime.json +2 -2
- package/fixtures/typescript-custom-flags/services/composer/platformatic.composer.json +1 -1
- package/fixtures/typescript-custom-flags/services/movies/global.d.ts +2 -3
- package/fixtures/typescript-custom-flags/services/movies/platformatic.db.json +1 -1
- package/fixtures/typescript-custom-flags/services/movies/types/Movie.d.ts +3 -3
- package/fixtures/typescript-custom-flags/services/movies/types/index.d.ts +6 -6
- package/fixtures/typescript-custom-flags/services/titles/client/client.d.ts +35 -35
- package/fixtures/typescript-custom-flags/services/titles/platformatic.service.json +1 -1
- package/fixtures/typescript-no-env/platformatic.runtime.json +2 -2
- package/fixtures/typescript-no-env/services/composer/platformatic.composer.json +1 -1
- package/fixtures/typescript-no-env/services/movies/global.d.ts +2 -3
- package/fixtures/typescript-no-env/services/movies/platformatic.db.json +1 -1
- package/fixtures/typescript-no-env/services/movies/types/Movie.d.ts +3 -3
- package/fixtures/typescript-no-env/services/movies/types/index.d.ts +6 -6
- package/fixtures/typescript-no-env/services/titles/client/client.d.ts +35 -35
- package/fixtures/typescript-no-env/services/titles/platformatic.service.json +1 -1
- package/index.d.ts +7 -8
- package/index.js +18 -10
- package/index.test-d.ts +10 -12
- package/lib/build-server.js +11 -13
- package/lib/compile.js +11 -10
- package/lib/config.js +32 -19
- package/lib/dependencies.js +2 -1
- package/lib/errors.js +6 -3
- package/lib/generator/errors.js +1 -1
- package/lib/generator/runtime-generator.d.ts +15 -15
- package/lib/generator/runtime-generator.js +95 -66
- package/lib/logger.js +55 -0
- package/lib/management-api.js +40 -46
- package/lib/prom-server.js +5 -9
- package/lib/runtime.js +1012 -0
- package/lib/schema.js +109 -91
- package/lib/start.js +51 -108
- package/lib/upgrade.js +2 -5
- package/lib/utils.js +65 -1
- package/lib/versions/v1.36.0.js +1 -1
- package/lib/versions/v1.5.0.js +1 -1
- package/lib/versions/v2.0.0.js +26 -0
- package/lib/worker/app.js +266 -0
- package/lib/worker/default-stackable.js +33 -0
- package/lib/worker/itc.js +162 -0
- package/lib/worker/main.js +135 -0
- package/lib/worker/metrics.js +106 -0
- package/lib/worker/symbols.js +7 -0
- package/package.json +36 -34
- package/runtime.mjs +5 -5
- package/schema.json +639 -0
- package/lib/api-client.js +0 -500
- package/lib/api.js +0 -420
- package/lib/app.js +0 -397
- package/lib/load-config.js +0 -12
- package/lib/loader.mjs +0 -103
- package/lib/message-port-writable.js +0 -50
- package/lib/worker.js +0 -182
- /package/lib/{interceptors.js → worker/interceptors.js} +0 -0
package/lib/logger.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { join } = require('node:path')
|
|
4
|
+
const { isatty } = require('node:tty')
|
|
5
|
+
|
|
6
|
+
const pino = require('pino')
|
|
7
|
+
const pretty = require('pino-pretty')
|
|
8
|
+
|
|
9
|
+
function createLogger (config, runtimeLogsDir) {
|
|
10
|
+
const loggerConfig = { ...config.logger }
|
|
11
|
+
const cliStream = isatty(1) ? pretty() : pino.destination(1)
|
|
12
|
+
|
|
13
|
+
if (!config.managementApi) {
|
|
14
|
+
return [pino(loggerConfig, cliStream), cliStream]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const multiStream = pino.multistream([
|
|
18
|
+
{ stream: cliStream, level: loggerConfig.level || 'info' },
|
|
19
|
+
])
|
|
20
|
+
|
|
21
|
+
if (loggerConfig.transport) {
|
|
22
|
+
const transport = pino.transport(loggerConfig.transport)
|
|
23
|
+
multiStream.add({ level: loggerConfig.level || 'info', stream: transport })
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (config.managementApi) {
|
|
27
|
+
const logsFileMb = 5
|
|
28
|
+
const logsLimitMb = config.managementApi?.logs?.maxSize || 200
|
|
29
|
+
|
|
30
|
+
let logsLimitCount = Math.ceil(logsLimitMb / logsFileMb) - 1
|
|
31
|
+
if (logsLimitCount < 1) {
|
|
32
|
+
logsLimitCount = 1
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const pinoRoll = pino.transport({
|
|
36
|
+
target: 'pino-roll',
|
|
37
|
+
options: {
|
|
38
|
+
file: join(runtimeLogsDir, 'logs'),
|
|
39
|
+
mode: 0o600,
|
|
40
|
+
size: logsFileMb + 'm',
|
|
41
|
+
mkdir: true,
|
|
42
|
+
fsync: true,
|
|
43
|
+
limit: {
|
|
44
|
+
count: logsLimitCount,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
multiStream.add({ level: 'trace', stream: pinoRoll })
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return [pino({ level: 'trace' }, multiStream), multiStream]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = { createLogger }
|
package/lib/management-api.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { tmpdir } = require('node:os')
|
|
4
|
-
const { platform } = require('node:os')
|
|
3
|
+
const { platform, tmpdir } = require('node:os')
|
|
5
4
|
const { join } = require('node:path')
|
|
6
|
-
const {
|
|
5
|
+
const { createDirectory, safeRemove } = require('@platformatic/utils')
|
|
6
|
+
|
|
7
7
|
const fastify = require('fastify')
|
|
8
8
|
const ws = require('ws')
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
const errors = require('./errors')
|
|
11
|
+
const { getRuntimeLogsDir } = require('./utils')
|
|
11
12
|
|
|
12
13
|
const PLATFORMATIC_TMP_DIR = join(tmpdir(), 'platformatic', 'runtimes')
|
|
13
14
|
|
|
14
15
|
async function managementApiPlugin (app, opts) {
|
|
15
16
|
app.log.warn(
|
|
16
17
|
'Runtime Management API is in the experimental stage. ' +
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
'The feature is not subject to semantic versioning rules. ' +
|
|
19
|
+
'Non-backward compatible changes or removal may occur in any future release. ' +
|
|
20
|
+
'Use of the feature is not recommended in production environments.'
|
|
20
21
|
)
|
|
21
22
|
|
|
22
23
|
const runtime = opts.runtime
|
|
@@ -30,16 +31,16 @@ async function managementApiPlugin (app, opts) {
|
|
|
30
31
|
})
|
|
31
32
|
|
|
32
33
|
app.get('/env', async () => {
|
|
33
|
-
return process.env
|
|
34
|
+
return { ...process.env, ...runtime.getRuntimeEnv() }
|
|
34
35
|
})
|
|
35
36
|
|
|
36
37
|
app.post('/stop', async () => {
|
|
37
38
|
app.log.debug('stop services')
|
|
38
|
-
await runtime.close()
|
|
39
|
+
await runtime.close(true)
|
|
39
40
|
})
|
|
40
41
|
|
|
41
|
-
app.post('/
|
|
42
|
-
app.log.debug('
|
|
42
|
+
app.post('/restart', async () => {
|
|
43
|
+
app.log.debug('restart services')
|
|
43
44
|
await runtime.restart()
|
|
44
45
|
})
|
|
45
46
|
|
|
@@ -47,40 +48,46 @@ async function managementApiPlugin (app, opts) {
|
|
|
47
48
|
return runtime.getServices()
|
|
48
49
|
})
|
|
49
50
|
|
|
50
|
-
app.get('/services/:id', async
|
|
51
|
+
app.get('/services/:id', async request => {
|
|
51
52
|
const { id } = request.params
|
|
52
53
|
app.log.debug('get service details', { id })
|
|
53
54
|
return runtime.getServiceDetails(id)
|
|
54
55
|
})
|
|
55
56
|
|
|
56
|
-
app.get('/services/:id/config', async
|
|
57
|
+
app.get('/services/:id/config', async request => {
|
|
57
58
|
const { id } = request.params
|
|
58
59
|
app.log.debug('get service config', { id })
|
|
59
60
|
return runtime.getServiceConfig(id)
|
|
60
61
|
})
|
|
61
62
|
|
|
62
|
-
app.get('/services/:id/
|
|
63
|
+
app.get('/services/:id/env', async request => {
|
|
64
|
+
const { id } = request.params
|
|
65
|
+
app.log.debug('get service config', { id })
|
|
66
|
+
return runtime.getServiceEnv(id)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
app.get('/services/:id/openapi-schema', async request => {
|
|
63
70
|
const { id } = request.params
|
|
64
71
|
app.log.debug('get openapi-schema', { id })
|
|
65
72
|
return runtime.getServiceOpenapiSchema(id)
|
|
66
73
|
})
|
|
67
74
|
|
|
68
|
-
app.get('/services/:id/graphql-schema', async
|
|
75
|
+
app.get('/services/:id/graphql-schema', async request => {
|
|
69
76
|
const { id } = request.params
|
|
70
77
|
app.log.debug('get graphql-schema', { id })
|
|
71
78
|
return runtime.getServiceGraphqlSchema(id)
|
|
72
79
|
})
|
|
73
80
|
|
|
74
|
-
app.post('/services/:id/start', async
|
|
81
|
+
app.post('/services/:id/start', async request => {
|
|
75
82
|
const { id } = request.params
|
|
76
83
|
app.log.debug('start service', { id })
|
|
77
84
|
await runtime.startService(id)
|
|
78
85
|
})
|
|
79
86
|
|
|
80
|
-
app.post('/services/:id/stop', async
|
|
87
|
+
app.post('/services/:id/stop', async request => {
|
|
81
88
|
const { id } = request.params
|
|
82
89
|
app.log.debug('stop service', { id })
|
|
83
|
-
await runtime.
|
|
90
|
+
await runtime._stopService(id)
|
|
84
91
|
})
|
|
85
92
|
|
|
86
93
|
app.all('/services/:id/proxy/*', async (request, reply) => {
|
|
@@ -102,22 +109,20 @@ async function managementApiPlugin (app, opts) {
|
|
|
102
109
|
|
|
103
110
|
const res = await runtime.inject(id, injectParams)
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
delete res.headers['content-length']
|
|
113
|
+
delete res.headers['transfer-encoding']
|
|
114
|
+
|
|
115
|
+
reply.code(res.statusCode).headers(res.headers).send(res.body)
|
|
109
116
|
})
|
|
110
117
|
|
|
111
|
-
app.get('/metrics/live', { websocket: true }, async
|
|
118
|
+
app.get('/metrics/live', { websocket: true }, async socket => {
|
|
112
119
|
const cachedMetrics = runtime.getCachedMetrics()
|
|
113
120
|
if (cachedMetrics.length > 0) {
|
|
114
|
-
const serializedMetrics = cachedMetrics
|
|
115
|
-
.map((metric) => JSON.stringify(metric))
|
|
116
|
-
.join('\n')
|
|
121
|
+
const serializedMetrics = cachedMetrics.map(metric => JSON.stringify(metric)).join('\n')
|
|
117
122
|
socket.send(serializedMetrics + '\n')
|
|
118
123
|
}
|
|
119
124
|
|
|
120
|
-
const eventHandler =
|
|
125
|
+
const eventHandler = metrics => {
|
|
121
126
|
const serializedMetrics = JSON.stringify(metrics)
|
|
122
127
|
socket.send(serializedMetrics + '\n')
|
|
123
128
|
}
|
|
@@ -147,7 +152,7 @@ async function managementApiPlugin (app, opts) {
|
|
|
147
152
|
runtime.pipeLogsStream(stream, req.log, startLogId)
|
|
148
153
|
})
|
|
149
154
|
|
|
150
|
-
app.get('/logs/indexes', async
|
|
155
|
+
app.get('/logs/indexes', async req => {
|
|
151
156
|
const returnAllIds = req.query.all === 'true'
|
|
152
157
|
|
|
153
158
|
if (returnAllIds) {
|
|
@@ -168,16 +173,10 @@ async function managementApiPlugin (app, opts) {
|
|
|
168
173
|
|
|
169
174
|
reply.hijack()
|
|
170
175
|
|
|
171
|
-
runtime.pipeLogsStream(
|
|
172
|
-
reply.raw,
|
|
173
|
-
req.log,
|
|
174
|
-
startLogId,
|
|
175
|
-
endLogId,
|
|
176
|
-
runtimePID
|
|
177
|
-
)
|
|
176
|
+
runtime.pipeLogsStream(reply.raw, req.log, startLogId, endLogId, runtimePID)
|
|
178
177
|
})
|
|
179
178
|
|
|
180
|
-
app.get('/logs/:id', async
|
|
179
|
+
app.get('/logs/:id', async req => {
|
|
181
180
|
const logId = parseInt(req.params.id)
|
|
182
181
|
const runtimePID = parseInt(req.query.pid) || process.pid
|
|
183
182
|
|
|
@@ -186,10 +185,7 @@ async function managementApiPlugin (app, opts) {
|
|
|
186
185
|
throw new errors.LogFileNotFound(logId)
|
|
187
186
|
}
|
|
188
187
|
|
|
189
|
-
const logFileStream = await runtime.getLogFileStream(
|
|
190
|
-
logId,
|
|
191
|
-
runtimePID
|
|
192
|
-
)
|
|
188
|
+
const logFileStream = await runtime.getLogFileStream(logId, runtimePID)
|
|
193
189
|
return logFileStream
|
|
194
190
|
})
|
|
195
191
|
}
|
|
@@ -200,13 +196,11 @@ async function startManagementApi (runtime, configManager) {
|
|
|
200
196
|
try {
|
|
201
197
|
const runtimePIDDir = join(PLATFORMATIC_TMP_DIR, runtimePID.toString())
|
|
202
198
|
if (platform() !== 'win32') {
|
|
203
|
-
await
|
|
204
|
-
await mkdir(runtimePIDDir, { recursive: true })
|
|
199
|
+
await createDirectory(runtimePIDDir, true)
|
|
205
200
|
}
|
|
206
201
|
|
|
207
202
|
const runtimeLogsDir = getRuntimeLogsDir(configManager.dirname, process.pid)
|
|
208
|
-
await
|
|
209
|
-
await mkdir(runtimeLogsDir, { recursive: true })
|
|
203
|
+
await createDirectory(runtimeLogsDir, true)
|
|
210
204
|
|
|
211
205
|
let socketPath = null
|
|
212
206
|
if (platform() === 'win32') {
|
|
@@ -221,13 +215,13 @@ async function startManagementApi (runtime, configManager) {
|
|
|
221
215
|
|
|
222
216
|
managementApi.addHook('onClose', async () => {
|
|
223
217
|
if (platform() !== 'win32') {
|
|
224
|
-
await
|
|
218
|
+
await safeRemove(runtimePIDDir)
|
|
225
219
|
}
|
|
226
220
|
})
|
|
227
221
|
|
|
228
222
|
await managementApi.listen({ path: socketPath })
|
|
229
223
|
return managementApi
|
|
230
|
-
|
|
224
|
+
/* c8 ignore next 4 */
|
|
231
225
|
} catch (err) {
|
|
232
226
|
console.error(err)
|
|
233
227
|
process.exit(1)
|
package/lib/prom-server.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fastify = require('fastify')
|
|
4
4
|
|
|
5
|
-
async function startPrometheusServer (
|
|
5
|
+
async function startPrometheusServer (runtime, opts) {
|
|
6
6
|
const host = opts.hostname ?? '0.0.0.0'
|
|
7
7
|
const port = opts.port ?? 9090
|
|
8
8
|
const metricsEndpoint = opts.endpoint ?? '/metrics'
|
|
@@ -10,10 +10,6 @@ async function startPrometheusServer (runtimeApiClient, opts) {
|
|
|
10
10
|
|
|
11
11
|
const promServer = fastify({ name: 'Prometheus server' })
|
|
12
12
|
|
|
13
|
-
runtimeApiClient.on('close', async () => {
|
|
14
|
-
await promServer.close()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
13
|
let onRequestHook
|
|
18
14
|
if (auth) {
|
|
19
15
|
const { username, password } = auth
|
|
@@ -24,7 +20,7 @@ async function startPrometheusServer (runtimeApiClient, opts) {
|
|
|
24
20
|
return reply.code(401).send({ message: 'Unauthorized' })
|
|
25
21
|
}
|
|
26
22
|
return done()
|
|
27
|
-
}
|
|
23
|
+
},
|
|
28
24
|
})
|
|
29
25
|
onRequestHook = promServer.basicAuth
|
|
30
26
|
}
|
|
@@ -36,9 +32,9 @@ async function startPrometheusServer (runtimeApiClient, opts) {
|
|
|
36
32
|
onRequest: onRequestHook,
|
|
37
33
|
handler: async (req, reply) => {
|
|
38
34
|
reply.type('text/plain')
|
|
39
|
-
const { metrics } = await
|
|
35
|
+
const { metrics } = await runtime.getMetrics('text')
|
|
40
36
|
return metrics
|
|
41
|
-
}
|
|
37
|
+
},
|
|
42
38
|
})
|
|
43
39
|
|
|
44
40
|
await promServer.listen({ port, host })
|
|
@@ -46,5 +42,5 @@ async function startPrometheusServer (runtimeApiClient, opts) {
|
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
module.exports = {
|
|
49
|
-
startPrometheusServer
|
|
45
|
+
startPrometheusServer,
|
|
50
46
|
}
|