@platformatic/basic 3.32.0-alpha.0 → 3.32.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 +37 -3
- package/lib/capability.js +6 -3
- package/lib/worker/child-process.js +57 -4
- package/package.json +5 -5
- package/schema.json +87 -36
package/config.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface PlatformaticBasicConfig {
|
|
|
31
31
|
};
|
|
32
32
|
workersRestartDelay?: number | string;
|
|
33
33
|
logger?: {
|
|
34
|
-
level
|
|
34
|
+
level?: (
|
|
35
35
|
| ("fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent")
|
|
36
36
|
| {
|
|
37
37
|
[k: string]: unknown;
|
|
@@ -134,7 +134,6 @@ export interface PlatformaticBasicConfig {
|
|
|
134
134
|
maxHeapTotal?: number | string;
|
|
135
135
|
maxYoungGeneration?: number | string;
|
|
136
136
|
codeRangeSize?: number | string;
|
|
137
|
-
noHeapCheck?: boolean | string;
|
|
138
137
|
};
|
|
139
138
|
undici?: {
|
|
140
139
|
agentOptions?: {
|
|
@@ -186,6 +185,18 @@ export interface PlatformaticBasicConfig {
|
|
|
186
185
|
maxSize?: number;
|
|
187
186
|
maxEntrySize?: number;
|
|
188
187
|
maxCount?: number;
|
|
188
|
+
/**
|
|
189
|
+
* Whitelist of origins to cache. Supports exact strings and regex patterns (e.g., "/https:\\/\\/.*\\.example\\.com/").
|
|
190
|
+
*/
|
|
191
|
+
origins?: string[];
|
|
192
|
+
/**
|
|
193
|
+
* Default cache duration in seconds for responses without explicit expiration headers.
|
|
194
|
+
*/
|
|
195
|
+
cacheByDefault?: number;
|
|
196
|
+
/**
|
|
197
|
+
* Cache type. "shared" caches may be shared between users, "private" caches are user-specific.
|
|
198
|
+
*/
|
|
199
|
+
type?: "shared" | "private";
|
|
189
200
|
[k: string]: unknown;
|
|
190
201
|
};
|
|
191
202
|
watch?: boolean | string;
|
|
@@ -415,6 +426,18 @@ export interface PlatformaticBasicConfig {
|
|
|
415
426
|
[k: string]: string | [string, ...string[]];
|
|
416
427
|
};
|
|
417
428
|
};
|
|
429
|
+
compileCache?:
|
|
430
|
+
| boolean
|
|
431
|
+
| {
|
|
432
|
+
/**
|
|
433
|
+
* Enable Node.js module compile cache for faster startup
|
|
434
|
+
*/
|
|
435
|
+
enabled?: boolean;
|
|
436
|
+
/**
|
|
437
|
+
* Directory to store compile cache. Defaults to .plt/compile-cache in app root
|
|
438
|
+
*/
|
|
439
|
+
directory?: string;
|
|
440
|
+
};
|
|
418
441
|
application?: {
|
|
419
442
|
reuseTcpPorts?: boolean;
|
|
420
443
|
workers?:
|
|
@@ -438,7 +461,6 @@ export interface PlatformaticBasicConfig {
|
|
|
438
461
|
maxHeapTotal?: number | string;
|
|
439
462
|
maxYoungGeneration?: number | string;
|
|
440
463
|
codeRangeSize?: number | string;
|
|
441
|
-
noHeapCheck?: boolean | string;
|
|
442
464
|
};
|
|
443
465
|
arguments?: string[];
|
|
444
466
|
env?: {
|
|
@@ -474,6 +496,18 @@ export interface PlatformaticBasicConfig {
|
|
|
474
496
|
)[];
|
|
475
497
|
[k: string]: unknown;
|
|
476
498
|
};
|
|
499
|
+
compileCache?:
|
|
500
|
+
| boolean
|
|
501
|
+
| {
|
|
502
|
+
/**
|
|
503
|
+
* Enable Node.js module compile cache for faster startup
|
|
504
|
+
*/
|
|
505
|
+
enabled?: boolean;
|
|
506
|
+
/**
|
|
507
|
+
* Directory to store compile cache. Defaults to .plt/compile-cache in app root
|
|
508
|
+
*/
|
|
509
|
+
directory?: string;
|
|
510
|
+
};
|
|
477
511
|
};
|
|
478
512
|
};
|
|
479
513
|
[k: string]: unknown;
|
package/lib/capability.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
kMetadata,
|
|
8
8
|
kTimeout
|
|
9
9
|
} from '@platformatic/foundation'
|
|
10
|
-
import { clearRegistry, client,
|
|
10
|
+
import { clearRegistry, client, collectThreadMetrics, ensureMetricsGroup, setupOtlpExporter } from '@platformatic/metrics'
|
|
11
11
|
import { parseCommandString } from 'execa'
|
|
12
12
|
import { spawn } from 'node:child_process'
|
|
13
13
|
import { tracingChannel } from 'node:diagnostics_channel'
|
|
@@ -578,7 +578,8 @@ export class BaseCapability extends EventEmitter {
|
|
|
578
578
|
backlog: this.serverConfig.backlog
|
|
579
579
|
}
|
|
580
580
|
: {},
|
|
581
|
-
telemetryConfig: this.telemetryConfig
|
|
581
|
+
telemetryConfig: this.telemetryConfig,
|
|
582
|
+
compileCache: this.config.compileCache ?? this.runtimeConfig?.compileCache
|
|
582
583
|
}
|
|
583
584
|
}
|
|
584
585
|
|
|
@@ -739,7 +740,9 @@ export class BaseCapability extends EventEmitter {
|
|
|
739
740
|
return
|
|
740
741
|
}
|
|
741
742
|
|
|
742
|
-
|
|
743
|
+
// Use thread-specific metrics collection - process-level metrics are collected
|
|
744
|
+
// by the main runtime thread and duplicated with worker labels
|
|
745
|
+
await collectThreadMetrics(this.applicationId, this.workerId, metricsConfig, this.metricsRegistry)
|
|
743
746
|
}
|
|
744
747
|
|
|
745
748
|
#setHttpCacheMetrics () {
|
|
@@ -5,14 +5,15 @@ import {
|
|
|
5
5
|
ensureLoggableError
|
|
6
6
|
} from '@platformatic/foundation'
|
|
7
7
|
import { ITC } from '@platformatic/itc/lib/index.js'
|
|
8
|
-
import { clearRegistry, client,
|
|
8
|
+
import { clearRegistry, client, collectThreadMetrics } from '@platformatic/metrics'
|
|
9
9
|
import diagnosticChannel, { tracingChannel } from 'node:diagnostics_channel'
|
|
10
10
|
import { EventEmitter, once } from 'node:events'
|
|
11
11
|
import { readFile } from 'node:fs/promises'
|
|
12
12
|
import { ServerResponse } from 'node:http'
|
|
13
13
|
import { register } from 'node:module'
|
|
14
14
|
import { hostname, platform, tmpdir } from 'node:os'
|
|
15
|
-
import { basename, resolve } from 'node:path'
|
|
15
|
+
import { basename, join, resolve } from 'node:path'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
16
17
|
import pino from 'pino'
|
|
17
18
|
import { Agent, Pool, setGlobalDispatcher } from 'undici'
|
|
18
19
|
import { WebSocket } from 'ws'
|
|
@@ -220,7 +221,9 @@ export class ChildProcess extends ITC {
|
|
|
220
221
|
}
|
|
221
222
|
|
|
222
223
|
async #collectMetrics ({ applicationId, workerId, metricsConfig }) {
|
|
223
|
-
|
|
224
|
+
// Use thread-specific metrics collection - process-level metrics are collected
|
|
225
|
+
// by the main runtime thread and duplicated with worker labels
|
|
226
|
+
await collectThreadMetrics(applicationId, workerId, metricsConfig, this.#metricsRegistry)
|
|
224
227
|
this.#setHttpCacheMetrics()
|
|
225
228
|
}
|
|
226
229
|
|
|
@@ -228,7 +231,9 @@ export class ChildProcess extends ITC {
|
|
|
228
231
|
clearRegistry(this.#metricsRegistry)
|
|
229
232
|
|
|
230
233
|
if (metricsConfig.enabled !== false) {
|
|
231
|
-
|
|
234
|
+
// Use thread-specific metrics collection - process-level metrics are collected
|
|
235
|
+
// by the main runtime thread and duplicated with worker labels
|
|
236
|
+
await collectThreadMetrics(applicationId, workerId, metricsConfig, this.#metricsRegistry)
|
|
232
237
|
this.#setHttpCacheMetrics()
|
|
233
238
|
}
|
|
234
239
|
}
|
|
@@ -503,12 +508,60 @@ function stripBasePath (basePath) {
|
|
|
503
508
|
}
|
|
504
509
|
}
|
|
505
510
|
|
|
511
|
+
// Enable compile cache if configured (Node.js 22.1.0+)
|
|
512
|
+
async function setupCompileCache (contextData) {
|
|
513
|
+
const config = contextData?.compileCache
|
|
514
|
+
|
|
515
|
+
// Normalize boolean shorthand
|
|
516
|
+
const normalizeConfig = cfg => {
|
|
517
|
+
if (cfg === true) return { enabled: true }
|
|
518
|
+
if (cfg === false) return { enabled: false }
|
|
519
|
+
return cfg
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const normalizedConfig = normalizeConfig(config)
|
|
523
|
+
if (!normalizedConfig?.enabled) {
|
|
524
|
+
return
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// Check if API is available (Node.js 22.1.0+)
|
|
528
|
+
let moduleApi
|
|
529
|
+
try {
|
|
530
|
+
moduleApi = await import('node:module')
|
|
531
|
+
if (typeof moduleApi.enableCompileCache !== 'function') {
|
|
532
|
+
return
|
|
533
|
+
}
|
|
534
|
+
} catch {
|
|
535
|
+
return
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Use root from context data (capability's this.root as URL)
|
|
539
|
+
const root = contextData?.root ? fileURLToPath(contextData.root) : null
|
|
540
|
+
if (!root) {
|
|
541
|
+
return
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const cacheDir =
|
|
545
|
+
typeof normalizedConfig === 'object' && normalizedConfig.directory
|
|
546
|
+
? normalizedConfig.directory
|
|
547
|
+
: join(root, '.plt', 'compile-cache')
|
|
548
|
+
|
|
549
|
+
try {
|
|
550
|
+
moduleApi.enableCompileCache(cacheDir)
|
|
551
|
+
} catch {
|
|
552
|
+
// Silently ignore - cache is optional optimization
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
506
556
|
async function main () {
|
|
507
557
|
const executable = basename(process.argv[1] ?? '')
|
|
508
558
|
|
|
509
559
|
const dataPath = resolve(tmpdir(), 'platformatic', 'runtimes', `${process.env.PLT_MANAGER_ID}.json`)
|
|
510
560
|
const { data, loader, scripts } = JSON.parse(await readFile(dataPath))
|
|
511
561
|
|
|
562
|
+
// Enable compile cache early before loading user modules
|
|
563
|
+
await setupCompileCache(data)
|
|
564
|
+
|
|
512
565
|
globalThis.platformatic = Object.assign(globalThis.platformatic ?? {}, data)
|
|
513
566
|
globalThis.platformatic.events = new ForwardingEventEmitter()
|
|
514
567
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/basic",
|
|
3
|
-
"version": "3.32.0-alpha.
|
|
3
|
+
"version": "3.32.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"split2": "^4.2.0",
|
|
26
26
|
"undici": "^7.0.0",
|
|
27
27
|
"ws": "^8.18.0",
|
|
28
|
-
"@platformatic/foundation": "3.32.0-alpha.
|
|
29
|
-
"@platformatic/itc": "3.32.0-alpha.
|
|
30
|
-
"@platformatic/
|
|
31
|
-
"@platformatic/
|
|
28
|
+
"@platformatic/foundation": "3.32.0-alpha.1",
|
|
29
|
+
"@platformatic/itc": "3.32.0-alpha.1",
|
|
30
|
+
"@platformatic/metrics": "3.32.0-alpha.1",
|
|
31
|
+
"@platformatic/telemetry": "3.32.0-alpha.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"cleaner-spec-reporter": "^0.5.0",
|
package/schema.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://schemas.platformatic.dev/@platformatic/basic/3.32.0-alpha.
|
|
2
|
+
"$id": "https://schemas.platformatic.dev/@platformatic/basic/3.32.0-alpha.1.json",
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
4
|
"title": "Platformatic Basic Config",
|
|
5
5
|
"type": "object",
|
|
@@ -212,16 +212,6 @@
|
|
|
212
212
|
"type": "string"
|
|
213
213
|
}
|
|
214
214
|
]
|
|
215
|
-
},
|
|
216
|
-
"noHeapCheck": {
|
|
217
|
-
"anyOf": [
|
|
218
|
-
{
|
|
219
|
-
"type": "boolean"
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
"type": "string"
|
|
223
|
-
}
|
|
224
|
-
]
|
|
225
215
|
}
|
|
226
216
|
},
|
|
227
217
|
"additionalProperties": false
|
|
@@ -346,6 +336,28 @@
|
|
|
346
336
|
}
|
|
347
337
|
}
|
|
348
338
|
}
|
|
339
|
+
},
|
|
340
|
+
"compileCache": {
|
|
341
|
+
"anyOf": [
|
|
342
|
+
{
|
|
343
|
+
"type": "boolean"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
"type": "object",
|
|
347
|
+
"properties": {
|
|
348
|
+
"enabled": {
|
|
349
|
+
"type": "boolean",
|
|
350
|
+
"default": true,
|
|
351
|
+
"description": "Enable Node.js module compile cache for faster startup"
|
|
352
|
+
},
|
|
353
|
+
"directory": {
|
|
354
|
+
"type": "string",
|
|
355
|
+
"description": "Directory to store compile cache. Defaults to .plt/compile-cache in app root"
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
"additionalProperties": false
|
|
359
|
+
}
|
|
360
|
+
]
|
|
349
361
|
}
|
|
350
362
|
}
|
|
351
363
|
}
|
|
@@ -425,7 +437,6 @@
|
|
|
425
437
|
"properties": {
|
|
426
438
|
"level": {
|
|
427
439
|
"type": "string",
|
|
428
|
-
"default": "info",
|
|
429
440
|
"oneOf": [
|
|
430
441
|
{
|
|
431
442
|
"enum": [
|
|
@@ -568,9 +579,6 @@
|
|
|
568
579
|
"additionalProperties": true
|
|
569
580
|
}
|
|
570
581
|
},
|
|
571
|
-
"required": [
|
|
572
|
-
"level"
|
|
573
|
-
],
|
|
574
582
|
"default": {},
|
|
575
583
|
"additionalProperties": true
|
|
576
584
|
},
|
|
@@ -866,17 +874,6 @@
|
|
|
866
874
|
}
|
|
867
875
|
],
|
|
868
876
|
"default": 268435456
|
|
869
|
-
},
|
|
870
|
-
"noHeapCheck": {
|
|
871
|
-
"anyOf": [
|
|
872
|
-
{
|
|
873
|
-
"type": "boolean"
|
|
874
|
-
},
|
|
875
|
-
{
|
|
876
|
-
"type": "string"
|
|
877
|
-
}
|
|
878
|
-
],
|
|
879
|
-
"default": false
|
|
880
877
|
}
|
|
881
878
|
},
|
|
882
879
|
"additionalProperties": false
|
|
@@ -1008,6 +1005,26 @@
|
|
|
1008
1005
|
},
|
|
1009
1006
|
"maxCount": {
|
|
1010
1007
|
"type": "integer"
|
|
1008
|
+
},
|
|
1009
|
+
"origins": {
|
|
1010
|
+
"type": "array",
|
|
1011
|
+
"items": {
|
|
1012
|
+
"type": "string"
|
|
1013
|
+
},
|
|
1014
|
+
"description": "Whitelist of origins to cache. Supports exact strings and regex patterns (e.g., \"/https:\\\\/\\\\/.*\\\\.example\\\\.com/\")."
|
|
1015
|
+
},
|
|
1016
|
+
"cacheByDefault": {
|
|
1017
|
+
"type": "integer",
|
|
1018
|
+
"description": "Default cache duration in seconds for responses without explicit expiration headers."
|
|
1019
|
+
},
|
|
1020
|
+
"type": {
|
|
1021
|
+
"type": "string",
|
|
1022
|
+
"enum": [
|
|
1023
|
+
"shared",
|
|
1024
|
+
"private"
|
|
1025
|
+
],
|
|
1026
|
+
"default": "shared",
|
|
1027
|
+
"description": "Cache type. \"shared\" caches may be shared between users, \"private\" caches are user-specific."
|
|
1011
1028
|
}
|
|
1012
1029
|
}
|
|
1013
1030
|
}
|
|
@@ -1623,6 +1640,28 @@
|
|
|
1623
1640
|
],
|
|
1624
1641
|
"additionalProperties": false
|
|
1625
1642
|
},
|
|
1643
|
+
"compileCache": {
|
|
1644
|
+
"anyOf": [
|
|
1645
|
+
{
|
|
1646
|
+
"type": "boolean"
|
|
1647
|
+
},
|
|
1648
|
+
{
|
|
1649
|
+
"type": "object",
|
|
1650
|
+
"properties": {
|
|
1651
|
+
"enabled": {
|
|
1652
|
+
"type": "boolean",
|
|
1653
|
+
"default": true,
|
|
1654
|
+
"description": "Enable Node.js module compile cache for faster startup"
|
|
1655
|
+
},
|
|
1656
|
+
"directory": {
|
|
1657
|
+
"type": "string",
|
|
1658
|
+
"description": "Directory to store compile cache. Defaults to .plt/compile-cache in app root"
|
|
1659
|
+
}
|
|
1660
|
+
},
|
|
1661
|
+
"additionalProperties": false
|
|
1662
|
+
}
|
|
1663
|
+
]
|
|
1664
|
+
},
|
|
1626
1665
|
"application": {
|
|
1627
1666
|
"type": "object",
|
|
1628
1667
|
"properties": {
|
|
@@ -1770,16 +1809,6 @@
|
|
|
1770
1809
|
"type": "string"
|
|
1771
1810
|
}
|
|
1772
1811
|
]
|
|
1773
|
-
},
|
|
1774
|
-
"noHeapCheck": {
|
|
1775
|
-
"anyOf": [
|
|
1776
|
-
{
|
|
1777
|
-
"type": "boolean"
|
|
1778
|
-
},
|
|
1779
|
-
{
|
|
1780
|
-
"type": "string"
|
|
1781
|
-
}
|
|
1782
|
-
]
|
|
1783
1812
|
}
|
|
1784
1813
|
},
|
|
1785
1814
|
"additionalProperties": false
|
|
@@ -1897,6 +1926,28 @@
|
|
|
1897
1926
|
}
|
|
1898
1927
|
}
|
|
1899
1928
|
}
|
|
1929
|
+
},
|
|
1930
|
+
"compileCache": {
|
|
1931
|
+
"anyOf": [
|
|
1932
|
+
{
|
|
1933
|
+
"type": "boolean"
|
|
1934
|
+
},
|
|
1935
|
+
{
|
|
1936
|
+
"type": "object",
|
|
1937
|
+
"properties": {
|
|
1938
|
+
"enabled": {
|
|
1939
|
+
"type": "boolean",
|
|
1940
|
+
"default": true,
|
|
1941
|
+
"description": "Enable Node.js module compile cache for faster startup"
|
|
1942
|
+
},
|
|
1943
|
+
"directory": {
|
|
1944
|
+
"type": "string",
|
|
1945
|
+
"description": "Directory to store compile cache. Defaults to .plt/compile-cache in app root"
|
|
1946
|
+
}
|
|
1947
|
+
},
|
|
1948
|
+
"additionalProperties": false
|
|
1949
|
+
}
|
|
1950
|
+
]
|
|
1900
1951
|
}
|
|
1901
1952
|
},
|
|
1902
1953
|
"additionalProperties": false
|