@nxtedition/lib 14.2.1 → 14.3.0
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 +22 -23
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const os = require('node:os')
|
|
2
|
+
const net = require('node:net')
|
|
3
|
+
const assert = require('node:assert')
|
|
3
4
|
const stream = require('node:stream')
|
|
4
5
|
const { Buffer } = require('node:buffer')
|
|
5
|
-
const
|
|
6
|
+
const { getDockerSecretsSync } = require('./docker-secrets')
|
|
7
|
+
const { getGlobalDispatcher } = require('undici')
|
|
6
8
|
const fp = require('lodash/fp.js')
|
|
7
|
-
const assert = require('node:assert')
|
|
8
9
|
|
|
9
10
|
module.exports = function (appConfig, onTerminate) {
|
|
10
11
|
let ds
|
|
@@ -90,14 +91,20 @@ module.exports = function (appConfig, onTerminate) {
|
|
|
90
91
|
|
|
91
92
|
const destroyers = []
|
|
92
93
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
const serviceName = appConfig.name + (instanceId && instanceId !== '0' ? `-${instanceId}` : '')
|
|
94
|
+
const serviceName = appConfig.name
|
|
95
|
+
const serviceModule = appConfig.module ?? 'main'
|
|
96
96
|
const serviceVersion = appConfig.version
|
|
97
|
+
const serviceInstanceId =
|
|
98
|
+
// process.env.name is the pm2 name of the process
|
|
99
|
+
appConfig.instanceId ?? appConfig.containerId ?? process.env.name ?? os.hostname()
|
|
97
100
|
|
|
98
101
|
const userAgent =
|
|
99
|
-
appConfig.userAgent
|
|
100
|
-
(serviceName
|
|
102
|
+
appConfig.userAgent ??
|
|
103
|
+
(serviceName &&
|
|
104
|
+
`${serviceName}/${
|
|
105
|
+
serviceVersion || '*'
|
|
106
|
+
} (module:${serviceModule}; instance:${serviceInstanceId}) Node/${process.version}`) ??
|
|
107
|
+
null
|
|
101
108
|
|
|
102
109
|
const terminate = async (finalLogger) => {
|
|
103
110
|
finalLogger ??= logger
|
|
@@ -137,6 +144,7 @@ module.exports = function (appConfig, onTerminate) {
|
|
|
137
144
|
{
|
|
138
145
|
...loggerConfig,
|
|
139
146
|
name: serviceName,
|
|
147
|
+
module: serviceModule,
|
|
140
148
|
base: loggerConfig?.base ? { ...loggerConfig.base } : {},
|
|
141
149
|
},
|
|
142
150
|
terminate
|
|
@@ -166,12 +174,7 @@ module.exports = function (appConfig, onTerminate) {
|
|
|
166
174
|
}
|
|
167
175
|
|
|
168
176
|
if (appConfig.perf && process.platform === 'linux') {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
const containerId = appConfig.containerId ?? os.hostname()
|
|
172
|
-
const hostname = process.env.NODE_ENV === 'production' ? containerId : serviceName
|
|
173
|
-
|
|
174
|
-
const perfName = typeof appConfig.perf === 'string' ? appConfig.perf : hostname
|
|
177
|
+
const perfName = typeof appConfig.perf === 'string' ? appConfig.perf : serviceInstanceId
|
|
175
178
|
|
|
176
179
|
try {
|
|
177
180
|
const linuxPerf = require('linux-perf')
|
|
@@ -648,21 +651,15 @@ module.exports = function (appConfig, onTerminate) {
|
|
|
648
651
|
const { isMainThread } = require('node:worker_threads')
|
|
649
652
|
|
|
650
653
|
if (isMainThread) {
|
|
651
|
-
const os = require('os')
|
|
652
|
-
const rx = require('rxjs/operators')
|
|
653
|
-
|
|
654
|
-
const containerId = appConfig.containerId ?? os.hostname()
|
|
655
|
-
const hostname = process.env.NODE_ENV === 'production' ? containerId : serviceName
|
|
656
|
-
|
|
657
654
|
const unprovide = ds.record.provide(`^([^:]+):monitor\\.([^?]+)[?]?`, (key) => {
|
|
658
655
|
const [, id, prop] = key.match(/^([^:]+):monitor\.([^?]+)[?]?/)
|
|
659
656
|
|
|
660
657
|
if (id === serviceName) {
|
|
661
658
|
// TODO (fix): If id === serviceName check if there are multiple instances.
|
|
662
|
-
return monitorProviders[prop + '$']
|
|
659
|
+
return monitorProviders[prop + '$']
|
|
663
660
|
}
|
|
664
661
|
|
|
665
|
-
if (id ===
|
|
662
|
+
if (id === serviceInstanceId) {
|
|
666
663
|
return monitorProviders[prop + '$']
|
|
667
664
|
}
|
|
668
665
|
})
|
|
@@ -794,7 +791,9 @@ module.exports = function (appConfig, onTerminate) {
|
|
|
794
791
|
tracer: trace,
|
|
795
792
|
userAgent,
|
|
796
793
|
serviceName,
|
|
794
|
+
serviceModule,
|
|
797
795
|
serviceVersion,
|
|
796
|
+
serviceInstanceId,
|
|
798
797
|
signal: ac.signal,
|
|
799
798
|
}
|
|
800
799
|
}
|