@nxtedition/lib 28.0.11 → 28.0.12
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 +75 -62
- package/package.json +3 -3
package/app.js
CHANGED
|
@@ -30,7 +30,6 @@ import { makeCouch } from './couch.js'
|
|
|
30
30
|
import { makeTemplateCompiler } from '@nxtedition/template'
|
|
31
31
|
import { makeDeepstream } from './deepstream.js'
|
|
32
32
|
import * as rxjs from 'rxjs'
|
|
33
|
-
import rx from 'rxjs/operators'
|
|
34
33
|
import hashString from './hash.js'
|
|
35
34
|
import { makeTrace } from './trace.js'
|
|
36
35
|
import { compose, createServer } from './http.js'
|
|
@@ -623,32 +622,30 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
623
622
|
stats$ = appConfig.stats
|
|
624
623
|
} else if (typeof appConfig.stats === 'function') {
|
|
625
624
|
stats$ = rxjs.timer(0, 10e3).pipe(
|
|
626
|
-
|
|
625
|
+
rxjs.exhaustMap(() => {
|
|
627
626
|
const ret = appConfig.stats({ ds, couch, logger })
|
|
628
627
|
return ret?.then || ret?.subscribe ? ret : rxjs.of(ret)
|
|
629
628
|
}),
|
|
630
629
|
)
|
|
631
630
|
} else if (typeof appConfig.stats === 'object') {
|
|
632
|
-
stats$ = rxjs.timer(0, 10e3).pipe(
|
|
631
|
+
stats$ = rxjs.timer(0, 10e3).pipe(rxjs.map(() => appConfig.stats))
|
|
633
632
|
} else {
|
|
634
|
-
stats$ = rxjs.timer(0, 10e3).pipe(
|
|
633
|
+
stats$ = rxjs.timer(0, 10e3).pipe(rxjs.map(() => ({})))
|
|
635
634
|
}
|
|
636
635
|
|
|
637
636
|
let statsMap
|
|
638
637
|
|
|
638
|
+
monitorProviders.stats$ = new rxjs.BehaviorSubject({})
|
|
639
|
+
|
|
639
640
|
const startTime = Date.now()
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
rxjs.timer(0, 1e3).pipe(
|
|
649
|
-
rx.map(() => performance.eventLoopUtilization?.()),
|
|
650
|
-
rx.pairwise(),
|
|
651
|
-
rx.map(([elu1, elu2]) => {
|
|
641
|
+
|
|
642
|
+
appDestroyers.unshift(
|
|
643
|
+
rxjs
|
|
644
|
+
.timer(0, 1e3)
|
|
645
|
+
.pipe(
|
|
646
|
+
rxjs.map(() => performance.eventLoopUtilization?.()),
|
|
647
|
+
rxjs.pairwise(),
|
|
648
|
+
rxjs.map(([elu1, elu2]) => {
|
|
652
649
|
const mem = process.memoryUsage()
|
|
653
650
|
const cpu = process.cpuUsage()
|
|
654
651
|
|
|
@@ -690,7 +687,10 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
690
687
|
}
|
|
691
688
|
}
|
|
692
689
|
|
|
690
|
+
const now = Date.now()
|
|
693
691
|
return {
|
|
692
|
+
uptime: now - startTime,
|
|
693
|
+
timestamp: now,
|
|
694
694
|
ds: ds?.stats,
|
|
695
695
|
couch: couch?.stats,
|
|
696
696
|
lag: toobusy?.lag(),
|
|
@@ -706,39 +706,52 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
706
706
|
undici,
|
|
707
707
|
}
|
|
708
708
|
}),
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
rx.refCount(),
|
|
709
|
+
rxjs.withLatestFrom(stats$.pipe(rxjs.startWith({}))),
|
|
710
|
+
rxjs.map(([appStats, serviceStats]) => ({
|
|
711
|
+
...appStats,
|
|
712
|
+
// TODO (fix): [serviceName] is not great and can collide.
|
|
713
|
+
[serviceName]: serviceStats,
|
|
714
|
+
})),
|
|
715
|
+
rxjs.retry({
|
|
716
|
+
delay(err, retryCount) {
|
|
717
|
+
logger.error({ err, retryCount }, 'monitor.stats$ failed')
|
|
718
|
+
return rxjs.timer(10e3)
|
|
719
|
+
},
|
|
720
|
+
}),
|
|
721
|
+
)
|
|
722
|
+
.subscribe(monitorProviders.stats$),
|
|
724
723
|
)
|
|
725
724
|
|
|
726
725
|
const statsBC = new BroadcastChannel('nxt:app:stats').unref()
|
|
726
|
+
|
|
727
727
|
if (isMainThread) {
|
|
728
728
|
statsMap = new Map()
|
|
729
729
|
statsBC.onmessage = ({ data: { data, id } }) => {
|
|
730
|
-
|
|
730
|
+
if (data != null) {
|
|
731
|
+
statsMap.set(id, data)
|
|
732
|
+
} else {
|
|
733
|
+
statsMap.delete(id)
|
|
734
|
+
}
|
|
731
735
|
}
|
|
732
736
|
}
|
|
733
737
|
|
|
734
|
-
|
|
738
|
+
appDestroyers.unshift(
|
|
739
|
+
monitorProviders.stats$
|
|
740
|
+
.subscribe((stats) => {
|
|
741
|
+
statsBC.postMessage({ id: threadId, data: stats })
|
|
742
|
+
})
|
|
743
|
+
.add(() => {
|
|
744
|
+
statsBC.postMessage({ id: threadId, data: undefined })
|
|
745
|
+
}),
|
|
746
|
+
)
|
|
735
747
|
|
|
736
748
|
if (process.env.NODE_ENV === 'production') {
|
|
737
749
|
appDestroyers.unshift(
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
750
|
+
monitorProviders.stats$
|
|
751
|
+
.pipe(rxjs.auditTime(10e3))
|
|
752
|
+
.subscribe((stats) => {
|
|
753
|
+
logger.debug(stats, 'STATS')
|
|
754
|
+
})
|
|
742
755
|
)
|
|
743
756
|
}
|
|
744
757
|
}
|
|
@@ -754,11 +767,11 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
754
767
|
return ret?.then || ret?.subscribe ? ret : rxjs.of(ret)
|
|
755
768
|
})
|
|
756
769
|
.pipe(
|
|
757
|
-
|
|
758
|
-
|
|
770
|
+
rxjs.catchError((err) => rxjs.of({ warnings: [err.message] })),
|
|
771
|
+
rxjs.repeatWhen(() => rxjs.timer(10e3)),
|
|
759
772
|
)
|
|
760
773
|
} else if (appConfig.status && typeof appConfig.status === 'object') {
|
|
761
|
-
status$ = rxjs.timer(0, 10e3).pipe(
|
|
774
|
+
status$ = rxjs.timer(0, 10e3).pipe(rxjs.exhaustMap(() => appConfig.status))
|
|
762
775
|
} else {
|
|
763
776
|
status$ = rxjs.of({})
|
|
764
777
|
}
|
|
@@ -767,9 +780,9 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
767
780
|
.combineLatest(
|
|
768
781
|
[
|
|
769
782
|
status$.pipe(
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
783
|
+
rxjs.filter(Boolean),
|
|
784
|
+
rxjs.map((xs) => (Array.isArray(xs) ? { messages: xs } : xs)),
|
|
785
|
+
rxjs.catchError((err) => {
|
|
773
786
|
logger.error({ err }, 'monitor.status')
|
|
774
787
|
return rxjs.of([
|
|
775
788
|
{
|
|
@@ -780,12 +793,12 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
780
793
|
},
|
|
781
794
|
])
|
|
782
795
|
}),
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
796
|
+
rxjs.startWith([]),
|
|
797
|
+
rxjs.distinctUntilChanged(fp.isEqual),
|
|
798
|
+
rxjs.repeatWhen((complete$) => complete$.pipe(rxjs.delay(10e3))),
|
|
786
799
|
),
|
|
787
800
|
stats$.pipe(
|
|
788
|
-
|
|
801
|
+
rxjs.map(({ memory, heap, utilization, undici, http }) => {
|
|
789
802
|
const messages = []
|
|
790
803
|
|
|
791
804
|
if (memory?.containerLimit) {
|
|
@@ -835,7 +848,7 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
835
848
|
}),
|
|
836
849
|
),
|
|
837
850
|
toobusy?.appLag$.pipe(
|
|
838
|
-
|
|
851
|
+
rxjs.map((lag) =>
|
|
839
852
|
lag == null
|
|
840
853
|
? []
|
|
841
854
|
: [
|
|
@@ -849,7 +862,7 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
849
862
|
),
|
|
850
863
|
) ?? rxjs.of([]),
|
|
851
864
|
underPressure?.pressure$?.pipe(
|
|
852
|
-
|
|
865
|
+
rxjs.map((pressure) =>
|
|
853
866
|
pressure == null
|
|
854
867
|
? []
|
|
855
868
|
: [
|
|
@@ -864,7 +877,7 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
864
877
|
) ?? rxjs.of([]),
|
|
865
878
|
couch
|
|
866
879
|
? rxjs.timer(0, 10e3).pipe(
|
|
867
|
-
|
|
880
|
+
rxjs.exhaustMap(async () => {
|
|
868
881
|
try {
|
|
869
882
|
await couch.up()
|
|
870
883
|
return [
|
|
@@ -885,8 +898,8 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
885
898
|
]
|
|
886
899
|
}
|
|
887
900
|
}),
|
|
888
|
-
|
|
889
|
-
|
|
901
|
+
rxjs.startWith([]),
|
|
902
|
+
rxjs.distinctUntilChanged(fp.isEqual),
|
|
890
903
|
)
|
|
891
904
|
: rxjs.of({}),
|
|
892
905
|
ds
|
|
@@ -914,7 +927,7 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
914
927
|
: rxjs.of([]),
|
|
915
928
|
ds
|
|
916
929
|
? rxjs.timer(0, 10e3).pipe(
|
|
917
|
-
|
|
930
|
+
rxjs.exhaustMap(async () => {
|
|
918
931
|
const messages = []
|
|
919
932
|
|
|
920
933
|
if (ds.stats.record.records > 100e3) {
|
|
@@ -970,8 +983,8 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
970
983
|
].filter(Boolean),
|
|
971
984
|
)
|
|
972
985
|
.pipe(
|
|
973
|
-
|
|
974
|
-
|
|
986
|
+
rxjs.auditTime(1e3),
|
|
987
|
+
rxjs.map(([status, lag, couch, ds]) => {
|
|
975
988
|
const messages = [
|
|
976
989
|
lag,
|
|
977
990
|
couch,
|
|
@@ -1006,21 +1019,21 @@ export function makeApp(appConfig, onTerminateOrMeta, metaOrNull) {
|
|
|
1006
1019
|
|
|
1007
1020
|
return { ...status, messages, timestamp: Date.now() }
|
|
1008
1021
|
}),
|
|
1009
|
-
|
|
1022
|
+
rxjs.catchError((err) => {
|
|
1010
1023
|
logger.error({ err }, 'monitor.status')
|
|
1011
1024
|
return rxjs.of({
|
|
1012
1025
|
messages: [{ id: 'app:monitor_status', level: 50, code: err.code, msg: err.message }],
|
|
1013
1026
|
})
|
|
1014
1027
|
}),
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1028
|
+
rxjs.repeatWhen((complete$) => complete$.pipe(rxjs.delay(10e3))),
|
|
1029
|
+
rxjs.startWith({}),
|
|
1030
|
+
rxjs.distinctUntilChanged(fp.isEqual),
|
|
1031
|
+
rxjs.publishReplay(1),
|
|
1032
|
+
rxjs.refCount(),
|
|
1020
1033
|
)
|
|
1021
1034
|
|
|
1022
1035
|
const loggerSubscription = status$
|
|
1023
|
-
.pipe(
|
|
1036
|
+
.pipe(rxjs.auditTime(1e3), rxjs.pluck('messages'), rxjs.startWith([]), rxjs.pairwise())
|
|
1024
1037
|
.subscribe(([prev, next]) => {
|
|
1025
1038
|
for (const { level, msg: status, ...message } of fp.differenceBy('id', next, prev)) {
|
|
1026
1039
|
if (level >= 50) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "28.0.
|
|
3
|
+
"version": "28.0.12",
|
|
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.10",
|
|
56
56
|
"@nxtedition/weak-cache": "^1.0.2",
|
|
57
57
|
"diff": "5.2.0",
|
|
58
58
|
"fast-querystring": "^1.1.2",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"pino": ">=7.0.0",
|
|
93
93
|
"rxjs": "^7.0.0"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "e0d096f01e85551f3caac31e96f8d144f4c17f5a"
|
|
96
96
|
}
|