@platformatic/watt-extra 1.6.0 → 1.6.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/package.json
CHANGED
package/plugins/flamegraphs.js
CHANGED
|
@@ -18,11 +18,9 @@ async function flamegraphs (app, _opts) {
|
|
|
18
18
|
const startProfilingOnWorker = async (runtime, workerFullId, logContext = {}) => {
|
|
19
19
|
await sleep(gracePeriod)
|
|
20
20
|
|
|
21
|
-
const runtimeConfig = await runtime.getRuntimeConfig()
|
|
22
21
|
// Get application details to read service-level sourceMaps setting
|
|
23
22
|
const appDetails = await runtime.getApplicationDetails(workerFullId)
|
|
24
|
-
|
|
25
|
-
const sourceMaps = appDetails.config?.sourceMaps ?? runtimeConfig.sourceMaps
|
|
23
|
+
const sourceMaps = appDetails.sourceMaps ?? false
|
|
26
24
|
|
|
27
25
|
try {
|
|
28
26
|
// Start CPU profiling
|
|
@@ -70,13 +70,13 @@ function createMockApp (port, includeScalerUrl = true) {
|
|
|
70
70
|
},
|
|
71
71
|
getApplicationDetails: async (id) => {
|
|
72
72
|
// Default implementation, can be overridden in tests
|
|
73
|
-
return { id,
|
|
73
|
+
return { id, sourceMaps: false }
|
|
74
74
|
},
|
|
75
75
|
getRuntimeConfig: async () => {
|
|
76
76
|
// Default implementation, can be overridden in tests
|
|
77
77
|
return {}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const app = {
|
|
@@ -127,11 +127,11 @@ test('setupFlamegraphs should pass sourceMaps from application config to startPr
|
|
|
127
127
|
// Mock getApplicationDetails to return config with sourceMaps for worker IDs
|
|
128
128
|
app.watt.runtime.getApplicationDetails = async (workerFullId) => {
|
|
129
129
|
if (workerFullId.startsWith('service-1')) {
|
|
130
|
-
return { id: workerFullId,
|
|
130
|
+
return { id: workerFullId, sourceMaps: true }
|
|
131
131
|
} else if (workerFullId.startsWith('service-2')) {
|
|
132
|
-
return { id: workerFullId,
|
|
132
|
+
return { id: workerFullId, sourceMaps: false }
|
|
133
133
|
}
|
|
134
|
-
return { id: workerFullId,
|
|
134
|
+
return { id: workerFullId, sourceMaps: false }
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
app.watt.runtime.getRuntimeConfig = async () => {
|
|
@@ -176,7 +176,7 @@ test('setupFlamegraphs should handle missing sourceMaps in application config',
|
|
|
176
176
|
|
|
177
177
|
// Mock getApplicationDetails to return config without sourceMaps
|
|
178
178
|
app.watt.runtime.getApplicationDetails = async (workerFullId) => {
|
|
179
|
-
return { id: workerFullId
|
|
179
|
+
return { id: workerFullId }
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
app.watt.runtime.getRuntimeConfig = async () => {
|
|
@@ -197,7 +197,7 @@ test('setupFlamegraphs should handle missing sourceMaps in application config',
|
|
|
197
197
|
equal(startProfilingCalls.length, 4, 'Should call startProfiling for both workers with cpu and heap')
|
|
198
198
|
|
|
199
199
|
for (const call of startProfilingCalls) {
|
|
200
|
-
equal(call.options.sourceMaps,
|
|
200
|
+
equal(call.options.sourceMaps, false, 'sourceMaps should be false when not in config')
|
|
201
201
|
equal(call.options.durationMillis, 1000, 'Should still pass duration')
|
|
202
202
|
}
|
|
203
203
|
})
|
|
@@ -235,7 +235,7 @@ test('setupFlamegraphs should handle errors when starting profiling', async (t)
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
app.watt.runtime.getApplicationDetails = async (workerFullId) => {
|
|
238
|
-
return { id: workerFullId,
|
|
238
|
+
return { id: workerFullId, sourceMaps: true }
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
app.watt.runtime.getRuntimeConfig = async () => {
|
|
@@ -943,85 +943,3 @@ test('sendFlamegraphs should include alertId in query params when provided', asy
|
|
|
943
943
|
ok(req.url.includes('alertId=test-alert-123'), 'URL should include alertId query param')
|
|
944
944
|
}
|
|
945
945
|
})
|
|
946
|
-
|
|
947
|
-
test('setupFlamegraphs should use runtime-level sourceMaps as fallback', async (t) => {
|
|
948
|
-
setUpEnvironment()
|
|
949
|
-
|
|
950
|
-
const app = createMockApp(port)
|
|
951
|
-
const startProfilingCalls = []
|
|
952
|
-
|
|
953
|
-
// Mock getApplicationDetails to return config WITHOUT service-level sourceMaps
|
|
954
|
-
app.watt.runtime.getApplicationDetails = async (workerFullId) => {
|
|
955
|
-
return { id: workerFullId, config: {} } // No sourceMaps at service level
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
// Mock getRuntimeConfig to return runtime-level sourceMaps
|
|
959
|
-
app.watt.runtime.getRuntimeConfig = async () => {
|
|
960
|
-
return { sourceMaps: true } // Runtime-level default
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
app.watt.runtime.sendCommandToApplication = async (workerFullId, command, options) => {
|
|
964
|
-
if (command === 'startProfiling') {
|
|
965
|
-
startProfilingCalls.push({ workerFullId, command, options })
|
|
966
|
-
return { success: true }
|
|
967
|
-
}
|
|
968
|
-
return { success: false }
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
await flamegraphsPlugin(app)
|
|
972
|
-
await app.setupFlamegraphs()
|
|
973
|
-
|
|
974
|
-
equal(startProfilingCalls.length, 4, 'Should call startProfiling for both workers with cpu and heap')
|
|
975
|
-
|
|
976
|
-
for (const call of startProfilingCalls) {
|
|
977
|
-
equal(call.options.sourceMaps, true, 'Should use runtime-level sourceMaps as fallback')
|
|
978
|
-
equal(call.options.durationMillis, 1000, 'Should still pass duration')
|
|
979
|
-
}
|
|
980
|
-
})
|
|
981
|
-
|
|
982
|
-
test('setupFlamegraphs should prefer service-level over runtime-level sourceMaps', async (t) => {
|
|
983
|
-
setUpEnvironment()
|
|
984
|
-
|
|
985
|
-
const app = createMockApp(port)
|
|
986
|
-
const startProfilingCalls = []
|
|
987
|
-
|
|
988
|
-
// Mock getApplicationDetails - service-1 has explicit false, service-2 has no setting
|
|
989
|
-
app.watt.runtime.getApplicationDetails = async (workerFullId) => {
|
|
990
|
-
if (workerFullId.startsWith('service-1')) {
|
|
991
|
-
return { id: workerFullId, config: { sourceMaps: false } } // Explicitly set to false
|
|
992
|
-
}
|
|
993
|
-
return { id: workerFullId, config: {} } // No setting
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// Mock getRuntimeConfig to return runtime-level sourceMaps = true
|
|
997
|
-
app.watt.runtime.getRuntimeConfig = async () => {
|
|
998
|
-
return { sourceMaps: true } // Runtime-level default
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
app.watt.runtime.sendCommandToApplication = async (workerFullId, command, options) => {
|
|
1002
|
-
if (command === 'startProfiling') {
|
|
1003
|
-
startProfilingCalls.push({ workerFullId, command, options })
|
|
1004
|
-
return { success: true }
|
|
1005
|
-
}
|
|
1006
|
-
return { success: false }
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
await flamegraphsPlugin(app)
|
|
1010
|
-
await app.setupFlamegraphs()
|
|
1011
|
-
|
|
1012
|
-
equal(startProfilingCalls.length, 4, 'Should call startProfiling for both workers with cpu and heap')
|
|
1013
|
-
|
|
1014
|
-
const service1Calls = startProfilingCalls.filter(c => c.workerFullId === 'service-1:0')
|
|
1015
|
-
const service2Calls = startProfilingCalls.filter(c => c.workerFullId === 'service-2:0')
|
|
1016
|
-
|
|
1017
|
-
equal(service1Calls.length, 2, 'Should have 2 calls for service-1 (cpu + heap)')
|
|
1018
|
-
equal(service2Calls.length, 2, 'Should have 2 calls for service-2 (cpu + heap)')
|
|
1019
|
-
|
|
1020
|
-
for (const call of service1Calls) {
|
|
1021
|
-
equal(call.options.sourceMaps, false, 'Service-1 should use explicit false, not runtime default')
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
for (const call of service2Calls) {
|
|
1025
|
-
equal(call.options.sourceMaps, true, 'Service-2 should inherit runtime-level true')
|
|
1026
|
-
}
|
|
1027
|
-
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"permissions": {
|
|
3
|
-
"allow": [
|
|
4
|
-
"Read(//work/workspaces/workspace-platformatic/platformatic/**)",
|
|
5
|
-
"Bash(npx borp:*)",
|
|
6
|
-
"Bash(timeout 30 npx borp -c 1 --timeout=20000 ./test/trigger-flamegraphs.test.js)",
|
|
7
|
-
"Bash(xargs cat:*)",
|
|
8
|
-
"Bash(pnpm install)",
|
|
9
|
-
"Bash(find:*)",
|
|
10
|
-
"Bash(cat:*)"
|
|
11
|
-
],
|
|
12
|
-
"deny": [],
|
|
13
|
-
"ask": []
|
|
14
|
-
}
|
|
15
|
-
}
|