@nxtedition/lib 28.0.24 → 28.0.26
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/app.js +58 -22
- package/http.js +4 -4
- package/package.json +3 -3
package/app.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs'
|
|
2
2
|
import * as inspector from 'node:inspector'
|
|
3
3
|
import fs from 'node:fs'
|
|
4
|
+
import util from 'node:util'
|
|
4
5
|
import os from 'node:os'
|
|
5
6
|
import http from 'node:http'
|
|
6
7
|
import net from 'node:net'
|
|
@@ -40,6 +41,7 @@ import makeUnderPressure from './under-pressure.js'
|
|
|
40
41
|
import { nice } from '@nxtedition/sched'
|
|
41
42
|
import { setAffinity } from './numa.js'
|
|
42
43
|
import { getContainerMemoryLimit, getContainerMemoryUsage } from './memory.js'
|
|
44
|
+
import { serializeError } from './errors.js'
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
47
|
* @param {object} appConfig
|
|
@@ -688,6 +690,8 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
688
690
|
sockets: globalThis.__undici_sockets?.size ?? 0,
|
|
689
691
|
}
|
|
690
692
|
|
|
693
|
+
const errors = []
|
|
694
|
+
|
|
691
695
|
if (statsMap) {
|
|
692
696
|
memory.totalHeapTotal = 0
|
|
693
697
|
memory.totalHeapUsed = 0
|
|
@@ -707,6 +711,10 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
707
711
|
http.totalPending += stats.http?.pending ?? 0
|
|
708
712
|
|
|
709
713
|
undici.totalSockets += stats.undici?.sockets ?? 0
|
|
714
|
+
|
|
715
|
+
if (stats.error) {
|
|
716
|
+
errors.push(stats.error)
|
|
717
|
+
}
|
|
710
718
|
}
|
|
711
719
|
}
|
|
712
720
|
|
|
@@ -718,6 +726,9 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
718
726
|
couch: couch?.stats,
|
|
719
727
|
lag: toobusy?.lag(),
|
|
720
728
|
version: process.version,
|
|
729
|
+
error: errors.length
|
|
730
|
+
? serializeError(errors.length > 1 ? new AggregateError(errors) : errors[0])
|
|
731
|
+
: null,
|
|
721
732
|
underPressure: underPressure?.isUnderPressure() ? underPressure.getPressure() : null,
|
|
722
733
|
cpu,
|
|
723
734
|
memory,
|
|
@@ -757,7 +768,15 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
757
768
|
appDestroyers.unshift(
|
|
758
769
|
monitorProviders.stats$
|
|
759
770
|
.subscribe((stats) => {
|
|
760
|
-
|
|
771
|
+
try {
|
|
772
|
+
statsBC.postMessage({ id: threadId, data: stats })
|
|
773
|
+
} catch (err) {
|
|
774
|
+
statsBC.postMessage({ id: threadId, data: { error: serializeError(err) } })
|
|
775
|
+
logger.error(
|
|
776
|
+
{ err, data: util.inspect(stats, { depth: 16 }) },
|
|
777
|
+
'stats broadcast failed',
|
|
778
|
+
)
|
|
779
|
+
}
|
|
761
780
|
})
|
|
762
781
|
.add(() => {
|
|
763
782
|
statsBC.postMessage({ id: threadId, data: undefined })
|
|
@@ -823,18 +842,25 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
823
842
|
}
|
|
824
843
|
}
|
|
825
844
|
}
|
|
826
|
-
return
|
|
845
|
+
return messages
|
|
827
846
|
}),
|
|
828
847
|
),
|
|
829
848
|
status$.pipe(
|
|
830
|
-
rxjs.
|
|
831
|
-
|
|
832
|
-
makeStatusPipe('stats'),
|
|
849
|
+
rxjs.map((xs) => [xs, xs?.messages].find(Array.isArray) ?? []),
|
|
850
|
+
makeStatusPipe('status'),
|
|
833
851
|
),
|
|
834
852
|
monitorProviders.stats$?.pipe(
|
|
835
|
-
rxjs.map(({ memory, heap, utilization, undici, http }) => {
|
|
853
|
+
rxjs.map(({ memory, heap, utilization, undici, http, error }) => {
|
|
836
854
|
const messages = []
|
|
837
855
|
|
|
856
|
+
if (error) {
|
|
857
|
+
messages.push({
|
|
858
|
+
id: 'app:monitor_stats_error',
|
|
859
|
+
level: 50,
|
|
860
|
+
msg: `Monitor Stats Error: ${error.message}`,
|
|
861
|
+
})
|
|
862
|
+
}
|
|
863
|
+
|
|
838
864
|
if (memory?.containerLimit) {
|
|
839
865
|
const usagePercent = (memory.containerUsage / memory.containerLimit) * 100
|
|
840
866
|
messages.push({
|
|
@@ -1021,17 +1047,8 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
1021
1047
|
])
|
|
1022
1048
|
.pipe(
|
|
1023
1049
|
rxjs.auditTime(1e3),
|
|
1024
|
-
rxjs.map((
|
|
1025
|
-
const messages =
|
|
1026
|
-
lag,
|
|
1027
|
-
couch,
|
|
1028
|
-
ds,
|
|
1029
|
-
[
|
|
1030
|
-
status?.messages,
|
|
1031
|
-
fp.map((x) => (fp.isString(x) ? { msg: x, level: 40 } : x), status?.warnings),
|
|
1032
|
-
status,
|
|
1033
|
-
].find((x) => fp.isArray(x) && !fp.isEmpty(x)) ?? [],
|
|
1034
|
-
]
|
|
1050
|
+
rxjs.map((xs) => {
|
|
1051
|
+
const messages = xs
|
|
1035
1052
|
.flat()
|
|
1036
1053
|
.filter((x) => fp.isPlainObject(x) && !fp.isEmpty(x))
|
|
1037
1054
|
.map((message) =>
|
|
@@ -1054,18 +1071,18 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
1054
1071
|
},
|
|
1055
1072
|
)
|
|
1056
1073
|
|
|
1057
|
-
return {
|
|
1074
|
+
return { messages, timestamp: Date.now() }
|
|
1058
1075
|
}),
|
|
1059
1076
|
makeStatusPipe('status'),
|
|
1060
1077
|
)
|
|
1061
1078
|
.subscribe(monitorProviders.status$),
|
|
1062
1079
|
)
|
|
1063
1080
|
|
|
1064
|
-
const
|
|
1081
|
+
const statusBC = new BroadcastChannel('nxt:app:stats').unref()
|
|
1065
1082
|
|
|
1066
1083
|
if (isMainThread) {
|
|
1067
1084
|
statusMap = new Map()
|
|
1068
|
-
|
|
1085
|
+
statusBC.onmessage = ({ data: { data, id } }) => {
|
|
1069
1086
|
if (data != null) {
|
|
1070
1087
|
statusMap.set(id, data)
|
|
1071
1088
|
} else {
|
|
@@ -1077,10 +1094,29 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
1077
1094
|
appDestroyers.unshift(
|
|
1078
1095
|
monitorProviders.status$
|
|
1079
1096
|
.subscribe((stats) => {
|
|
1080
|
-
|
|
1097
|
+
try {
|
|
1098
|
+
statusBC.postMessage({ id: threadId, data: stats })
|
|
1099
|
+
} catch (err) {
|
|
1100
|
+
statusBC.postMessage({
|
|
1101
|
+
id: threadId,
|
|
1102
|
+
data: {
|
|
1103
|
+
messages: [
|
|
1104
|
+
{
|
|
1105
|
+
id: 'app:monitor_status_broadcast_error_' + threadId,
|
|
1106
|
+
level: 50,
|
|
1107
|
+
msg: `Monitor Status Error: ${err.message}`,
|
|
1108
|
+
},
|
|
1109
|
+
],
|
|
1110
|
+
},
|
|
1111
|
+
})
|
|
1112
|
+
logger.error(
|
|
1113
|
+
{ err, data: util.inspect(stats, { depth: 16 }) },
|
|
1114
|
+
'status broadcast failed',
|
|
1115
|
+
)
|
|
1116
|
+
}
|
|
1081
1117
|
})
|
|
1082
1118
|
.add(() => {
|
|
1083
|
-
|
|
1119
|
+
statusBC.postMessage({ id: threadId, data: undefined })
|
|
1084
1120
|
}),
|
|
1085
1121
|
)
|
|
1086
1122
|
|
package/http.js
CHANGED
|
@@ -572,7 +572,7 @@ export class ServerResponse extends http.ServerResponse {
|
|
|
572
572
|
|
|
573
573
|
/**
|
|
574
574
|
* @param {Buffer|string} chunk
|
|
575
|
-
* @param {
|
|
575
|
+
* @param {NodeJS.BufferEncoding} [encoding]
|
|
576
576
|
* @param {(err: Error) => void} [callback]
|
|
577
577
|
*/
|
|
578
578
|
write(chunk, encoding, callback) {
|
|
@@ -599,7 +599,7 @@ export class ServerResponse extends http.ServerResponse {
|
|
|
599
599
|
|
|
600
600
|
/**
|
|
601
601
|
* @param {Buffer|string} chunk
|
|
602
|
-
* @param {
|
|
602
|
+
* @param {NodeJS.BufferEncoding} [encoding]
|
|
603
603
|
* @param {(err: Error) => void} [callback]
|
|
604
604
|
*/
|
|
605
605
|
end(chunk, encoding, callback) {
|
|
@@ -811,7 +811,7 @@ export class Http2ServerResponse extends http2.Http2ServerResponse {
|
|
|
811
811
|
|
|
812
812
|
/**
|
|
813
813
|
* @param {Buffer|string} chunk
|
|
814
|
-
* @param {
|
|
814
|
+
* @param {NodeJS.BufferEncoding} [encoding]
|
|
815
815
|
* @param {(err: Error) => void} [callback]
|
|
816
816
|
*/
|
|
817
817
|
write(chunk, encoding, callback) {
|
|
@@ -838,7 +838,7 @@ export class Http2ServerResponse extends http2.Http2ServerResponse {
|
|
|
838
838
|
|
|
839
839
|
/**
|
|
840
840
|
* @param {Buffer|string} chunk
|
|
841
|
-
* @param {
|
|
841
|
+
* @param {NodeJS.BufferEncoding} [encoding]
|
|
842
842
|
* @param {(err: Error) => void} [callback]
|
|
843
843
|
*/
|
|
844
844
|
end(chunk, encoding, callback) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "28.0.
|
|
3
|
+
"version": "28.0.26",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"type": "module",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@elastic/transport": "^8.9.3",
|
|
53
53
|
"@nxtedition/nxt-undici": "^7.1.9",
|
|
54
54
|
"@nxtedition/sched": "^1.0.2",
|
|
55
|
-
"@nxtedition/template": "^1.0.
|
|
55
|
+
"@nxtedition/template": "^1.0.11",
|
|
56
56
|
"@nxtedition/weak-cache": "^1.0.2",
|
|
57
57
|
"@nxtedition/yield": "^1.0.2",
|
|
58
58
|
"diff": "5.2.0",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"canvas": "^3.1.0",
|
|
93
93
|
"rxjs": "^7.0.0"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "007b8e2002dfc572af40f794575ded6ad79620e7"
|
|
96
96
|
}
|