@platformatic/watt-extra 1.18.1 → 1.19.1-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/.github/workflows/test.yml +6 -3
- package/README.md +11 -0
- package/cli.js +24 -8
- package/docker-compose.yml +14 -0
- package/eslint.config.js +15 -9
- package/help/watt-extra.txt +2 -0
- package/lib/banner.js +2 -2
- package/lib/start-args.js +57 -23
- package/package.json +9 -11
- package/plugins/flamegraphs.js +32 -1
- package/pnpm-workspace.yaml +4 -0
- package/test/cli.test.js +30 -1
- package/test/fixtures/runtime-health/services/service-1/package.json +1 -1
- package/test/fixtures/runtime-health/services/service-2/package.json +1 -1
- package/test/fixtures/runtime-health-custom/services/service-1/package.json +1 -1
- package/test/fixtures/runtime-health-custom/services/service-2/package.json +1 -1
- package/test/fixtures/runtime-health-disabled/services/service-1/package.json +1 -1
- package/test/fixtures/runtime-health-disabled/services/service-2/package.json +1 -1
- package/test/fixtures/runtime-scheduler/main/package.json +1 -1
- package/test/fixtures/runtime-service/main/package.json +1 -1
- package/test/next-cache.test.js +5 -2
- package/test/trigger-flamegraphs.test.js +85 -0
|
@@ -21,9 +21,12 @@ jobs:
|
|
|
21
21
|
|
|
22
22
|
services:
|
|
23
23
|
valkey:
|
|
24
|
-
image: "valkey/valkey:9.
|
|
24
|
+
image: "valkey/valkey:9.2"
|
|
25
|
+
env:
|
|
26
|
+
# User expected by test/next-cache.test.js
|
|
27
|
+
VALKEY_EXTRA_FLAGS: "--user cache-user on >cache-pass allkeys allchannels +@all"
|
|
25
28
|
ports:
|
|
26
|
-
- "
|
|
29
|
+
- "6390:6379"
|
|
27
30
|
options: >-
|
|
28
31
|
--health-cmd "valkey-cli ping"
|
|
29
32
|
--health-interval 10s
|
|
@@ -36,7 +39,7 @@ jobs:
|
|
|
36
39
|
|
|
37
40
|
steps:
|
|
38
41
|
- uses: actions/checkout@v7
|
|
39
|
-
- uses: pnpm/action-setup@v6.0
|
|
42
|
+
- uses: pnpm/action-setup@v6.1.0
|
|
40
43
|
with:
|
|
41
44
|
version: 12
|
|
42
45
|
|
package/README.md
CHANGED
|
@@ -85,3 +85,14 @@ watt-extra start --app-name=my-application
|
|
|
85
85
|
# Set application directory. This is useful for development and test
|
|
86
86
|
watt-extra start --app-dir=/path/to/application
|
|
87
87
|
```
|
|
88
|
+
|
|
89
|
+
## Running the tests
|
|
90
|
+
|
|
91
|
+
Some tests need a Valkey instance. Start it with Docker Compose before running the suite:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
docker compose up -d --wait
|
|
95
|
+
pnpm test
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Valkey is exposed on the non-default port `6390`, so it does not clash with a local Redis or Valkey.
|
package/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { join, dirname } from 'node:path'
|
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
import helpMeInit from 'help-me'
|
|
6
6
|
import { readFileSync } from 'node:fs'
|
|
7
|
+
import { once } from 'node:events'
|
|
7
8
|
import { start, logger } from './index.js'
|
|
8
9
|
import { getSimpleBanner } from './lib/banner.js'
|
|
9
10
|
import { applyStartArgs } from './lib/start-args.js'
|
|
@@ -19,6 +20,21 @@ const helpMe = helpMeInit({
|
|
|
19
20
|
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
|
|
20
21
|
const commistInstance = commist()
|
|
21
22
|
|
|
23
|
+
async function writeHelpPage (page = 'watt-extra') {
|
|
24
|
+
try {
|
|
25
|
+
for await (const chunk of helpMe.createStream(page)) {
|
|
26
|
+
if (!process.stdout.write(chunk)) {
|
|
27
|
+
await once(process.stdout, 'drain')
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
process.stdout.write(`no such help file: ${page}.\n\n`)
|
|
32
|
+
if (page !== 'watt-extra') {
|
|
33
|
+
await writeHelpPage()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
22
38
|
function version () {
|
|
23
39
|
if (process.stdout.isTTY) {
|
|
24
40
|
console.log(getSimpleBanner(pkg.version))
|
|
@@ -40,7 +56,7 @@ async function startCommand (argv) {
|
|
|
40
56
|
logger.debug({ args, argv }, 'Start command arguments')
|
|
41
57
|
|
|
42
58
|
if (help) {
|
|
43
|
-
|
|
59
|
+
await writeHelpPage('start')
|
|
44
60
|
return true
|
|
45
61
|
}
|
|
46
62
|
|
|
@@ -49,10 +65,10 @@ async function startCommand (argv) {
|
|
|
49
65
|
}
|
|
50
66
|
|
|
51
67
|
// Handle help command
|
|
52
|
-
function help (args) {
|
|
68
|
+
async function help (args) {
|
|
53
69
|
// Make sure args exists and has the expected structure
|
|
54
70
|
const command = args && args._ ? args._[0] : undefined
|
|
55
|
-
|
|
71
|
+
await writeHelpPage(command || 'watt-extra')
|
|
56
72
|
}
|
|
57
73
|
|
|
58
74
|
// Register commands
|
|
@@ -69,13 +85,13 @@ async function run () {
|
|
|
69
85
|
|
|
70
86
|
// Show help if no arguments are provided
|
|
71
87
|
if (args.length === 0) {
|
|
72
|
-
|
|
88
|
+
await writeHelpPage()
|
|
73
89
|
return
|
|
74
90
|
}
|
|
75
91
|
|
|
76
92
|
// Handle help flag directly
|
|
77
93
|
if (args[0] === '--help' || args[0] === '-h') {
|
|
78
|
-
|
|
94
|
+
await writeHelpPage()
|
|
79
95
|
return
|
|
80
96
|
}
|
|
81
97
|
|
|
@@ -92,7 +108,7 @@ async function run () {
|
|
|
92
108
|
if (command === 'help') {
|
|
93
109
|
// Handle the 'help' command with optional subcommand
|
|
94
110
|
const subcommand = args[1]
|
|
95
|
-
|
|
111
|
+
await writeHelpPage(subcommand || 'watt-extra')
|
|
96
112
|
return
|
|
97
113
|
}
|
|
98
114
|
|
|
@@ -102,7 +118,7 @@ async function run () {
|
|
|
102
118
|
}
|
|
103
119
|
|
|
104
120
|
logger.error(`Command "${command}" does not exist`)
|
|
105
|
-
|
|
121
|
+
await writeHelpPage()
|
|
106
122
|
process.exit(1)
|
|
107
123
|
}
|
|
108
124
|
|
|
@@ -113,4 +129,4 @@ async function run () {
|
|
|
113
129
|
}
|
|
114
130
|
}
|
|
115
131
|
|
|
116
|
-
run()
|
|
132
|
+
await run()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
services:
|
|
2
|
+
valkey:
|
|
3
|
+
image: valkey/valkey:9.2
|
|
4
|
+
ports:
|
|
5
|
+
# Non-default host port, to avoid clashing with a local Redis/Valkey
|
|
6
|
+
- "6390:6379"
|
|
7
|
+
environment:
|
|
8
|
+
# User expected by test/next-cache.test.js
|
|
9
|
+
VALKEY_EXTRA_FLAGS: "--user cache-user on >cache-pass allkeys allchannels +@all"
|
|
10
|
+
healthcheck:
|
|
11
|
+
test: ["CMD", "valkey-cli", "ping"]
|
|
12
|
+
interval: 10s
|
|
13
|
+
timeout: 5s
|
|
14
|
+
retries: 5
|
package/eslint.config.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import { defineConfig, globalIgnores } from 'eslint/config'
|
|
1
2
|
import neostandard from 'neostandard'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
const ignores = [
|
|
5
|
+
...neostandard.resolveIgnoresFromGitignore(),
|
|
6
|
+
'clients/**/*',
|
|
7
|
+
'test/fixtures/**/*',
|
|
8
|
+
'test/tmp/**/*',
|
|
9
|
+
'node_modules/**/*'
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
// neostandard's `ignores` only scopes its own rules, so the list must also be
|
|
13
|
+
// declared as global ignores or ESLint still visits those files.
|
|
14
|
+
export default defineConfig([
|
|
15
|
+
globalIgnores(ignores),
|
|
16
|
+
...neostandard({ ignores })
|
|
17
|
+
])
|
package/help/watt-extra.txt
CHANGED
package/lib/banner.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { styleText } from 'node:util'
|
|
2
2
|
|
|
3
3
|
function getSimpleBanner (version) {
|
|
4
4
|
const versionStr = version || '0.0.1'
|
|
@@ -14,7 +14,7 @@ function getSimpleBanner (version) {
|
|
|
14
14
|
+=================================+
|
|
15
15
|
`
|
|
16
16
|
|
|
17
|
-
return
|
|
17
|
+
return styleText('green', bannerText)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export {
|
package/lib/start-args.js
CHANGED
|
@@ -1,46 +1,80 @@
|
|
|
1
|
-
import minimist from 'minimist'
|
|
2
1
|
import { resolve } from 'node:path'
|
|
2
|
+
import { parseArgs } from 'node:util'
|
|
3
|
+
|
|
4
|
+
const options = {
|
|
5
|
+
help: { type: 'boolean', short: 'h' },
|
|
6
|
+
'log-level': { type: 'string', short: 'l' },
|
|
7
|
+
'icc-url': { type: 'string', short: 'i' },
|
|
8
|
+
'app-name': { type: 'string', short: 'a' },
|
|
9
|
+
'app-dir': { type: 'string', short: 'd' }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const stringOptions = {
|
|
13
|
+
'--log-level': '-l',
|
|
14
|
+
'--icc-url': '-i',
|
|
15
|
+
'--app-name': '-a',
|
|
16
|
+
'--app-dir': '-d'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function validateStringOptions (argv) {
|
|
20
|
+
for (let index = 0; index < argv.length; index++) {
|
|
21
|
+
const arg = argv[index]
|
|
22
|
+
|
|
23
|
+
for (const [longOption, shortOption] of Object.entries(stringOptions)) {
|
|
24
|
+
if (arg === longOption || arg === shortOption) {
|
|
25
|
+
const value = argv[index + 1]
|
|
26
|
+
if (!value || value.startsWith('-')) {
|
|
27
|
+
throw new Error(`Option "${arg}" requires a value`)
|
|
28
|
+
}
|
|
29
|
+
index++
|
|
30
|
+
break
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (arg === `${longOption}=`) {
|
|
34
|
+
throw new Error(`Option "${longOption}" requires a value`)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
3
39
|
|
|
4
40
|
// Parse start command argv and apply CLI options to env.
|
|
5
41
|
// Precedence for PLT_LOG_LEVEL: --log-level flag > pre-set env > 'info' default.
|
|
6
|
-
// Do NOT add a
|
|
42
|
+
// Do NOT add a parseArgs default for `log-level`: that would make args['log-level']
|
|
7
43
|
// always truthy and unconditionally clobber an env-provided value.
|
|
8
44
|
export function applyStartArgs (argv, env = process.env) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
boolean: ['help'],
|
|
18
|
-
string: ['log-level', 'icc-url', 'app-name', 'app-dir'],
|
|
19
|
-
default: {
|
|
20
|
-
'app-dir': process.cwd()
|
|
21
|
-
}
|
|
45
|
+
validateStringOptions(argv)
|
|
46
|
+
|
|
47
|
+
const { values: args } = parseArgs({
|
|
48
|
+
args: argv,
|
|
49
|
+
options,
|
|
50
|
+
strict: true,
|
|
51
|
+
allowPositionals: false
|
|
22
52
|
})
|
|
23
53
|
|
|
24
54
|
if (args.help) {
|
|
25
55
|
return { args, help: true }
|
|
26
56
|
}
|
|
27
57
|
|
|
28
|
-
|
|
29
|
-
|
|
58
|
+
const logLevel = args['log-level']
|
|
59
|
+
if (logLevel) {
|
|
60
|
+
env.PLT_LOG_LEVEL = logLevel
|
|
30
61
|
} else if (!env.PLT_LOG_LEVEL) {
|
|
31
62
|
env.PLT_LOG_LEVEL = 'info'
|
|
32
63
|
}
|
|
33
64
|
|
|
34
|
-
|
|
35
|
-
|
|
65
|
+
const iccUrl = args['icc-url']
|
|
66
|
+
if (iccUrl) {
|
|
67
|
+
env.PLT_ICC_URL = iccUrl
|
|
36
68
|
}
|
|
37
69
|
|
|
38
|
-
|
|
39
|
-
|
|
70
|
+
const appName = args['app-name']
|
|
71
|
+
if (appName) {
|
|
72
|
+
env.PLT_APP_NAME = appName
|
|
40
73
|
}
|
|
41
74
|
|
|
42
|
-
|
|
43
|
-
|
|
75
|
+
const appDir = args['app-dir'] ?? process.cwd()
|
|
76
|
+
if (appDir) {
|
|
77
|
+
env.PLT_APP_DIR = resolve(appDir) // Ensure the path is absolute
|
|
44
78
|
}
|
|
45
79
|
|
|
46
80
|
return { args, help: false }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/watt-extra",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.1-alpha.1",
|
|
4
4
|
"description": "The Platformatic runtime manager",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@fastify/websocket": "^11.1.0",
|
|
22
|
-
"@platformatic/composer": "
|
|
23
|
-
"@platformatic/next": "
|
|
24
|
-
"@platformatic/node": "
|
|
25
|
-
"@platformatic/service": "
|
|
22
|
+
"@platformatic/composer": "3.71.1-alpha.0",
|
|
23
|
+
"@platformatic/next": "3.71.1-alpha.0",
|
|
24
|
+
"@platformatic/node": "3.71.1-alpha.0",
|
|
25
|
+
"@platformatic/service": "3.71.1-alpha.0",
|
|
26
26
|
"atomic-sleep": "^1.0.0",
|
|
27
27
|
"borp": "^1.0.0",
|
|
28
28
|
"eslint": "10",
|
|
@@ -30,22 +30,20 @@
|
|
|
30
30
|
"fastify-plugin": "^6.0.0",
|
|
31
31
|
"neostandard": "0.14.0-next.1",
|
|
32
32
|
"next": "^16.2.10",
|
|
33
|
-
"platformatic": "^3.
|
|
33
|
+
"platformatic": "^3.71.0",
|
|
34
34
|
"pprof-format": "^2.1.0",
|
|
35
35
|
"why-is-node-running": "^2.3.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@datadog/pprof": "^5.9.0",
|
|
39
39
|
"@fastify/error": "^4.2.0",
|
|
40
|
-
"@platformatic/foundation": "
|
|
41
|
-
"@platformatic/runtime": "
|
|
42
|
-
"@platformatic/wattpm-pprof-capture": "
|
|
40
|
+
"@platformatic/foundation": "3.71.1-alpha.0",
|
|
41
|
+
"@platformatic/runtime": "3.71.1-alpha.0",
|
|
42
|
+
"@platformatic/wattpm-pprof-capture": "3.71.1-alpha.0",
|
|
43
43
|
"avvio": "^9.1.0",
|
|
44
|
-
"chalk": "^4.1.2",
|
|
45
44
|
"commist": "^3.2.0",
|
|
46
45
|
"env-schema": "^8.0.0",
|
|
47
46
|
"help-me": "^5.0.0",
|
|
48
|
-
"minimist": "^1.2.8",
|
|
49
47
|
"pino": "^10.0.0",
|
|
50
48
|
"pino-pretty": "^13.0.0",
|
|
51
49
|
"semver": "^7.7.3",
|
package/plugins/flamegraphs.js
CHANGED
|
@@ -78,6 +78,29 @@ async function flamegraphs (app, _opts) {
|
|
|
78
78
|
// API (older ICC): reporting is disabled for the lifetime of the pod.
|
|
79
79
|
let stateReportingSupported = true
|
|
80
80
|
|
|
81
|
+
// The modules in node_modules whose source maps must be loaded, like next.
|
|
82
|
+
// They are not part of the application details, so they are read from the
|
|
83
|
+
// runtime configuration: the application setting overrides the runtime one.
|
|
84
|
+
const getNodeModulesSourceMaps = async (runtime, workerFullId) => {
|
|
85
|
+
const serviceId = workerFullId.split(':')[0]
|
|
86
|
+
|
|
87
|
+
let modules
|
|
88
|
+
try {
|
|
89
|
+
const config = await runtime.getRuntimeConfig()
|
|
90
|
+
for (const application of config?.applications ?? []) {
|
|
91
|
+
if (application.id === serviceId) {
|
|
92
|
+
modules = application.nodeModulesSourceMaps
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
modules ??= config?.nodeModulesSourceMaps
|
|
97
|
+
} catch (err) {
|
|
98
|
+
app.log.warn({ err, workerFullId }, 'Failed to read the node_modules source maps setting')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return Array.isArray(modules) ? modules : []
|
|
102
|
+
}
|
|
103
|
+
|
|
81
104
|
const startProfilingOnWorker = async (runtime, workerFullId, types, logContext = {}, { grace = true } = {}) => {
|
|
82
105
|
if (grace) {
|
|
83
106
|
await sleep(gracePeriod)
|
|
@@ -87,12 +110,20 @@ async function flamegraphs (app, _opts) {
|
|
|
87
110
|
const appDetails = await runtime.getApplicationDetails(workerFullId)
|
|
88
111
|
const sourceMaps = appDetails.sourceMaps ?? false
|
|
89
112
|
|
|
113
|
+
const profilingOptions = { durationMillis, eluThreshold, sourceMaps }
|
|
114
|
+
if (sourceMaps) {
|
|
115
|
+
const nodeModulesSourceMaps = await getNodeModulesSourceMaps(runtime, workerFullId)
|
|
116
|
+
if (nodeModulesSourceMaps.length > 0) {
|
|
117
|
+
profilingOptions.nodeModulesSourceMaps = nodeModulesSourceMaps
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
90
121
|
for (const type of types) {
|
|
91
122
|
try {
|
|
92
123
|
await runtime.sendCommandToApplication(
|
|
93
124
|
workerFullId,
|
|
94
125
|
'startProfiling',
|
|
95
|
-
{
|
|
126
|
+
{ ...profilingOptions, type }
|
|
96
127
|
)
|
|
97
128
|
} catch (err) {
|
|
98
129
|
// A worker which is already being profiled is considered covered
|
package/pnpm-workspace.yaml
CHANGED
package/test/cli.test.js
CHANGED
|
@@ -105,7 +105,7 @@ test('applyStartArgs: -l short flag also overrides env', () => {
|
|
|
105
105
|
})
|
|
106
106
|
|
|
107
107
|
// Regression test: cli.js used to have `default: { 'log-level': 'info' }` in its
|
|
108
|
-
//
|
|
108
|
+
// argument parser config, which populated args['log-level'] with 'info' whenever the flag
|
|
109
109
|
// was not passed. The subsequent unconditional write to process.env.PLT_LOG_LEVEL
|
|
110
110
|
// then silently clobbered the value provided by the deployment environment (e.g.
|
|
111
111
|
// PLT_LOG_LEVEL=warn from k8s), forcing the runtime to log at info regardless.
|
|
@@ -139,3 +139,32 @@ test('applyStartArgs: --help short-circuits without mutating env', () => {
|
|
|
139
139
|
assert.strictEqual(res.help, true)
|
|
140
140
|
assert.strictEqual(env.PLT_LOG_LEVEL, undefined)
|
|
141
141
|
})
|
|
142
|
+
|
|
143
|
+
test('applyStartArgs: supports -h, --opt=value and short aliases', () => {
|
|
144
|
+
assert.strictEqual(applyStartArgs(['-h'], {}).help, true)
|
|
145
|
+
|
|
146
|
+
const env = {}
|
|
147
|
+
applyStartArgs(['--log-level=debug', '-i', 'http://icc.example', '-a', 'my-app', '-d', 'test'], env)
|
|
148
|
+
assert.strictEqual(env.PLT_LOG_LEVEL, 'debug')
|
|
149
|
+
assert.strictEqual(env.PLT_ICC_URL, 'http://icc.example')
|
|
150
|
+
assert.strictEqual(env.PLT_APP_NAME, 'my-app')
|
|
151
|
+
assert.strictEqual(env.PLT_APP_DIR, resolve('test'))
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
test('applyStartArgs: defaults PLT_APP_DIR to the current directory', () => {
|
|
155
|
+
const env = {}
|
|
156
|
+
applyStartArgs([], env)
|
|
157
|
+
assert.strictEqual(env.PLT_APP_DIR, process.cwd())
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('applyStartArgs: rejects unknown options and positionals', () => {
|
|
161
|
+
assert.throws(() => applyStartArgs(['--unknown'], {}), /Unknown option/)
|
|
162
|
+
assert.throws(() => applyStartArgs(['positional'], {}), /Unexpected argument/)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
test('applyStartArgs: rejects string options without a value', () => {
|
|
166
|
+
assert.throws(() => applyStartArgs(['--log-level'], {}), /requires a value/)
|
|
167
|
+
assert.throws(() => applyStartArgs(['--log-level='], {}), /requires a value/)
|
|
168
|
+
assert.throws(() => applyStartArgs(['--log-level', '--help'], {}), /requires a value/)
|
|
169
|
+
assert.throws(() => applyStartArgs(['-l', '-h'], {}), /requires a value/)
|
|
170
|
+
})
|
package/test/next-cache.test.js
CHANGED
|
@@ -11,6 +11,9 @@ import { setUpEnvironment, startICC } from './helper.js'
|
|
|
11
11
|
|
|
12
12
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
13
13
|
|
|
14
|
+
// Matches the host port exposed by docker-compose.yml and the CI service
|
|
15
|
+
const valkeyPort = 6390
|
|
16
|
+
|
|
14
17
|
// The runtime reports a Next.js application as '@platformatic/next' (older
|
|
15
18
|
// runtimes said 'next'). The Next patches, cache adapter included, must be
|
|
16
19
|
// applied in both cases.
|
|
@@ -29,7 +32,7 @@ test('should configure the Next.js cache adapter for @platformatic/next applicat
|
|
|
29
32
|
|
|
30
33
|
const clientOpts = {
|
|
31
34
|
host: '127.0.0.1',
|
|
32
|
-
port:
|
|
35
|
+
port: valkeyPort,
|
|
33
36
|
username: 'cache-user',
|
|
34
37
|
password: 'cache-pass',
|
|
35
38
|
keyPrefix: `${applicationId}:`
|
|
@@ -72,7 +75,7 @@ test('should configure the Next.js cache adapter for @platformatic/next applicat
|
|
|
72
75
|
const nextConfig = await app.watt.runtime.getApplicationConfig('next')
|
|
73
76
|
assert.deepStrictEqual(nextConfig.cache, {
|
|
74
77
|
adapter: 'valkey',
|
|
75
|
-
url:
|
|
78
|
+
url: `valkey://cache-user:cache-pass@127.0.0.1:${valkeyPort}`,
|
|
76
79
|
prefix: `${applicationId}:`,
|
|
77
80
|
maxTTL: 604800
|
|
78
81
|
})
|
|
@@ -177,6 +177,91 @@ test('setupFlamegraphs should pass sourceMaps from application config to startPr
|
|
|
177
177
|
equal(service2HeapCall.options.sourceMaps, false, 'Should pass sourceMaps=false for service-2 heap')
|
|
178
178
|
})
|
|
179
179
|
|
|
180
|
+
test('setupFlamegraphs should pass nodeModulesSourceMaps from runtime config to startProfiling', async (t) => {
|
|
181
|
+
setUpEnvironment()
|
|
182
|
+
|
|
183
|
+
const app = createMockApp(port)
|
|
184
|
+
const startProfilingCalls = []
|
|
185
|
+
|
|
186
|
+
app.watt.runtime.getWorkers = async () => ({
|
|
187
|
+
'service-1:0': { application: 'service-1', worker: 0, status: 'started' },
|
|
188
|
+
'service-2:0': { application: 'service-2', worker: 0, status: 'started' },
|
|
189
|
+
'service-3:0': { application: 'service-3', worker: 0, status: 'started' }
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
app.watt.runtime.getApplicationDetails = async (workerFullId) => {
|
|
193
|
+
return { id: workerFullId, sourceMaps: !workerFullId.startsWith('service-3') }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
app.watt.runtime.getRuntimeConfig = () => {
|
|
197
|
+
return {
|
|
198
|
+
nodeModulesSourceMaps: ['next'],
|
|
199
|
+
applications: [
|
|
200
|
+
{ id: 'service-1', nodeModulesSourceMaps: ['next', '@next/next-server'] },
|
|
201
|
+
{ id: 'service-2' },
|
|
202
|
+
{ id: 'service-3' }
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
app.watt.runtime.sendCommandToApplication = async (workerFullId, command, options) => {
|
|
208
|
+
if (command === 'startProfiling') {
|
|
209
|
+
startProfilingCalls.push({ workerFullId, command, options })
|
|
210
|
+
return { success: true }
|
|
211
|
+
}
|
|
212
|
+
return { success: false }
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
await flamegraphsPlugin(app)
|
|
216
|
+
await app.setupFlamegraphs()
|
|
217
|
+
|
|
218
|
+
equal(startProfilingCalls.length, 6)
|
|
219
|
+
|
|
220
|
+
for (const call of startProfilingCalls) {
|
|
221
|
+
if (call.workerFullId === 'service-1:0') {
|
|
222
|
+
deepEqual(call.options.nodeModulesSourceMaps, ['next', '@next/next-server'])
|
|
223
|
+
} else if (call.workerFullId === 'service-2:0') {
|
|
224
|
+
deepEqual(call.options.nodeModulesSourceMaps, ['next'])
|
|
225
|
+
} else {
|
|
226
|
+
equal(call.options.sourceMaps, false)
|
|
227
|
+
equal('nodeModulesSourceMaps' in call.options, false)
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
test('setupFlamegraphs should start profiling when the runtime config cannot be read', async (t) => {
|
|
233
|
+
setUpEnvironment()
|
|
234
|
+
|
|
235
|
+
const app = createMockApp(port)
|
|
236
|
+
const startProfilingCalls = []
|
|
237
|
+
|
|
238
|
+
app.watt.runtime.getApplicationDetails = async (workerFullId) => {
|
|
239
|
+
return { id: workerFullId, sourceMaps: true }
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
app.watt.runtime.getRuntimeConfig = () => {
|
|
243
|
+
throw new Error('Runtime config not available')
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
app.watt.runtime.sendCommandToApplication = async (workerFullId, command, options) => {
|
|
247
|
+
if (command === 'startProfiling') {
|
|
248
|
+
startProfilingCalls.push({ workerFullId, command, options })
|
|
249
|
+
return { success: true }
|
|
250
|
+
}
|
|
251
|
+
return { success: false }
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
await flamegraphsPlugin(app)
|
|
255
|
+
await app.setupFlamegraphs()
|
|
256
|
+
|
|
257
|
+
equal(startProfilingCalls.length, 4)
|
|
258
|
+
|
|
259
|
+
for (const call of startProfilingCalls) {
|
|
260
|
+
equal(call.options.sourceMaps, true)
|
|
261
|
+
equal('nodeModulesSourceMaps' in call.options, false)
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
|
|
180
265
|
test('setupFlamegraphs should handle missing sourceMaps in application config', async (t) => {
|
|
181
266
|
setUpEnvironment()
|
|
182
267
|
|