@platformatic/runtime 2.72.0 → 3.0.0-alpha.1
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 +1 -1
- package/index.d.ts +51 -23
- package/index.js +99 -17
- package/lib/config.js +159 -218
- package/lib/errors.js +150 -108
- package/lib/{generator/runtime-generator.js → generator.js} +37 -33
- package/lib/logger.js +2 -2
- package/lib/management-api.js +2 -2
- package/lib/prom-server.js +3 -7
- package/lib/runtime.js +209 -125
- package/lib/schema.js +1 -0
- package/lib/upgrade.js +6 -4
- package/lib/utils.js +1 -42
- package/lib/worker/app.js +39 -71
- package/lib/worker/itc.js +1 -5
- package/lib/worker/main.js +1 -11
- package/lib/worker/messaging.js +2 -2
- package/package.json +16 -23
- package/schema.json +2 -1
- package/help/compile.txt +0 -8
- package/help/help.txt +0 -5
- package/help/start.txt +0 -21
- package/index.test-d.ts +0 -41
- package/lib/build-server.js +0 -67
- package/lib/compile.js +0 -108
- package/lib/generator/README.md +0 -32
- package/lib/generator/errors.js +0 -10
- package/lib/generator/runtime-generator.d.ts +0 -37
- package/lib/start.js +0 -211
- package/lib/worker/default-stackable.js +0 -33
- package/lib/worker/shared-context.js +0 -26
- package/runtime.mjs +0 -54
package/lib/errors.js
CHANGED
|
@@ -4,113 +4,155 @@ const createError = require('@fastify/error')
|
|
|
4
4
|
|
|
5
5
|
const ERROR_PREFIX = 'PLT_RUNTIME'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
7
|
+
const AddressInUseError = createError(
|
|
8
|
+
`${ERROR_PREFIX}_EADDR_IN_USE`,
|
|
9
|
+
'The current port is in use by another application'
|
|
10
|
+
)
|
|
11
|
+
const RuntimeExitedError = createError(
|
|
12
|
+
`${ERROR_PREFIX}_RUNTIME_EXIT`,
|
|
13
|
+
'The runtime exited before the operation completed'
|
|
14
|
+
)
|
|
15
|
+
const RuntimeAbortedError = createError(`${ERROR_PREFIX}_RUNTIME_ABORT`, 'The runtime aborted the operation')
|
|
16
|
+
// The following two use the same code as we only need to differentiate the label
|
|
17
|
+
const ServiceExitedError = createError(
|
|
18
|
+
`${ERROR_PREFIX}_SERVICE_EXIT`,
|
|
19
|
+
'The service "%s" exited prematurely with error code %d'
|
|
20
|
+
)
|
|
21
|
+
const WorkerExitedError = createError(
|
|
22
|
+
`${ERROR_PREFIX}_SERVICE_EXIT`,
|
|
23
|
+
'The worker %s of the service "%s" exited prematurely with error code %d'
|
|
24
|
+
)
|
|
25
|
+
const UnknownRuntimeAPICommandError = createError(
|
|
26
|
+
`${ERROR_PREFIX}_UNKNOWN_RUNTIME_API_COMMAND`,
|
|
27
|
+
'Unknown Runtime API command "%s"'
|
|
28
|
+
)
|
|
29
|
+
const ServiceNotFoundError = createError(
|
|
30
|
+
`${ERROR_PREFIX}_SERVICE_NOT_FOUND`,
|
|
31
|
+
'Service %s not found. Available services are: %s'
|
|
32
|
+
)
|
|
33
|
+
const WorkerNotFoundError = createError(
|
|
34
|
+
`${ERROR_PREFIX}_WORKER_NOT_FOUND`,
|
|
35
|
+
'Worker %s of service %s not found. Available services are: %s'
|
|
36
|
+
)
|
|
37
|
+
const ServiceNotStartedError = createError(`${ERROR_PREFIX}_SERVICE_NOT_STARTED`, "Service with id '%s' is not started")
|
|
38
|
+
const ServiceStartTimeoutError = createError(
|
|
39
|
+
`${ERROR_PREFIX}_SERVICE_START_TIMEOUT`,
|
|
40
|
+
"Service with id '%s' failed to start in %dms."
|
|
41
|
+
)
|
|
42
|
+
const FailedToRetrieveOpenAPISchemaError = createError(
|
|
43
|
+
`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`,
|
|
44
|
+
'Failed to retrieve OpenAPI schema for service with id "%s": %s'
|
|
45
|
+
)
|
|
46
|
+
const FailedToRetrieveGraphQLSchemaError = createError(
|
|
47
|
+
`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`,
|
|
48
|
+
'Failed to retrieve GraphQL schema for service with id "%s": %s'
|
|
49
|
+
)
|
|
50
|
+
const FailedToRetrieveMetaError = createError(
|
|
51
|
+
`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_META`,
|
|
52
|
+
'Failed to retrieve metadata for service with id "%s": %s'
|
|
53
|
+
)
|
|
54
|
+
const FailedToRetrieveMetricsError = createError(
|
|
55
|
+
`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_METRICS`,
|
|
56
|
+
'Failed to retrieve metrics for service with id "%s": %s'
|
|
57
|
+
)
|
|
58
|
+
const FailedToRetrieveHealthError = createError(
|
|
59
|
+
`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_HEALTH`,
|
|
60
|
+
'Failed to retrieve health for service with id "%s": %s'
|
|
61
|
+
)
|
|
62
|
+
const FailedToPerformCustomHealthCheckError = createError(
|
|
63
|
+
`${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_HEALTH_CHECK`,
|
|
64
|
+
'Failed to perform custom healthcheck for service with id "%s": %s'
|
|
65
|
+
)
|
|
66
|
+
const FailedToPerformCustomReadinessCheckError = createError(
|
|
67
|
+
`${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_READINESS_CHECK`,
|
|
68
|
+
'Failed to perform custom readiness check for service with id "%s": %s'
|
|
69
|
+
)
|
|
70
|
+
const ApplicationAlreadyStartedError = createError(
|
|
71
|
+
`${ERROR_PREFIX}_APPLICATION_ALREADY_STARTED`,
|
|
72
|
+
'Application is already started'
|
|
73
|
+
)
|
|
74
|
+
const ApplicationNotStartedError = createError(
|
|
75
|
+
`${ERROR_PREFIX}_APPLICATION_NOT_STARTED`,
|
|
76
|
+
'Application has not been started'
|
|
77
|
+
)
|
|
78
|
+
const ConfigPathMustBeStringError = createError(
|
|
79
|
+
`${ERROR_PREFIX}_CONFIG_PATH_MUST_BE_STRING`,
|
|
80
|
+
'Config path must be a string'
|
|
81
|
+
)
|
|
82
|
+
const NoConfigFileFoundError = createError(
|
|
83
|
+
`${ERROR_PREFIX}_NO_CONFIG_FILE_FOUND`,
|
|
84
|
+
"No config file found for service '%s'"
|
|
85
|
+
)
|
|
86
|
+
const InvalidEntrypointError = createError(
|
|
87
|
+
`${ERROR_PREFIX}_INVALID_ENTRYPOINT`,
|
|
88
|
+
"Invalid entrypoint: '%s' does not exist"
|
|
89
|
+
)
|
|
90
|
+
const MissingEntrypointError = createError(`${ERROR_PREFIX}_MISSING_ENTRYPOINT`, 'Missing application entrypoint.')
|
|
91
|
+
const InvalidServicesWithWebError = createError(
|
|
92
|
+
`${ERROR_PREFIX}_INVALID_SERVICES_WITH_WEB`,
|
|
93
|
+
'The "services" property cannot be used when the "web" property is also defined'
|
|
94
|
+
)
|
|
95
|
+
const MissingDependencyError = createError(`${ERROR_PREFIX}_MISSING_DEPENDENCY`, 'Missing dependency: "%s"')
|
|
96
|
+
const InspectAndInspectBrkError = createError(
|
|
97
|
+
`${ERROR_PREFIX}_INSPECT_AND_INSPECT_BRK`,
|
|
98
|
+
'--inspect and --inspect-brk cannot be used together'
|
|
99
|
+
)
|
|
100
|
+
const InspectorPortError = createError(
|
|
101
|
+
`${ERROR_PREFIX}_INSPECTOR_PORT`,
|
|
102
|
+
'Inspector port must be 0 or in range 1024 to 65535'
|
|
103
|
+
)
|
|
104
|
+
const InspectorHostError = createError(`${ERROR_PREFIX}_INSPECTOR_HOST`, 'Inspector host cannot be empty')
|
|
105
|
+
const CannotMapSpecifierToAbsolutePathError = createError(
|
|
106
|
+
`${ERROR_PREFIX}_CANNOT_MAP_SPECIFIER_TO_ABSOLUTE_PATH`,
|
|
107
|
+
'Cannot map "%s" to an absolute path'
|
|
108
|
+
)
|
|
109
|
+
const NodeInspectorFlagsNotSupportedError = createError(
|
|
110
|
+
`${ERROR_PREFIX}_NODE_INSPECTOR_FLAGS_NOT_SUPPORTED`,
|
|
111
|
+
"The Node.js inspector flags are not supported. Please use 'platformatic start --inspect' instead."
|
|
112
|
+
)
|
|
113
|
+
const FailedToUnlinkManagementApiSocket = createError(
|
|
114
|
+
`${ERROR_PREFIX}_FAILED_TO_UNLINK_MANAGEMENT_API_SOCKET`,
|
|
115
|
+
'Failed to unlink management API socket "%s"'
|
|
116
|
+
)
|
|
117
|
+
const LogFileNotFound = createError(`${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`, 'Log file with index %s not found', 404)
|
|
118
|
+
const WorkerIsRequired = createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required')
|
|
119
|
+
const InvalidArgumentError = createError(`${ERROR_PREFIX}_INVALID_ARGUMENT`, 'Invalid argument: "%s"')
|
|
120
|
+
const MessagingError = createError(`${ERROR_PREFIX}_MESSAGING_ERROR`, 'Cannot send a message to service "%s": %s')
|
|
110
121
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
module.exports = {
|
|
123
|
+
AddressInUseError,
|
|
124
|
+
RuntimeExitedError,
|
|
125
|
+
RuntimeAbortedError,
|
|
126
|
+
ServiceExitedError,
|
|
127
|
+
WorkerExitedError,
|
|
128
|
+
UnknownRuntimeAPICommandError,
|
|
129
|
+
ServiceNotFoundError,
|
|
130
|
+
WorkerNotFoundError,
|
|
131
|
+
ServiceNotStartedError,
|
|
132
|
+
ServiceStartTimeoutError,
|
|
133
|
+
FailedToRetrieveOpenAPISchemaError,
|
|
134
|
+
FailedToRetrieveGraphQLSchemaError,
|
|
135
|
+
FailedToRetrieveMetaError,
|
|
136
|
+
FailedToRetrieveMetricsError,
|
|
137
|
+
FailedToRetrieveHealthError,
|
|
138
|
+
FailedToPerformCustomHealthCheckError,
|
|
139
|
+
FailedToPerformCustomReadinessCheckError,
|
|
140
|
+
ApplicationAlreadyStartedError,
|
|
141
|
+
ApplicationNotStartedError,
|
|
142
|
+
ConfigPathMustBeStringError,
|
|
143
|
+
NoConfigFileFoundError,
|
|
144
|
+
InvalidEntrypointError,
|
|
145
|
+
MissingEntrypointError,
|
|
146
|
+
InvalidServicesWithWebError,
|
|
147
|
+
MissingDependencyError,
|
|
148
|
+
InspectAndInspectBrkError,
|
|
149
|
+
InspectorPortError,
|
|
150
|
+
InspectorHostError,
|
|
151
|
+
CannotMapSpecifierToAbsolutePathError,
|
|
152
|
+
NodeInspectorFlagsNotSupportedError,
|
|
153
|
+
FailedToUnlinkManagementApiSocket,
|
|
154
|
+
LogFileNotFound,
|
|
155
|
+
WorkerIsRequired,
|
|
156
|
+
InvalidArgumentError,
|
|
157
|
+
MessagingError
|
|
116
158
|
}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const createError = require('@fastify/error')
|
|
3
4
|
const { BaseGenerator } = require('@platformatic/generators')
|
|
4
|
-
const { NoEntryPointError, NoServiceNamedError } = require('./errors')
|
|
5
5
|
const { existsSync } = require('node:fs')
|
|
6
6
|
const { join, basename } = require('node:path')
|
|
7
7
|
const { envObjectToString } = require('@platformatic/generators/lib/utils')
|
|
8
8
|
const { readFile, readdir, stat } = require('node:fs/promises')
|
|
9
|
-
const {
|
|
10
|
-
const { platformaticRuntime } = require('../config')
|
|
9
|
+
const { transform } = require('./config')
|
|
11
10
|
const { getServiceTemplateFromSchemaUrl } = require('@platformatic/generators/lib/utils')
|
|
12
11
|
const { DotEnvTool } = require('dotenv-tool')
|
|
13
|
-
const { getArrayDifference } = require('
|
|
12
|
+
const { getArrayDifference } = require('./utils')
|
|
13
|
+
const { schema } = require('./schema')
|
|
14
14
|
const { pathToFileURL } = require('node:url')
|
|
15
|
-
const {
|
|
15
|
+
const {
|
|
16
|
+
safeRemove,
|
|
17
|
+
generateDashedName,
|
|
18
|
+
findConfigurationFile,
|
|
19
|
+
loadConfiguration,
|
|
20
|
+
loadConfigurationFile,
|
|
21
|
+
kMetadata
|
|
22
|
+
} = require('@platformatic/utils')
|
|
16
23
|
const { createRequire } = require('node:module')
|
|
17
24
|
|
|
18
25
|
const wrappableProperties = {
|
|
@@ -27,9 +34,17 @@ const wrappableProperties = {
|
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
const engines = {
|
|
30
|
-
node: '
|
|
37
|
+
node: '>=22.16.0'
|
|
31
38
|
}
|
|
32
39
|
|
|
40
|
+
const ERROR_PREFIX = 'PLT_RUNTIME_GEN'
|
|
41
|
+
|
|
42
|
+
const NoServiceNamedError = createError(
|
|
43
|
+
`${ERROR_PREFIX}_NO_SERVICE_FOUND`,
|
|
44
|
+
"No service named '%s' has been added to this runtime."
|
|
45
|
+
)
|
|
46
|
+
const NoEntryPointError = createError(`${ERROR_PREFIX}_NO_ENTRYPOINT`, 'No entrypoint had been defined.')
|
|
47
|
+
|
|
33
48
|
function getRuntimeBaseEnvVars (config) {
|
|
34
49
|
return {
|
|
35
50
|
PLT_SERVER_HOSTNAME: '127.0.0.1',
|
|
@@ -50,7 +65,6 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
50
65
|
this.services = []
|
|
51
66
|
this.existingServices = []
|
|
52
67
|
this.entryPoint = null
|
|
53
|
-
this.packageManager = opts.packageManager ?? DEFAULT_PACKAGE_MANAGER
|
|
54
68
|
}
|
|
55
69
|
|
|
56
70
|
async addService (service, name) {
|
|
@@ -86,6 +100,7 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
86
100
|
async generatePackageJson () {
|
|
87
101
|
const template = {
|
|
88
102
|
name: `${this.runtimeName}`,
|
|
103
|
+
workspaces: [this.servicesFolder + '/*'],
|
|
89
104
|
scripts: {
|
|
90
105
|
dev: this.config.devCommand,
|
|
91
106
|
build: this.config.buildCommand,
|
|
@@ -103,13 +118,8 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
103
118
|
},
|
|
104
119
|
engines
|
|
105
120
|
}
|
|
106
|
-
|
|
107
|
-
if (this.packageManager === 'npm' || this.packageManager === 'yarn') {
|
|
108
|
-
template.workspaces = [this.servicesFolder + '/*']
|
|
109
|
-
}
|
|
110
|
-
|
|
111
121
|
if (this.config.typescript) {
|
|
112
|
-
const typescriptVersion = JSON.parse(await readFile(join(__dirname, '..', '
|
|
122
|
+
const typescriptVersion = JSON.parse(await readFile(join(__dirname, '..', 'package.json'), 'utf-8'))
|
|
113
123
|
.devDependencies.typescript
|
|
114
124
|
template.scripts.clean = 'rm -fr ./dist'
|
|
115
125
|
template.scripts.build = 'platformatic compile'
|
|
@@ -141,21 +151,19 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
141
151
|
return
|
|
142
152
|
}
|
|
143
153
|
this._hasCheckedForExistingConfig = true
|
|
144
|
-
const existingConfigFile =
|
|
145
|
-
this.runtimeConfig ?? (await ConfigManager.findConfigFile(this.targetDirectory, 'runtime'))
|
|
154
|
+
const existingConfigFile = this.runtimeConfig ?? (await findConfigurationFile(this.targetDirectory, 'runtime'))
|
|
146
155
|
if (existingConfigFile && existsSync(join(this.targetDirectory, existingConfigFile))) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
156
|
+
this.existingConfigRaw = await loadConfigurationFile(join(this.targetDirectory, existingConfigFile))
|
|
157
|
+
this.existingConfig = await loadConfiguration(join(this.targetDirectory, existingConfigFile), schema, {
|
|
158
|
+
transform,
|
|
159
|
+
ignoreProcessEnv: true
|
|
150
160
|
})
|
|
151
|
-
await configManager.parse()
|
|
152
161
|
|
|
153
|
-
|
|
154
|
-
this.
|
|
155
|
-
this.config.
|
|
156
|
-
this.
|
|
157
|
-
this.
|
|
158
|
-
this.existingServices = configManager.current.services.map(s => s.id)
|
|
162
|
+
const { PLT_ROOT, ...existingEnvironment } = this.existingConfig[kMetadata].env
|
|
163
|
+
this.config.env = existingEnvironment
|
|
164
|
+
this.config.port = this.config.env.PORT
|
|
165
|
+
this.entryPoint = this.existingConfig.services.find(svc => svc.entrypoint)
|
|
166
|
+
this.existingServices = this.existingConfig.services.map(s => s.id)
|
|
159
167
|
|
|
160
168
|
this.updateRuntimeConfig(this.existingConfigRaw)
|
|
161
169
|
this.updateRuntimeEnv(await readFile(join(this.targetDirectory, '.env'), 'utf-8'))
|
|
@@ -218,13 +226,9 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
218
226
|
this.addFile({
|
|
219
227
|
path: '',
|
|
220
228
|
file: '.env.sample',
|
|
221
|
-
contents: envObjectToString(this.config.
|
|
229
|
+
contents: envObjectToString(this.config.env)
|
|
222
230
|
})
|
|
223
231
|
|
|
224
|
-
if (!this.existingConfig) {
|
|
225
|
-
this.addFile({ path: '', file: 'README.md', contents: await readFile(join(__dirname, 'README.md'), 'utf-8') })
|
|
226
|
-
}
|
|
227
|
-
|
|
228
232
|
return {
|
|
229
233
|
targetDirectory: this.targetDirectory,
|
|
230
234
|
env: servicesEnv
|
|
@@ -362,7 +366,7 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
362
366
|
const dirStat = await stat(currentServicePath)
|
|
363
367
|
if (dirStat.isDirectory()) {
|
|
364
368
|
// load the service config
|
|
365
|
-
const configFile = await
|
|
369
|
+
const configFile = await findConfigurationFile(currentServicePath)
|
|
366
370
|
const servicePltJson = JSON.parse(await readFile(join(currentServicePath, configFile), 'utf-8'))
|
|
367
371
|
// get module to load
|
|
368
372
|
const template = servicePltJson.module || getServiceTemplateFromSchemaUrl(servicePltJson.$schema)
|
|
@@ -410,7 +414,7 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
410
414
|
|
|
411
415
|
// delete dependencies
|
|
412
416
|
const servicePath = join(this.targetDirectory, this.servicesFolder, s.name)
|
|
413
|
-
const configFile = await
|
|
417
|
+
const configFile = await findConfigurationFile(servicePath)
|
|
414
418
|
const servicePackageJson = JSON.parse(await readFile(join(servicePath, configFile), 'utf-8'))
|
|
415
419
|
if (servicePackageJson.plugins && servicePackageJson.plugins.packages) {
|
|
416
420
|
servicePackageJson.plugins.packages.forEach(p => {
|
|
@@ -586,7 +590,7 @@ class WrappedGenerator extends BaseGenerator {
|
|
|
586
590
|
this.addFile({
|
|
587
591
|
path: '',
|
|
588
592
|
file: '.env.sample',
|
|
589
|
-
contents: (await this.#readExistingFile('.env.sample', '', '\n')) + envObjectToString(this.config.
|
|
593
|
+
contents: (await this.#readExistingFile('.env.sample', '', '\n')) + envObjectToString(this.config.env)
|
|
590
594
|
})
|
|
591
595
|
}
|
|
592
596
|
|
package/lib/logger.js
CHANGED
|
@@ -5,7 +5,7 @@ const { join } = require('node:path')
|
|
|
5
5
|
const { isatty } = require('node:tty')
|
|
6
6
|
const pino = require('pino')
|
|
7
7
|
const pretty = require('pino-pretty')
|
|
8
|
-
const { buildPinoFormatters, buildPinoTimestamp } = require('@platformatic/utils')
|
|
8
|
+
const { abstractLogger, buildPinoFormatters, buildPinoTimestamp } = require('@platformatic/utils')
|
|
9
9
|
|
|
10
10
|
const customPrettifiers = {
|
|
11
11
|
name (name, _, obj) {
|
|
@@ -79,4 +79,4 @@ async function createLogger (config, runtimeLogsDir) {
|
|
|
79
79
|
return [pino(loggerConfig, multiStream), multiStream]
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
module.exports = { createLogger }
|
|
82
|
+
module.exports = { abstractLogger, createLogger }
|
package/lib/management-api.js
CHANGED
|
@@ -203,7 +203,7 @@ async function managementApiPlugin (app, opts) {
|
|
|
203
203
|
})
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
async function startManagementApi (runtime,
|
|
206
|
+
async function startManagementApi (runtime, root) {
|
|
207
207
|
const runtimePID = process.pid
|
|
208
208
|
|
|
209
209
|
try {
|
|
@@ -212,7 +212,7 @@ async function startManagementApi (runtime, configManager) {
|
|
|
212
212
|
await createDirectory(runtimePIDDir, true)
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
const runtimeLogsDir = getRuntimeLogsDir(
|
|
215
|
+
const runtimeLogsDir = getRuntimeLogsDir(root, process.pid)
|
|
216
216
|
await createDirectory(runtimeLogsDir, true)
|
|
217
217
|
|
|
218
218
|
let socketPath = null
|
package/lib/prom-server.js
CHANGED
|
@@ -77,7 +77,6 @@ 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(require('@fastify/accepts'))
|
|
81
80
|
|
|
82
81
|
let onRequestHook
|
|
83
82
|
if (auth) {
|
|
@@ -123,12 +122,9 @@ async function startPrometheusServer (runtime, opts) {
|
|
|
123
122
|
logLevel: 'warn',
|
|
124
123
|
onRequest: onRequestHook,
|
|
125
124
|
handler: async (req, reply) => {
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
reply.type('text/plain')
|
|
130
|
-
}
|
|
131
|
-
return (await runtime.getMetrics(reqType)).metrics
|
|
125
|
+
reply.type('text/plain')
|
|
126
|
+
const { metrics } = await runtime.getMetrics('text')
|
|
127
|
+
return metrics
|
|
132
128
|
},
|
|
133
129
|
})
|
|
134
130
|
|