@nsshunt/stsappframework 3.0.176 → 3.0.178
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/dist/commonTypes.js.map +1 -1
- package/dist/influxdb/influxDBManager.js +12 -8
- package/dist/influxdb/influxDBManager.js.map +1 -1
- package/dist/influxdb/influxDBManagerAgent.js +12 -9
- package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
- package/dist/influxdb/influxDBManagerBase.js +6 -3
- package/dist/influxdb/influxDBManagerBase.js.map +1 -1
- package/dist/influxdb/influxDBManagerService.js +13 -10
- package/dist/influxdb/influxDBManagerService.js.map +1 -1
- package/dist/instrumentationsubscriber.js +26 -36
- package/dist/instrumentationsubscriber.js.map +1 -1
- package/dist/kafka/IMKafkaManager.js +10 -5
- package/dist/kafka/IMKafkaManager.js.map +1 -1
- package/dist/kafka/kafkaconsumer.js +11 -6
- package/dist/kafka/kafkaconsumer.js.map +1 -1
- package/dist/kafka/kafkamanager.js +15 -3
- package/dist/kafka/kafkamanager.js.map +1 -1
- package/dist/kafka/kafkaproducer.js +11 -6
- package/dist/kafka/kafkaproducer.js.map +1 -1
- package/dist/kafkatesting/consume.js +45 -24
- package/dist/kafkatesting/consume.js.map +1 -1
- package/dist/kafkatesting/produce.js +35 -17
- package/dist/kafkatesting/produce.js.map +1 -1
- package/dist/masterprocessbase.js +11 -2
- package/dist/masterprocessbase.js.map +1 -1
- package/dist/processbase.js +46 -39
- package/dist/processbase.js.map +1 -1
- package/dist/processoptions.js.map +1 -1
- package/dist/publishertransports/publishTransportDirect.js +12 -5
- package/dist/publishertransports/publishTransportDirect.js.map +1 -1
- package/dist/server.js +2 -2
- package/dist/server.js.map +1 -1
- package/dist/serverprocessbase.js +11 -11
- package/dist/serverprocessbase.js.map +1 -1
- package/dist/socketIoServerHelper.js +5 -5
- package/dist/socketIoServerHelper.js.map +1 -1
- package/dist/stslatencycontroller.js +1 -1
- package/dist/stslatencycontroller.js.map +1 -1
- package/dist/tcpclient/app.js +2 -1
- package/dist/tcpclient/app.js.map +1 -1
- package/dist/tcpclient/app2.js +7 -6
- package/dist/tcpclient/app2.js.map +1 -1
- package/dist/tcpserver/appConfig.js +24 -1
- package/dist/tcpserver/appConfig.js.map +1 -1
- package/dist/tcpserver/appmaster.js +33 -27
- package/dist/tcpserver/appmaster.js.map +1 -1
- package/dist/testing/app.js +14 -12
- package/dist/testing/app.js.map +1 -1
- package/dist/testing/appConfig.js +24 -1
- package/dist/testing/appConfig.js.map +1 -1
- package/dist/testing/appWorkerWSS.js +18 -12
- package/dist/testing/appWorkerWSS.js.map +1 -1
- package/dist/testing/appsolo.js +15 -13
- package/dist/testing/appsolo.js.map +1 -1
- package/dist/testing/singleservertest.test.js +11 -7
- package/dist/testing/singleservertest.test.js.map +1 -1
- package/dist/webworkertesting/app.js +8 -6
- package/dist/webworkertesting/app.js.map +1 -1
- package/dist/webworkertesting/worker.js +4 -2
- package/dist/webworkertesting/worker.js.map +1 -1
- package/package.json +8 -7
- package/src/commonTypes.ts +4 -4
- package/src/influxdb/influxDBManager.ts +14 -9
- package/src/influxdb/influxDBManagerAgent.ts +13 -9
- package/src/influxdb/influxDBManagerBase.ts +7 -3
- package/src/influxdb/influxDBManagerService.ts +14 -10
- package/src/instrumentationsubscriber.ts +29 -40
- package/src/kafka/IMKafkaManager.ts +16 -6
- package/src/kafka/kafkaconsumer.ts +20 -6
- package/src/kafka/kafkamanager.ts +16 -4
- package/src/kafka/kafkaproducer.ts +19 -6
- package/src/kafkatesting/consume.ts +55 -24
- package/src/kafkatesting/produce.ts +45 -17
- package/src/masterprocessbase.ts +15 -2
- package/src/processbase.ts +52 -45
- package/src/processoptions.ts +6 -0
- package/src/publishertransports/publishTransportDirect.ts +18 -5
- package/src/server.ts +2 -2
- package/src/serverprocessbase.ts +11 -11
- package/src/socketIoServerHelper.ts +5 -5
- package/src/stslatencycontroller.ts +1 -1
- package/src/tcpclient/app.ts +3 -1
- package/src/tcpclient/app2.ts +8 -6
- package/src/tcpserver/appConfig.ts +35 -1
- package/src/tcpserver/appmaster.ts +35 -27
- package/src/testing/app.ts +14 -12
- package/src/testing/appConfig.ts +35 -1
- package/src/testing/appWorkerWSS.ts +22 -14
- package/src/testing/appsolo.ts +16 -13
- package/src/testing/singleservertest.test.ts +13 -7
- package/src/webworkertesting/app.ts +9 -6
- package/src/webworkertesting/worker.ts +5 -2
- package/types/commonTypes.d.ts +4 -2
- package/types/commonTypes.d.ts.map +1 -1
- package/types/influxdb/influxDBManager.d.ts +2 -2
- package/types/influxdb/influxDBManager.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
- package/types/instrumentationsubscriber.d.ts +2 -3
- package/types/instrumentationsubscriber.d.ts.map +1 -1
- package/types/kafka/IMKafkaManager.d.ts +5 -1
- package/types/kafka/IMKafkaManager.d.ts.map +1 -1
- package/types/kafka/kafkaconsumer.d.ts +8 -1
- package/types/kafka/kafkaconsumer.d.ts.map +1 -1
- package/types/kafka/kafkamanager.d.ts +2 -1
- package/types/kafka/kafkamanager.d.ts.map +1 -1
- package/types/kafka/kafkaproducer.d.ts +7 -1
- package/types/kafka/kafkaproducer.d.ts.map +1 -1
- package/types/masterprocessbase.d.ts.map +1 -1
- package/types/processbase.d.ts +2 -0
- package/types/processbase.d.ts.map +1 -1
- package/types/processoptions.d.ts +3 -0
- package/types/processoptions.d.ts.map +1 -1
- package/types/publishertransports/publishTransportDirect.d.ts +5 -1
- package/types/publishertransports/publishTransportDirect.d.ts.map +1 -1
- package/types/tcpserver/appConfig.d.ts.map +1 -1
- package/types/tcpserver/appmaster.d.ts.map +1 -1
- package/types/testing/appConfig.d.ts.map +1 -1
- package/types/testing/appWorkerWSS.d.ts +2 -2
- package/types/testing/appWorkerWSS.d.ts.map +1 -1
- package/types/testing/appsolo.d.ts.map +1 -1
|
@@ -4,10 +4,38 @@ import { TOPIC, GROUP_ID, CLIENT_ID, BROKERS, TIMEOUT } from './config'
|
|
|
4
4
|
import { KafkaManager } from './../kafka/kafkamanager'
|
|
5
5
|
import { JSONObject } from '@nsshunt/stsutils';
|
|
6
6
|
|
|
7
|
+
import winston from 'winston'
|
|
8
|
+
|
|
7
9
|
async function Sleep(milliseconds = 1000) {
|
|
8
10
|
return new Promise(resolve => setTimeout(resolve, milliseconds))
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
|
|
14
|
+
winston.format.combine(
|
|
15
|
+
winston.format.colorize(),
|
|
16
|
+
winston.format.simple()
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const logger = winston.createLogger({
|
|
20
|
+
level: 'silly',
|
|
21
|
+
format: winston.format.combine(
|
|
22
|
+
winston.format.colorize(),
|
|
23
|
+
winston.format.simple()
|
|
24
|
+
),
|
|
25
|
+
transports: [
|
|
26
|
+
new winston.transports.Console()
|
|
27
|
+
]});
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
const LogErrorMessage = (message: any) => {
|
|
31
|
+
logger.error(message);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
const LogInfoMessage = (message: any) => {
|
|
36
|
+
logger.info(message);
|
|
37
|
+
}
|
|
38
|
+
|
|
11
39
|
const km = new KafkaManager({
|
|
12
40
|
clientId: CLIENT_ID + process.env.CLIENT_ID,
|
|
13
41
|
brokers: BROKERS,
|
|
@@ -15,7 +43,8 @@ const km = new KafkaManager({
|
|
|
15
43
|
connectionTimeout: TIMEOUT,
|
|
16
44
|
requestTimeout: TIMEOUT,
|
|
17
45
|
logLevel: 'NOTHING',
|
|
18
|
-
useSSL: false
|
|
46
|
+
useSSL: false,
|
|
47
|
+
logger
|
|
19
48
|
});
|
|
20
49
|
|
|
21
50
|
const runme = async () => {
|
|
@@ -24,80 +53,82 @@ const runme = async () => {
|
|
|
24
53
|
|
|
25
54
|
const consumer = km.CreateConsumer(GROUP_ID + process.env.GROUP_ID);
|
|
26
55
|
|
|
56
|
+
|
|
57
|
+
|
|
27
58
|
await consumer.Connect((error) => {
|
|
28
|
-
|
|
59
|
+
LogErrorMessage(`Connect(): Error: [${error}]`);
|
|
29
60
|
});
|
|
30
61
|
|
|
31
62
|
await consumer.Subscribe([TOPIC], fromBeginning, (error) => {
|
|
32
|
-
|
|
63
|
+
LogErrorMessage(`Subscribe(): Error: [${error}]`);
|
|
33
64
|
});
|
|
34
65
|
|
|
35
66
|
await consumer.StartConsumingMessages((topic: string, key: string, partition: number, value: string, headers: JSONObject | undefined) => {
|
|
36
|
-
|
|
67
|
+
LogInfoMessage({
|
|
37
68
|
key,
|
|
38
69
|
partition,
|
|
39
70
|
value,
|
|
40
71
|
headers
|
|
41
72
|
});
|
|
42
73
|
}, (error) => {
|
|
43
|
-
|
|
74
|
+
LogErrorMessage(`StartConsumingMessages(): Error: [${error}]`);
|
|
44
75
|
});
|
|
45
76
|
|
|
46
77
|
await consumer.Stop((error) => {
|
|
47
|
-
|
|
78
|
+
LogErrorMessage(`Stop(): Error: [${error}]`);
|
|
48
79
|
});
|
|
49
80
|
|
|
50
81
|
await consumer.Subscribe(['zzz'], fromBeginning, (error) => {
|
|
51
|
-
|
|
82
|
+
LogErrorMessage(`Subscribe(): Error: [${error}]`);
|
|
52
83
|
});
|
|
53
84
|
|
|
54
85
|
await consumer.StartConsumingMessages((topic: string, key: string, partition: number, value: string, headers: JSONObject | undefined) => {
|
|
55
|
-
|
|
86
|
+
LogInfoMessage({
|
|
56
87
|
key,
|
|
57
88
|
partition,
|
|
58
89
|
value,
|
|
59
90
|
headers
|
|
60
91
|
});
|
|
61
92
|
}, (error) => {
|
|
62
|
-
|
|
93
|
+
LogErrorMessage(`StartConsumingMessages(): Error: [${error}]`);
|
|
63
94
|
});
|
|
64
95
|
|
|
65
96
|
await consumer.Stop((error) => {
|
|
66
|
-
|
|
97
|
+
LogErrorMessage(`Stop(): Error: [${error}]`);
|
|
67
98
|
});
|
|
68
99
|
|
|
69
100
|
await consumer.Subscribe(['yyy'], fromBeginning, (error) => {
|
|
70
|
-
|
|
101
|
+
LogErrorMessage(`Subscribe(): Error: [${error}]`);
|
|
71
102
|
});
|
|
72
103
|
|
|
73
104
|
await consumer.StartConsumingMessages((topic: string, key: string, partition: number, value: string, headers: JSONObject | undefined) => {
|
|
74
105
|
/*
|
|
75
|
-
|
|
106
|
+
this.#LogInfoMessage({
|
|
76
107
|
key,
|
|
77
108
|
partition,
|
|
78
109
|
value,
|
|
79
110
|
headers
|
|
80
111
|
});
|
|
81
112
|
*/
|
|
82
|
-
|
|
113
|
+
LogInfoMessage(`key: [${key}] value: [${value}] partition: [${partition}] headers: [${headers}]`);
|
|
83
114
|
}, (error) => {
|
|
84
|
-
|
|
115
|
+
LogErrorMessage(`StartConsumingMessages(): Error: [${error}]`);
|
|
85
116
|
});
|
|
86
117
|
|
|
87
118
|
//await km.Subscribe(['zzz'], cb);
|
|
88
119
|
|
|
89
120
|
process.on("SIGINT", async () => {
|
|
90
|
-
|
|
121
|
+
LogInfoMessage('=========SIGTERM START =======================')
|
|
91
122
|
await consumer.Disconnect((error) => {
|
|
92
|
-
|
|
123
|
+
LogErrorMessage(`Disconnect(): Error: [${error}]`);
|
|
93
124
|
});
|
|
94
|
-
|
|
125
|
+
LogInfoMessage('=========SIGTERM END =======================')
|
|
95
126
|
process.exit();
|
|
96
127
|
});
|
|
97
128
|
|
|
98
129
|
let iteration = 0;
|
|
99
130
|
for (;;) {
|
|
100
|
-
|
|
131
|
+
LogInfoMessage('sleep: ' + iteration++);
|
|
101
132
|
await Sleep(1000);
|
|
102
133
|
}
|
|
103
134
|
}
|
|
@@ -109,10 +140,10 @@ const signalTraps = ['SIGTERM', 'SIGINT', 'SIGUSR2']
|
|
|
109
140
|
errorTypes.forEach(type => {
|
|
110
141
|
process.on(type, async () => {
|
|
111
142
|
try {
|
|
112
|
-
|
|
113
|
-
|
|
143
|
+
this.#LogInfoMessage(`process.on ${type}`)
|
|
144
|
+
this.#LogInfoMessage('=========consumer.disconnect() START =======================')
|
|
114
145
|
await consumer.disconnect()
|
|
115
|
-
|
|
146
|
+
this.#LogInfoMessage('=========consumer.disconnect() END =======================')
|
|
116
147
|
process.exit(0)
|
|
117
148
|
} catch (_) {
|
|
118
149
|
process.exit(1)
|
|
@@ -123,9 +154,9 @@ errorTypes.forEach(type => {
|
|
|
123
154
|
signalTraps.forEach(type => {
|
|
124
155
|
process.once(type, async () => {
|
|
125
156
|
try {
|
|
126
|
-
|
|
157
|
+
this.#LogInfoMessage('=========consumer.disconnect() START [2] =======================')
|
|
127
158
|
await consumer.disconnect()
|
|
128
|
-
|
|
159
|
+
this.#LogInfoMessage('=========consumer.disconnect() END [2] =======================')
|
|
129
160
|
} finally {
|
|
130
161
|
process.kill(process.pid, type)
|
|
131
162
|
}
|
|
@@ -133,4 +164,4 @@ signalTraps.forEach(type => {
|
|
|
133
164
|
})
|
|
134
165
|
*/
|
|
135
166
|
|
|
136
|
-
runme().catch(e =>
|
|
167
|
+
runme().catch(e => LogErrorMessage(`[example/producer] ${e.message}`))
|
|
@@ -56,6 +56,33 @@ import { KafkaManager } from './../kafka/kafkamanager'
|
|
|
56
56
|
|
|
57
57
|
import chalk from 'chalk';
|
|
58
58
|
|
|
59
|
+
import winston from 'winston'
|
|
60
|
+
|
|
61
|
+
winston.format.combine(
|
|
62
|
+
winston.format.colorize(),
|
|
63
|
+
winston.format.simple()
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const logger = winston.createLogger({
|
|
67
|
+
level: 'silly',
|
|
68
|
+
format: winston.format.combine(
|
|
69
|
+
winston.format.colorize(),
|
|
70
|
+
winston.format.simple()
|
|
71
|
+
),
|
|
72
|
+
transports: [
|
|
73
|
+
new winston.transports.Console()
|
|
74
|
+
]});
|
|
75
|
+
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
const LogErrorMessage = (message: any) => {
|
|
78
|
+
logger.error(message);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
|
+
const LogInfoMessage = (message: any) => {
|
|
83
|
+
logger.info(message);
|
|
84
|
+
}
|
|
85
|
+
|
|
59
86
|
async function Sleep(milliseconds = 1000) {
|
|
60
87
|
return new Promise(resolve => setTimeout(resolve, milliseconds))
|
|
61
88
|
}
|
|
@@ -67,30 +94,31 @@ const km = new KafkaManager({
|
|
|
67
94
|
connectionTimeout: TIMEOUT,
|
|
68
95
|
requestTimeout: TIMEOUT,
|
|
69
96
|
logLevel: 'NOTHING',
|
|
70
|
-
useSSL: false
|
|
97
|
+
useSSL: false,
|
|
98
|
+
logger
|
|
71
99
|
});
|
|
72
100
|
|
|
73
101
|
const runme = async () => {
|
|
74
|
-
await km.CreateTopic(TOPIC, PARTITIONS, (error) =>
|
|
75
|
-
await km.CreateTopic('zzz', 1, (error) =>
|
|
76
|
-
await km.CreateTopic('yyy', 1, (error) =>
|
|
102
|
+
await km.CreateTopic(TOPIC, PARTITIONS, (error) => LogInfoMessage(`CreateTopic: Error: [${error}]`));
|
|
103
|
+
await km.CreateTopic('zzz', 1, (error) => LogInfoMessage(`CreateTopic: Error: [${error}]`));
|
|
104
|
+
await km.CreateTopic('yyy', 1, (error) => LogInfoMessage(`CreateTopic: Error: [${error}]`));
|
|
77
105
|
|
|
78
106
|
const producer = km.CreateProducer();
|
|
79
107
|
|
|
80
|
-
await producer.Connect((error) =>
|
|
108
|
+
await producer.Connect((error) => LogInfoMessage(`Connect: Error: [${error}]`));
|
|
81
109
|
|
|
82
110
|
const count = 100000;
|
|
83
111
|
const sleepTime = 1000;
|
|
84
112
|
|
|
85
113
|
process.on("SIGINT", async () => {
|
|
86
|
-
|
|
87
|
-
await producer.Disconnect((error) =>
|
|
88
|
-
|
|
114
|
+
LogInfoMessage('=========SIGTERM START =======================')
|
|
115
|
+
await producer.Disconnect((error) => LogInfoMessage(`Disconnect: Error: [${error}]`));
|
|
116
|
+
LogInfoMessage('=========SIGTERM END =======================')
|
|
89
117
|
process.exit();
|
|
90
118
|
});
|
|
91
119
|
|
|
92
120
|
for (let i=0; i < count; i++) {
|
|
93
|
-
if (i % 100 === 0)
|
|
121
|
+
if (i % 100 === 0) LogInfoMessage(i);
|
|
94
122
|
const retVal = await producer.SendMessages(TOPIC, [
|
|
95
123
|
{ key: 'key1', value: chalk.green(`hello world - ${i}`) },
|
|
96
124
|
{ key: 'key2', value: 'hey hey! -2' },
|
|
@@ -98,34 +126,34 @@ const runme = async () => {
|
|
|
98
126
|
{ key: 'key4', value: 'hey hey! -4' },
|
|
99
127
|
{ key: 'key5', value: 'hey hey! -5' }
|
|
100
128
|
], (error) => {
|
|
101
|
-
|
|
129
|
+
LogErrorMessage(error);
|
|
102
130
|
}
|
|
103
131
|
);
|
|
104
132
|
|
|
105
133
|
await producer.SendMessages('zzz', [
|
|
106
134
|
{ key: 'key-zzz', value: chalk.yellow(`hello world - ${i}`) }
|
|
107
135
|
], (error) => {
|
|
108
|
-
|
|
136
|
+
LogErrorMessage(error);
|
|
109
137
|
}
|
|
110
138
|
);
|
|
111
139
|
|
|
112
140
|
await producer.SendMessages('yyy', [
|
|
113
141
|
{ key: 'key-yyy', value: chalk.cyan(`hello world - ${i}`) }
|
|
114
142
|
], (error) => {
|
|
115
|
-
|
|
143
|
+
LogErrorMessage(error);
|
|
116
144
|
}
|
|
117
145
|
);
|
|
118
146
|
|
|
119
147
|
if (i % 100 === 0) {
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
LogInfoMessage(retVal);
|
|
149
|
+
LogInfoMessage(` ------------=================> ${i}`);
|
|
122
150
|
}
|
|
123
151
|
if (sleepTime >= 0) {
|
|
124
152
|
await Sleep(sleepTime);
|
|
125
153
|
}
|
|
126
154
|
}
|
|
127
155
|
|
|
128
|
-
await producer.Disconnect((error) =>
|
|
156
|
+
await producer.Disconnect((error) => LogInfoMessage(`Disconnect: Error: [${error}]`));
|
|
129
157
|
}
|
|
130
158
|
|
|
131
159
|
/*
|
|
@@ -135,7 +163,7 @@ const signalTraps = ['SIGTERM', 'SIGINT', 'SIGUSR2']
|
|
|
135
163
|
errorTypes.forEach(type => {
|
|
136
164
|
process.on(type, async () => {
|
|
137
165
|
try {
|
|
138
|
-
|
|
166
|
+
LogInfoMessage(`process.on ${type}`)
|
|
139
167
|
await producer.disconnect()
|
|
140
168
|
process.exit(0)
|
|
141
169
|
} catch (_) {
|
|
@@ -155,5 +183,5 @@ signalTraps.forEach(type => {
|
|
|
155
183
|
})
|
|
156
184
|
*/
|
|
157
185
|
|
|
158
|
-
runme().catch(e =>
|
|
186
|
+
runme().catch(e => LogErrorMessage(`[example/producer] ${e.message}`))
|
|
159
187
|
|
package/src/masterprocessbase.ts
CHANGED
|
@@ -60,6 +60,14 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
#LogErrorMessage(message: any) {
|
|
64
|
+
this.options.logger.error(message);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#LogInfoMessage(message: any) {
|
|
68
|
+
this.options.logger.info(message);
|
|
69
|
+
}
|
|
70
|
+
|
|
63
71
|
override CollectAdditionalTelemetry(): void {
|
|
64
72
|
si.get(this.#siValueObject).then(data => {
|
|
65
73
|
this.UpdateInstrument(Gauge.CPU_SYSTEM_LOAD_GAUGE, {
|
|
@@ -156,7 +164,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
156
164
|
});
|
|
157
165
|
} catch (error)
|
|
158
166
|
{
|
|
159
|
-
|
|
167
|
+
this.#LogErrorMessage(error);
|
|
160
168
|
throw error;
|
|
161
169
|
}
|
|
162
170
|
}
|
|
@@ -362,7 +370,12 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
362
370
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
363
371
|
#SpawnWorker = (spawnWorkerOptions?: any): number => {
|
|
364
372
|
const workerEnv: any = { };
|
|
365
|
-
|
|
373
|
+
|
|
374
|
+
const tempOptions = { ...this.options };
|
|
375
|
+
delete (tempOptions as any).logger;
|
|
376
|
+
delete (tempOptions as any).publisherLogger;
|
|
377
|
+
|
|
378
|
+
workerEnv['STS_GSD_SII'] = JSON.stringify(tempOptions);
|
|
366
379
|
if (spawnWorkerOptions) {
|
|
367
380
|
workerEnv['STS_GSD_OPTIONS'] = JSON.stringify(spawnWorkerOptions);
|
|
368
381
|
}
|
package/src/processbase.ts
CHANGED
|
@@ -8,9 +8,6 @@ import { GetFirstNetworkInterface } from './network'
|
|
|
8
8
|
|
|
9
9
|
import chalk from 'chalk';
|
|
10
10
|
|
|
11
|
-
import debugModule from 'debug'
|
|
12
|
-
const debug = debugModule(`proc:${process.pid}:processBase`);
|
|
13
|
-
|
|
14
11
|
import { Gauge, InstrumentBaseTelemetry, InstrumentGaugeTelemetry, InstrumentObjectTelemetry, InstrumentLogTelemetry } from '@nsshunt/stsinstrumentation'
|
|
15
12
|
|
|
16
13
|
import { PGAccessLayer, PGPoolManager, PGPoolManagerEventName } from '@nsshunt/stsdatamanagement'
|
|
@@ -32,7 +29,7 @@ import { Worker } from 'worker_threads';
|
|
|
32
29
|
|
|
33
30
|
import os from 'os';
|
|
34
31
|
|
|
35
|
-
import { IProcessBase, ISocketIoServerHelper
|
|
32
|
+
import { IProcessBase, ISocketIoServerHelper } from './commonTypes'
|
|
36
33
|
|
|
37
34
|
import { STSDefaultClientToServerEvents, STSDefaultServerToClientEvents } from '@nsshunt/stssocketio-client'
|
|
38
35
|
|
|
@@ -47,7 +44,6 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
47
44
|
#socketIoServerHelper: ISocketIoServerHelper<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents> | null = null;
|
|
48
45
|
#accessLayer: PGAccessLayer | null = null;
|
|
49
46
|
#poolManager: PGPoolManager | null = null;
|
|
50
|
-
#logEx: logFunction | null = null;
|
|
51
47
|
|
|
52
48
|
constructor(options: ProcessOptions)
|
|
53
49
|
{
|
|
@@ -59,6 +55,39 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
59
55
|
}
|
|
60
56
|
}
|
|
61
57
|
|
|
58
|
+
#GetFormattedLogMessage(message: string): string {
|
|
59
|
+
let prefix = '';
|
|
60
|
+
let col = null;
|
|
61
|
+
const appName = this.options.serviceName;
|
|
62
|
+
|
|
63
|
+
if (cluster.isPrimary) {
|
|
64
|
+
prefix = 'M';
|
|
65
|
+
col = chalk.bold.cyan;
|
|
66
|
+
} else {
|
|
67
|
+
prefix = 'W';
|
|
68
|
+
col = chalk.green;
|
|
69
|
+
}
|
|
70
|
+
return col(`${prefix}(${process.pid}) [${appName}]: ${message}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
LogErrorMessage(message: any) {
|
|
74
|
+
const msg = this.#GetFormattedLogMessage(message);
|
|
75
|
+
this.options.logger.error(msg);
|
|
76
|
+
|
|
77
|
+
this.UpdateInstrument(Gauge.LOGGER, {
|
|
78
|
+
LogMessage: msg
|
|
79
|
+
} as InstrumentLogTelemetry);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
LogInfoMessage(message: any) {
|
|
83
|
+
const msg = this.#GetFormattedLogMessage(message);
|
|
84
|
+
this.options.logger.info(msg);
|
|
85
|
+
|
|
86
|
+
this.UpdateInstrument(Gauge.LOGGER, {
|
|
87
|
+
LogMessage: msg
|
|
88
|
+
} as InstrumentLogTelemetry);
|
|
89
|
+
}
|
|
90
|
+
|
|
62
91
|
override get options(): ProcessOptions {
|
|
63
92
|
return super.options as ProcessOptions;
|
|
64
93
|
}
|
|
@@ -67,29 +96,6 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
67
96
|
return false;
|
|
68
97
|
}
|
|
69
98
|
|
|
70
|
-
#log(appName: any): logFunction {
|
|
71
|
-
return (msg) =>
|
|
72
|
-
{
|
|
73
|
-
let prefix = '';
|
|
74
|
-
let col = null;
|
|
75
|
-
|
|
76
|
-
if (cluster.isPrimary)
|
|
77
|
-
{
|
|
78
|
-
prefix = 'M';
|
|
79
|
-
col = chalk.bold.cyan;
|
|
80
|
-
} else {
|
|
81
|
-
prefix = 'W';
|
|
82
|
-
col = chalk.green;
|
|
83
|
-
}
|
|
84
|
-
const msgEx = col(`${prefix}(${process.pid}) [${appName}]: ${msg}`);
|
|
85
|
-
debug(msgEx);
|
|
86
|
-
|
|
87
|
-
this.UpdateInstrument(Gauge.LOGGER, {
|
|
88
|
-
LogMessage: msgEx
|
|
89
|
-
} as InstrumentLogTelemetry);
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
99
|
#GetRootFolder = (): string => {
|
|
94
100
|
const mainpath = require.resolve('@nsshunt/stsutils');
|
|
95
101
|
const anotherDir = path.dirname(mainpath);
|
|
@@ -130,7 +136,8 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
130
136
|
maxFreeSockets: goptions.maxFreeSockets,
|
|
131
137
|
timeout: goptions.timeout,
|
|
132
138
|
rejectUnauthorized: goptions.isProduction // Allows self signed certs in non production mode(s)
|
|
133
|
-
}
|
|
139
|
+
},
|
|
140
|
+
logger: this.options.logger
|
|
134
141
|
} as IPublishTransportRESTServerOptions
|
|
135
142
|
}
|
|
136
143
|
|
|
@@ -168,7 +175,6 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
168
175
|
const publishTransportOptions: IPublishTransportRESTServerOptions = {
|
|
169
176
|
transportType: TransportType.RESTAPI,
|
|
170
177
|
url: `${goptions.imendpoint}:${goptions.import}${goptions.imapiroot}/publishmessage`,
|
|
171
|
-
publishdebug: goptions.publishdebug,
|
|
172
178
|
// socketPath: '/var/run/sts/stsrest01.sock'
|
|
173
179
|
agentOptions: {
|
|
174
180
|
keepAlive: goptions.keepAlive,
|
|
@@ -177,11 +183,14 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
177
183
|
maxFreeSockets: goptions.maxFreeSockets,
|
|
178
184
|
timeout: goptions.timeout,
|
|
179
185
|
rejectUnauthorized: goptions.isProduction // Allows self signed certs in non production mode(s)
|
|
180
|
-
}
|
|
186
|
+
},
|
|
187
|
+
logger: this.options.publisherLogger
|
|
181
188
|
};
|
|
182
189
|
publisherTransport = new PublishTransportRESTServerV2(publishTransportOptions);
|
|
183
190
|
} else {
|
|
184
|
-
publisherTransport = new PublishTransportDirect(
|
|
191
|
+
publisherTransport = new PublishTransportDirect({
|
|
192
|
+
logger: this.options.publisherLogger
|
|
193
|
+
});
|
|
185
194
|
}
|
|
186
195
|
|
|
187
196
|
const instrumentControllerOptions: IPublishInstrumentControllerOptionsV2 = {
|
|
@@ -193,7 +202,8 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
193
202
|
instrumentationObservationInterval: this.options.instrumentationObservationInterval,
|
|
194
203
|
instrumentationTimeWindow: this.options.instrumentationTimeWindow,
|
|
195
204
|
instrumentDefinitions: this.GetAdditionalInstruments(),
|
|
196
|
-
publisherTransport
|
|
205
|
+
publisherTransport,
|
|
206
|
+
logger: this.options.publisherLogger
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
this.#instrumentController = new PublishInstrumentControllerV2(instrumentControllerOptions);
|
|
@@ -239,8 +249,6 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
239
249
|
this.CollectAdditionalTelemetry();
|
|
240
250
|
|
|
241
251
|
}, goptions.systemInformationInterval).unref();
|
|
242
|
-
|
|
243
|
-
this.#logEx = this.#log(this.options.serviceName);
|
|
244
252
|
|
|
245
253
|
if (this.options.useDatabase) {
|
|
246
254
|
// Get the accessLayer to force DB connection test
|
|
@@ -259,14 +267,7 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
259
267
|
}
|
|
260
268
|
|
|
261
269
|
LogEx = (message: any) => {
|
|
262
|
-
|
|
263
|
-
this.#logEx(message);
|
|
264
|
-
} else {
|
|
265
|
-
console.log('')
|
|
266
|
-
console.log('************* Attempt to log before _logex set ***************')
|
|
267
|
-
console.log(message)
|
|
268
|
-
console.log('')
|
|
269
|
-
}
|
|
270
|
+
this.LogInfoMessage(message);
|
|
270
271
|
}
|
|
271
272
|
|
|
272
273
|
InstrumentExists(instrumentName: Gauge): boolean
|
|
@@ -328,8 +329,14 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
328
329
|
{
|
|
329
330
|
if (this.options.useDatabase) {
|
|
330
331
|
if (this.#accessLayer === null) {
|
|
331
|
-
this.#poolManager = new PGPoolManager(
|
|
332
|
-
|
|
332
|
+
this.#poolManager = new PGPoolManager({
|
|
333
|
+
usedefaultdb: false,
|
|
334
|
+
logger: this.options.logger
|
|
335
|
+
});
|
|
336
|
+
this.#accessLayer = new PGAccessLayer({
|
|
337
|
+
poolManager: this.#poolManager,
|
|
338
|
+
logger: this.options.logger
|
|
339
|
+
});
|
|
333
340
|
(async () => {
|
|
334
341
|
try {
|
|
335
342
|
const retVal = await (this.accessLayer as PGAccessLayer).getResourceCount();
|
package/src/processoptions.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { IServiceProcessContext } from '@nsshunt/stspublisherserver'
|
|
|
3
3
|
import express from 'express'
|
|
4
4
|
|
|
5
5
|
import { IProcessBase } from './commonTypes'
|
|
6
|
+
import { ISTSLogger } from '@nsshunt/stsutils'
|
|
6
7
|
|
|
7
8
|
export interface STSExpressServer {
|
|
8
9
|
get App(): express.Express
|
|
@@ -161,4 +162,9 @@ export interface ProcessOptions {
|
|
|
161
162
|
* Is this application using nodejs cluster mode?
|
|
162
163
|
*/
|
|
163
164
|
clusterMode: boolean
|
|
165
|
+
|
|
166
|
+
logger: ISTSLogger
|
|
167
|
+
|
|
168
|
+
publisherLogger: ISTSLogger
|
|
169
|
+
|
|
164
170
|
}
|
|
@@ -10,21 +10,34 @@ import { InfluxDBManager } from './../influxdb/influxDBManager'
|
|
|
10
10
|
import { PublishTransportUtils } from './publishTransportUtils'
|
|
11
11
|
|
|
12
12
|
import chalk from 'chalk';
|
|
13
|
+
import { ISTSLogger } from '@nsshunt/stsutils';
|
|
14
|
+
|
|
15
|
+
export interface IPublishTransportDirectOptions {
|
|
16
|
+
logger: ISTSLogger
|
|
17
|
+
}
|
|
13
18
|
|
|
14
19
|
export class PublishTransportDirect implements IPublisherTransport
|
|
15
20
|
{
|
|
16
21
|
#influxDBManager: InfluxDBManager;
|
|
17
22
|
#IMkafkaManager: IMKafkaManager;
|
|
23
|
+
#options: IPublishTransportDirectOptions;
|
|
18
24
|
|
|
19
|
-
constructor()
|
|
25
|
+
constructor(options: IPublishTransportDirectOptions)
|
|
20
26
|
{
|
|
21
|
-
this.#
|
|
22
|
-
this.#
|
|
27
|
+
this.#options = options;
|
|
28
|
+
this.#influxDBManager = new InfluxDBManager(this.#options.logger);
|
|
29
|
+
this.#IMkafkaManager = new IMKafkaManager({
|
|
30
|
+
logger: this.#options.logger
|
|
31
|
+
});
|
|
23
32
|
this.#IMkafkaManager.Start((error) => {
|
|
24
|
-
|
|
33
|
+
this.#LogErrorMessage(chalk.red(`${process.pid}:PublishTransportDirect:constructor(): Error during IMkafkaManager.Start: [${error}]`));
|
|
25
34
|
});
|
|
26
35
|
}
|
|
27
36
|
|
|
37
|
+
#LogErrorMessage(message: any) {
|
|
38
|
+
this.#options.logger.error(message);
|
|
39
|
+
}
|
|
40
|
+
|
|
28
41
|
// Returns true for success or false for failure.
|
|
29
42
|
Publish = async (payload: IInstrumentPayload): Promise<boolean> =>
|
|
30
43
|
{
|
|
@@ -35,7 +48,7 @@ export class PublishTransportDirect implements IPublisherTransport
|
|
|
35
48
|
//this.#SendIPCMessageToMaster(InstrumentManagerEventName.UPDATE_INSTRUMENT_DATA, instrumentPayload)
|
|
36
49
|
this.#influxDBManager.OutputInfluxDB(payload);
|
|
37
50
|
this.#IMkafkaManager.OutputLogs(payload, (error) => {
|
|
38
|
-
|
|
51
|
+
this.#LogErrorMessage(chalk.red(`${process.pid}:PublishTransportDirect:Publish(): Error during IMkafkaManager.OutputLogs: [${error}]`));
|
|
39
52
|
});
|
|
40
53
|
|
|
41
54
|
return true;
|
package/src/server.ts
CHANGED
|
@@ -33,7 +33,7 @@ export class STSExpressServer
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
serverNetworkMiddleware.on(ServerNetworkMiddlewareEventName.UpdateInstrument_SERVER_NET_VAL, (data: ISocketRecord) => {
|
|
36
|
-
//
|
|
36
|
+
//this.#LogInfoMessage(chalk.magenta(`serverNetworkMiddleware: [${JSON.stringify(data)}]`));
|
|
37
37
|
stsApp.UpdateInstrument(Gauge.NETWORK_RX_GAUGE, {
|
|
38
38
|
Inc: data.requestBytesRead
|
|
39
39
|
} as InstrumentGaugeTelemetry);
|
|
@@ -119,7 +119,7 @@ export class STSExpressServer
|
|
|
119
119
|
//@@ add to errors metric here - perhaps break down by type
|
|
120
120
|
|
|
121
121
|
if (err) {
|
|
122
|
-
//@@
|
|
122
|
+
//@@this.#LogInfoMessage(err);
|
|
123
123
|
res.status(err.status).send(err);
|
|
124
124
|
} else {
|
|
125
125
|
next();
|
package/src/serverprocessbase.ts
CHANGED
|
@@ -114,7 +114,7 @@ export class ServerProcessBase extends ProcessBase
|
|
|
114
114
|
|
|
115
115
|
#SetupTLSServer = async (socket: net.Socket): Promise<void> => {
|
|
116
116
|
// Add a 'close' event handler to this instance of socket
|
|
117
|
-
|
|
117
|
+
this.LogInfoMessage('CONNECTED: ' + socket.remoteAddress + ':' + socket.remotePort + ' ' + process.pid);
|
|
118
118
|
this.#sockets.push(socket);
|
|
119
119
|
|
|
120
120
|
//const self = this;
|
|
@@ -123,11 +123,11 @@ export class ServerProcessBase extends ProcessBase
|
|
|
123
123
|
return o.remoteAddress === socket.remoteAddress && o.remotePort === socket.remotePort;
|
|
124
124
|
})
|
|
125
125
|
if (index !== -1) this.#sockets.splice(index, 1);
|
|
126
|
-
|
|
126
|
+
this.LogInfoMessage('CLOSED: ' + socket.remoteAddress + ' ' + socket.remotePort + ' ' + process.pid);
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
socket.on('data',
|
|
130
|
-
|
|
129
|
+
socket.on('data', (data: any) => {
|
|
130
|
+
this.LogInfoMessage('DATA ' + socket.remoteAddress + ': ' + socket.remotePort + ': ' + data);
|
|
131
131
|
socket.write(socket.remoteAddress + ':' + socket.remotePort + " said " + data + '\n');
|
|
132
132
|
|
|
133
133
|
// Write the data back to all the connected, the client will receive it as data from the server
|
|
@@ -141,14 +141,14 @@ export class ServerProcessBase extends ProcessBase
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
#SetupRPCServer = async (socket: net.Socket): Promise<void> => {
|
|
144
|
-
|
|
144
|
+
this.LogInfoMessage('CONNECTED: ' + socket.remoteAddress + ':' + socket.remotePort + ' ' + process.pid);
|
|
145
145
|
|
|
146
|
-
socket.on('close',
|
|
147
|
-
|
|
146
|
+
socket.on('close', (data: any) => {
|
|
147
|
+
this.LogInfoMessage('CLOSED: ' + socket.remoteAddress + ' ' + socket.remotePort + ' ' + process.pid);
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
socket.on('data',
|
|
151
|
-
|
|
150
|
+
socket.on('data', (data: any) => {
|
|
151
|
+
this.LogInfoMessage('DATA ' + socket.remoteAddress + ': ' + data);
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -234,7 +234,7 @@ export class ServerProcessBase extends ProcessBase
|
|
|
234
234
|
// The second parameter is the automatic listener for the secureConnection event from the tls.Server class
|
|
235
235
|
this.#httpServer = tls.createServer(this.#GetTLSOptions(), this.#SetupTLSServer);
|
|
236
236
|
this.#httpServer.listen(this.options.listenPort, 'stscore.stsmda.org', () => {
|
|
237
|
-
|
|
237
|
+
this.LogInfoMessage('TCP Server is running on port ' + this.options.listenPort + '.');
|
|
238
238
|
}).on('listening', () =>
|
|
239
239
|
{
|
|
240
240
|
this.LogEx(`TCP live on ${this.options.endpoint}:${this.options.listenPort}${this.options.apiRoot}`);
|
|
@@ -250,7 +250,7 @@ export class ServerProcessBase extends ProcessBase
|
|
|
250
250
|
this.#httpServer = jaysonServer.tls(this.#GetTLSOptions());
|
|
251
251
|
(this.#httpServer as tls.Server).on('secureConnection', this.#SetupRPCServer);
|
|
252
252
|
this.#httpServer.listen(this.options.listenPort, 'stscore.stsmda.org', () => {
|
|
253
|
-
|
|
253
|
+
this.LogInfoMessage('JSON RPC 2.0 Server is running on port ' + this.options.listenPort + '.');
|
|
254
254
|
}).on('listening', () =>
|
|
255
255
|
{
|
|
256
256
|
this.LogEx(`JSON RPC 2.0 live on ${this.options.endpoint}:${this.options.listenPort}${this.options.apiRoot}`);
|