@nsshunt/stsappframework 3.0.176 → 3.0.177
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 +10 -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 +15 -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 +15 -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 +14 -2
- package/src/processbase.ts +52 -45
- package/src/processoptions.ts +3 -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 +22 -1
- package/src/tcpserver/appmaster.ts +35 -27
- package/src/testing/app.ts +14 -12
- package/src/testing/appConfig.ts +22 -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 +2 -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
|
@@ -89,9 +89,9 @@ export class SocketIoServerHelper<ClientToServerEvents extends STSDefaultClientT
|
|
|
89
89
|
// Use this middleward to check every incomming connection
|
|
90
90
|
#SetupConnectionMiddleware = (nameSpace: STSSocketIONamespace) => {
|
|
91
91
|
nameSpace.socketionamespace.use((socket, next) => {
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
//
|
|
92
|
+
//this.#LogInfoMessage(JSON.stringify(socket));
|
|
93
|
+
//this.#LogInfoMessage(JSON.stringify(socket.handshake.auth));
|
|
94
|
+
//this.#LogInfoMessage(JSON.stringify(socket.handshake.headers));
|
|
95
95
|
//if (isValid(socket.request)) {
|
|
96
96
|
const a=5; // for lint purposes
|
|
97
97
|
if (a === 5) {
|
|
@@ -105,8 +105,8 @@ export class SocketIoServerHelper<ClientToServerEvents extends STSDefaultClientT
|
|
|
105
105
|
// Use this middleware to check very packet being received
|
|
106
106
|
#SetupMessageMiddleware = (socket: STSServerSocket) => {
|
|
107
107
|
socket.use(([event, ...args], next) => {
|
|
108
|
-
//
|
|
109
|
-
//
|
|
108
|
+
//this.#LogInfoMessage(JSON.stringify(event));
|
|
109
|
+
//this.#LogInfoMessage(JSON.stringify(args));
|
|
110
110
|
/*
|
|
111
111
|
if (isUnauthorized(event)) {
|
|
112
112
|
return next(new Error("unauthorized event"));
|
|
@@ -20,7 +20,7 @@ export class STSLatencyController extends STSControllerBase
|
|
|
20
20
|
};
|
|
21
21
|
return res.status(StatusCodes.OK).send(retVal);
|
|
22
22
|
} catch (error) {
|
|
23
|
-
|
|
23
|
+
this.stsApp.LogErrorMessage(error);
|
|
24
24
|
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send( { status: StatusCodes.INTERNAL_SERVER_ERROR, error: 'Operation was not successful', detail: error } );
|
|
25
25
|
}
|
|
26
26
|
}
|
package/src/tcpclient/app.ts
CHANGED
|
@@ -10,10 +10,12 @@ const options: jayson.TcpClientOptions = {
|
|
|
10
10
|
|
|
11
11
|
const client = jayson.client.tls(options);
|
|
12
12
|
|
|
13
|
+
const LogInfoMessage = (message: any) => console.log(message)
|
|
14
|
+
|
|
13
15
|
// create a client
|
|
14
16
|
|
|
15
17
|
// invoke "add"
|
|
16
18
|
client.request('add', [1, 1], function(err: any, response: any) {
|
|
17
19
|
if(err) throw err;
|
|
18
|
-
|
|
20
|
+
LogInfoMessage(response.result); // 2
|
|
19
21
|
});
|
package/src/tcpclient/app2.ts
CHANGED
|
@@ -11,13 +11,15 @@ const options = {
|
|
|
11
11
|
|
|
12
12
|
const done: boolean[] = [];
|
|
13
13
|
|
|
14
|
+
const LogInfoMessage = (message: any) => console.log(message)
|
|
15
|
+
|
|
14
16
|
const dosomework = (socket: any, index: number) => {
|
|
15
|
-
|
|
17
|
+
LogInfoMessage('Connected');
|
|
16
18
|
socket.write("Hello From Client " + JSON.stringify(socket.address()));
|
|
17
19
|
(async () => {
|
|
18
20
|
for (;;) {
|
|
19
21
|
const msg = `${new Date()}: Hello`;
|
|
20
|
-
|
|
22
|
+
LogInfoMessage(`sending: [${msg}]`);
|
|
21
23
|
socket.write(msg);
|
|
22
24
|
await Sleep(1000);
|
|
23
25
|
if (done[index]) {
|
|
@@ -34,11 +36,11 @@ for (let i=0; i < 6; i++) {
|
|
|
34
36
|
dosomework(socket1, i);
|
|
35
37
|
});
|
|
36
38
|
socket1.on('close', function(data: any) {
|
|
37
|
-
|
|
39
|
+
LogInfoMessage(chalk.yellow(`CLOSED: ${socket1.remoteAddress} ${socket1.remotePort}`));
|
|
38
40
|
done[i]=true;
|
|
39
41
|
});
|
|
40
42
|
socket1.on('data', function(data: any) {
|
|
41
|
-
|
|
43
|
+
LogInfoMessage(chalk.yellow(`DATA ${socket1.remoteAddress} ${socket1.remotePort} ${data}`));
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -48,9 +50,9 @@ socket2.on('secureConnect', () => {
|
|
|
48
50
|
dosomework(socket2);
|
|
49
51
|
});
|
|
50
52
|
socket2.on('close', function(data: any) {
|
|
51
|
-
|
|
53
|
+
LogInfoMessage(chalk.green(`CLOSED: ${socket2.remoteAddress} ${socket2.remotePort}`));
|
|
52
54
|
});
|
|
53
55
|
socket2.on('data', function(data: any) {
|
|
54
|
-
|
|
56
|
+
LogInfoMessage(chalk.green(`DATA ${socket2.remoteAddress} ${socket2.remotePort} ${data}`));
|
|
55
57
|
});
|
|
56
58
|
*/
|
|
@@ -5,6 +5,8 @@ const goptions = $Options()
|
|
|
5
5
|
|
|
6
6
|
import { ProcessOptions, STSServerType } from '../index'
|
|
7
7
|
|
|
8
|
+
import winston from 'winston'
|
|
9
|
+
|
|
8
10
|
/*
|
|
9
11
|
// nid: `${goptions.rest01servicename} @ ${goptions.rest01serviceversion} | ${this.options.globalServiceData.serviceInstanceId} @ ${os.hostname()} ^ ${process.pid} @ ${(cluster.isMaster ? process.pid : process.ppid)}`,
|
|
10
12
|
// <serviceId> <serviceInstanceId> <serviceInstanceProcessId>
|
|
@@ -24,6 +26,22 @@ ${process.pid}${ModelDelimeter.COMPONENT_SEPERATOR}${(isMaster ? process.pid : p
|
|
|
24
26
|
*/
|
|
25
27
|
|
|
26
28
|
export function ServiceConfigOptions(clusterMode: boolean, isMaster: boolean): ProcessOptions {
|
|
29
|
+
winston.format.combine(
|
|
30
|
+
winston.format.colorize(),
|
|
31
|
+
winston.format.simple()
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const logger = winston.createLogger({
|
|
35
|
+
level: 'silly',
|
|
36
|
+
format: winston.format.combine(
|
|
37
|
+
winston.format.colorize(),
|
|
38
|
+
winston.format.simple()
|
|
39
|
+
),
|
|
40
|
+
transports: [
|
|
41
|
+
new winston.transports.Console()
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
|
|
27
45
|
if (isMaster === true) {
|
|
28
46
|
const serviceInstanceId = uuidv4();
|
|
29
47
|
const data: ProcessOptions = {
|
|
@@ -55,11 +73,14 @@ export function ServiceConfigOptions(clusterMode: boolean, isMaster: boolean): P
|
|
|
55
73
|
instrumentationObservationInterval: goptions.instrumentationObservationInterval,
|
|
56
74
|
instrumentationTimeWindow: goptions.instrumentationTimeWindow,
|
|
57
75
|
|
|
58
|
-
useRedisAdaptor: false
|
|
76
|
+
useRedisAdaptor: false,
|
|
77
|
+
|
|
78
|
+
logger: logger
|
|
59
79
|
}
|
|
60
80
|
return data;
|
|
61
81
|
} else {
|
|
62
82
|
const data: ProcessOptions = JSON.parse(process.env['STS_GSD_SII'] as string) as ProcessOptions;
|
|
83
|
+
data.logger = logger;
|
|
63
84
|
return data;
|
|
64
85
|
}
|
|
65
86
|
}
|
|
@@ -95,6 +95,14 @@ export class AppMaster extends MasterProcessBase
|
|
|
95
95
|
this.#heartBeatTimeout = 750; //@@ config - also must be smaller than electionTimeout
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
#LogErrorMessage(message: any) {
|
|
99
|
+
this.options.logger.error(message);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#LogInfoMessage(message: any) {
|
|
103
|
+
this.options.logger.error(message);
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
#GetTLSOptions = (): JSONObject => {
|
|
99
107
|
return {
|
|
100
108
|
key: fs.readFileSync(this.options.httpsServerKeyPath),
|
|
@@ -103,14 +111,14 @@ export class AppMaster extends MasterProcessBase
|
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
#SetupRPCServer = async (socket: net.Socket): Promise<void> => {
|
|
106
|
-
|
|
114
|
+
this.#LogInfoMessage('CONNECTED: ' + socket.remoteAddress + ':' + socket.remotePort + ' ' + process.pid);
|
|
107
115
|
|
|
108
|
-
socket.on('close',
|
|
109
|
-
|
|
116
|
+
socket.on('close', (data: any) => {
|
|
117
|
+
this.#LogInfoMessage('CLOSED: ' + socket.remoteAddress + ' ' + socket.remotePort + ' ' + process.pid);
|
|
110
118
|
});
|
|
111
119
|
|
|
112
|
-
socket.on('data',
|
|
113
|
-
|
|
120
|
+
socket.on('data', (data: any) => {
|
|
121
|
+
this.#LogInfoMessage('DATA ' + socket.remoteAddress + ': ' + data);
|
|
114
122
|
});
|
|
115
123
|
}
|
|
116
124
|
|
|
@@ -124,7 +132,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
124
132
|
// Update my currentTerm
|
|
125
133
|
this.#currentTerm = term;
|
|
126
134
|
// Return my yes vote
|
|
127
|
-
|
|
135
|
+
this.#LogInfoMessage(chalk.green(`${message} - Vote Yes`));
|
|
128
136
|
callback(null, true); // YES vote
|
|
129
137
|
}
|
|
130
138
|
|
|
@@ -132,7 +140,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
132
140
|
// Log the fact that I have now voted for this currentTerm
|
|
133
141
|
this.#votedLog[term] = true;
|
|
134
142
|
// Return my yes vote
|
|
135
|
-
|
|
143
|
+
this.#LogInfoMessage(chalk.yellow(`${message} - Vote No`));
|
|
136
144
|
callback(null, false); // NO vote
|
|
137
145
|
}
|
|
138
146
|
|
|
@@ -230,20 +238,20 @@ export class AppMaster extends MasterProcessBase
|
|
|
230
238
|
if (this.#RAFTState.localeCompare(AppMasterRAFTState.CANDIDATE) === 0) {
|
|
231
239
|
const retVal = this.#CheckMoreRecentTerm(term, lastLogItemTerm, lastLogItemIndex);
|
|
232
240
|
if (retVal.retVal === true) {
|
|
233
|
-
|
|
234
|
-
|
|
241
|
+
this.#LogInfoMessage(`${retVal.msg}`);
|
|
242
|
+
this.#LogInfoMessage(chalk.magenta(`${this.#GetLogPrefix()}: New leader detected, Host: [${host}], Port: [${port}], while in CANDIDATE mode, reverting to FOLLOWER.`));
|
|
235
243
|
// This sending node is the leader so revert to follower
|
|
236
244
|
this.#currentTerm = term;
|
|
237
245
|
this.#ChangeState(AppMasterRAFTState.FOLLOWER);
|
|
238
246
|
} else {
|
|
239
|
-
|
|
240
|
-
|
|
247
|
+
this.#LogInfoMessage(`${retVal.msg}`);
|
|
248
|
+
this.#LogInfoMessage(chalk.magenta(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`));
|
|
241
249
|
// Reject this RPC and continue in the CANDIDATE state
|
|
242
250
|
callback(null, false);
|
|
243
251
|
return;
|
|
244
252
|
}
|
|
245
253
|
} else if (this.#RAFTState.localeCompare(AppMasterRAFTState.LEADER) === 0) {
|
|
246
|
-
|
|
254
|
+
this.#LogInfoMessage(chalk.red(`${this.#GetLogPrefix()}: appendEntry called while I am the current leader, rejecting RPC call.`));
|
|
247
255
|
// Reject this RPC and continue in the LEADER state
|
|
248
256
|
callback(null, false);
|
|
249
257
|
return;
|
|
@@ -255,12 +263,12 @@ export class AppMaster extends MasterProcessBase
|
|
|
255
263
|
const retVal = this.#CheckMoreRecentTerm(term, lastLogItemTerm, lastLogItemIndex);
|
|
256
264
|
if (retVal.retVal === true) {
|
|
257
265
|
if (term > this.#currentTerm) {
|
|
258
|
-
|
|
266
|
+
this.#LogInfoMessage(chalk.cyan(`${retVal.msg}`));
|
|
259
267
|
this.#currentTerm = term;
|
|
260
268
|
}
|
|
261
269
|
} else {
|
|
262
|
-
|
|
263
|
-
|
|
270
|
+
this.#LogInfoMessage(`${retVal.msg}`);
|
|
271
|
+
this.#LogInfoMessage(chalk.magenta(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`));
|
|
264
272
|
// Reject this RPC and continue in the CANDIDATE state
|
|
265
273
|
callback(null, false);
|
|
266
274
|
return;
|
|
@@ -272,13 +280,13 @@ export class AppMaster extends MasterProcessBase
|
|
|
272
280
|
if (sentLeaderService) {
|
|
273
281
|
if (sentLeaderService.host.localeCompare(this.#leaderNode.host) !== 0 || sentLeaderService.port !== this.#leaderNode.port) {
|
|
274
282
|
this.#leaderNode = sentLeaderService;
|
|
275
|
-
|
|
283
|
+
this.#LogInfoMessage(chalk.white(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`));
|
|
276
284
|
}
|
|
277
285
|
}
|
|
278
286
|
} else {
|
|
279
287
|
this.#leaderNode = this.#FindService(host, port);
|
|
280
288
|
if (this.#leaderNode) {
|
|
281
|
-
|
|
289
|
+
this.#LogInfoMessage(chalk.white(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`));
|
|
282
290
|
}
|
|
283
291
|
}
|
|
284
292
|
|
|
@@ -286,9 +294,9 @@ export class AppMaster extends MasterProcessBase
|
|
|
286
294
|
callback(null, true);
|
|
287
295
|
});
|
|
288
296
|
|
|
289
|
-
jaysonServer.method("ping", async
|
|
297
|
+
jaysonServer.method("ping", async (args: any, callback: any) => {
|
|
290
298
|
// do something, do nothing
|
|
291
|
-
|
|
299
|
+
this.#LogInfoMessage('server got ping');
|
|
292
300
|
callback();
|
|
293
301
|
});
|
|
294
302
|
|
|
@@ -296,7 +304,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
296
304
|
//(server as tls.Server).on('secureConnection', this.#SetupRPCServer);
|
|
297
305
|
//server.listen(this.options.listenPort, () => { // 'stscore.stsmda.org'
|
|
298
306
|
server.listen(this.#serverPort, () => { // 'stscore.stsmda.org'
|
|
299
|
-
|
|
307
|
+
this.#LogInfoMessage('JSON RPC 2.0 Server is running on port ' + this.options.listenPort + '.');
|
|
300
308
|
}).on('listening', () =>
|
|
301
309
|
{
|
|
302
310
|
this.LogEx(`JSON RPC 2.0 live on ${this.options.endpoint}:${this.options.listenPort}${this.options.apiRoot}`);
|
|
@@ -325,7 +333,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
325
333
|
|
|
326
334
|
client.request('vote', [ this.#currentTerm, lastLogItem.term, lastLogItem.index ], (error: any, response: any) => {
|
|
327
335
|
if (error) {
|
|
328
|
-
//
|
|
336
|
+
//this.#LogInfoMessage(chalk.red(`vote attempt fail: [${JSON.stringify(options)}: ${error}]`));
|
|
329
337
|
} else {
|
|
330
338
|
// Log the result
|
|
331
339
|
if (response.result === true) {
|
|
@@ -357,7 +365,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
357
365
|
|
|
358
366
|
client.request('appendEntry', [ this.#thisService.host, this.#thisService.port, this.#currentTerm, lastLogItem.term, lastLogItem.index ], (error: any, response: any) => {
|
|
359
367
|
if (error) {
|
|
360
|
-
//
|
|
368
|
+
//this.#LogInfoMessage(chalk.red(`appendEntry attempt fail: [${JSON.stringify(options)}: ${error}]`));
|
|
361
369
|
} else {
|
|
362
370
|
this.#appendedEntries[this.#GetServiceKey(service)] = 1;
|
|
363
371
|
// Log the result
|
|
@@ -409,14 +417,14 @@ export class AppMaster extends MasterProcessBase
|
|
|
409
417
|
if (majority) {
|
|
410
418
|
this.#StartAppendEntries();
|
|
411
419
|
} else {
|
|
412
|
-
|
|
420
|
+
this.#LogInfoMessage(chalk.red(`${this.#GetLogPrefix()}: Not enough response for valid cluster state.`));
|
|
413
421
|
}
|
|
414
422
|
}, this.#heartBeatTimeout);
|
|
415
423
|
}
|
|
416
424
|
|
|
417
425
|
#Promote = () => {
|
|
418
426
|
this.#ChangeState(AppMasterRAFTState.LEADER);
|
|
419
|
-
|
|
427
|
+
this.#LogInfoMessage(chalk.green(`${this.#GetLogPrefix()}: New LEADER is elected: [${this.#GetSelfServiceKey()}]`));
|
|
420
428
|
// As leader, now start the regular pings
|
|
421
429
|
this.#StartAppendEntries();
|
|
422
430
|
}
|
|
@@ -435,7 +443,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
435
443
|
const requiredVotes = Math.floor(this.#services.length / 2) + 1;
|
|
436
444
|
|
|
437
445
|
if (requiredVotes !== this.#lastRequiredVotes || votes !== this.#lastVotes) {
|
|
438
|
-
|
|
446
|
+
this.#LogInfoMessage(chalk.cyan(`${this.#GetLogPrefix()}votes: [${votes} need: [${requiredVotes}]`));
|
|
439
447
|
this.#lastRequiredVotes = requiredVotes;
|
|
440
448
|
this.#lastVotes = votes;
|
|
441
449
|
}
|
|
@@ -448,7 +456,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
448
456
|
// Get the election timeout going again
|
|
449
457
|
this.#StartElectionTimeout();
|
|
450
458
|
|
|
451
|
-
|
|
459
|
+
this.#LogInfoMessage(chalk.yellow(`${this.#GetLogPrefix()}: Start CANDIDATE vote`));
|
|
452
460
|
// Start in the CANDIDATE state
|
|
453
461
|
this.#ChangeState(AppMasterRAFTState.CANDIDATE);
|
|
454
462
|
// Reset votes
|
|
@@ -470,7 +478,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
470
478
|
// Log the result - Vote for myself
|
|
471
479
|
this.#votes[this.#GetSelfServiceKey()] = 1;
|
|
472
480
|
// Return my yes vote
|
|
473
|
-
|
|
481
|
+
this.#LogInfoMessage(chalk.green(`${this.#GetLogPrefix()}: SELF VOTE: canidate currentTerm: [${this.#currentTerm}], vote YES`));
|
|
474
482
|
this.#CheckMajority();
|
|
475
483
|
} else {
|
|
476
484
|
// Send vote request
|
package/src/testing/app.ts
CHANGED
|
@@ -12,6 +12,8 @@ const pid = 523552
|
|
|
12
12
|
|
|
13
13
|
const filePath = `/proc/${pid}/net/dev`;
|
|
14
14
|
|
|
15
|
+
const LogInfoMessage = (message: any) => console.log(message)
|
|
16
|
+
const LogErrorMessage = (message: any) => console.error(message)
|
|
15
17
|
/*
|
|
16
18
|
async function testError() {
|
|
17
19
|
throw new Error('some error')
|
|
@@ -21,7 +23,7 @@ async function testtheerror() {
|
|
|
21
23
|
try {
|
|
22
24
|
await testError();
|
|
23
25
|
} catch (error) {
|
|
24
|
-
|
|
26
|
+
this.#LogErrorMessage(`Error2: [${error}]`);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -31,14 +33,14 @@ async function testtheerror2(cb: (error: any) => void) {
|
|
|
31
33
|
cb('some error');
|
|
32
34
|
|
|
33
35
|
} catch (error) {
|
|
34
|
-
|
|
36
|
+
this.#LogErrorMessage(`Error2: [${error}]`);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
(async () => {
|
|
39
41
|
await Sleep(1000);
|
|
40
|
-
let z = await testtheerror2((error) =>
|
|
41
|
-
|
|
42
|
+
let z = await testtheerror2((error) => this.#LogInfoMessage(error));
|
|
43
|
+
this.#LogInfoMessage(`done.....`);
|
|
42
44
|
|
|
43
45
|
process.exit(0);
|
|
44
46
|
})();
|
|
@@ -55,7 +57,7 @@ function getNetworkUsage() {
|
|
|
55
57
|
const headers2 = lines[1].split('|').map(header => header.trim());
|
|
56
58
|
const data = lines[2].split('|').map(value => value.trim());
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
LogInfoMessage(data);
|
|
59
61
|
|
|
60
62
|
// Find the index of the relevant network statistics (e.g., bytes received and transmitted)
|
|
61
63
|
//const rxIndex = headers.indexOf('Receive');
|
|
@@ -63,12 +65,12 @@ function getNetworkUsage() {
|
|
|
63
65
|
|
|
64
66
|
// Display network usage information
|
|
65
67
|
/*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
this.#LogInfoMessage(`Network Usage for Process ${pid}:`);
|
|
69
|
+
this.#LogInfoMessage(` Incoming: ${data[rxIndex]} bytes`);
|
|
70
|
+
this.#LogInfoMessage(` Outgoing: ${data[txIndex]} bytes`);
|
|
69
71
|
*/
|
|
70
|
-
} catch (
|
|
71
|
-
|
|
72
|
+
} catch (error) {
|
|
73
|
+
LogErrorMessage(`Error reading file: [${error}]`);
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
|
|
@@ -78,13 +80,13 @@ if (cluster.isPrimary) {
|
|
|
78
80
|
setInterval(function() {
|
|
79
81
|
/*
|
|
80
82
|
si.networkStats().then(data => {
|
|
81
|
-
|
|
83
|
+
this.#LogInfoMessage(data);
|
|
82
84
|
});
|
|
83
85
|
*/
|
|
84
86
|
|
|
85
87
|
getNetworkUsage()
|
|
86
88
|
|
|
87
|
-
//
|
|
89
|
+
//this.#LogInfoMessage(process.pid)
|
|
88
90
|
|
|
89
91
|
//getNetworkUsage()
|
|
90
92
|
|
package/src/testing/appConfig.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { ProcessOptions, IProcessBase, STSServerType } from './..'
|
|
|
8
8
|
|
|
9
9
|
import { STSExpressRouteFactory } from './server'
|
|
10
10
|
|
|
11
|
+
import winston from 'winston'
|
|
12
|
+
|
|
11
13
|
/*
|
|
12
14
|
// nid: `${goptions.rest01servicename} @ ${goptions.rest01serviceversion} | ${this.options.globalServiceData.serviceInstanceId} @ ${os.hostname()} ^ ${process.pid} @ ${(cluster.isMaster ? process.pid : process.ppid)}`,
|
|
13
15
|
// <serviceId> <serviceInstanceId> <serviceInstanceProcessId>
|
|
@@ -27,6 +29,22 @@ ${process.pid}${ModelDelimeter.COMPONENT_SEPERATOR}${(isMaster ? process.pid : p
|
|
|
27
29
|
*/
|
|
28
30
|
|
|
29
31
|
export function ServiceConfigOptions(clusterMode: boolean, isMaster: boolean): ProcessOptions {
|
|
32
|
+
winston.format.combine(
|
|
33
|
+
winston.format.colorize(),
|
|
34
|
+
winston.format.simple()
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const logger = winston.createLogger({
|
|
38
|
+
level: 'silly',
|
|
39
|
+
format: winston.format.combine(
|
|
40
|
+
winston.format.colorize(),
|
|
41
|
+
winston.format.simple()
|
|
42
|
+
),
|
|
43
|
+
transports: [
|
|
44
|
+
new winston.transports.Console()
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
|
|
30
48
|
if (isMaster === true) {
|
|
31
49
|
const serviceInstanceId = uuidv4();
|
|
32
50
|
const data: ProcessOptions = {
|
|
@@ -56,7 +74,9 @@ export function ServiceConfigOptions(clusterMode: boolean, isMaster: boolean): P
|
|
|
56
74
|
instrumentationTimeWindow: goptions.instrumentationTimeWindow,
|
|
57
75
|
|
|
58
76
|
useRedisAdaptor: false,
|
|
59
|
-
workerExec: './dist/testing/app.js'
|
|
77
|
+
workerExec: './dist/testing/app.js',
|
|
78
|
+
|
|
79
|
+
logger: logger
|
|
60
80
|
}
|
|
61
81
|
|
|
62
82
|
if (!clusterMode) {
|
|
@@ -71,6 +91,7 @@ export function ServiceConfigOptions(clusterMode: boolean, isMaster: boolean): P
|
|
|
71
91
|
data.expressServerRouteFactory = (app: express.Express, stsApp: IProcessBase) => {
|
|
72
92
|
return new STSExpressRouteFactory(app, stsApp);
|
|
73
93
|
}
|
|
94
|
+
data.logger = logger;
|
|
74
95
|
return data;
|
|
75
96
|
}
|
|
76
97
|
}
|
|
@@ -3,7 +3,7 @@ import cluster from 'node:cluster';
|
|
|
3
3
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
|
|
6
|
-
import { WorkerProcessBase, STSNamespace, STSRoom, SocketIoServerHelper, STSSocketIONamespace } from './../index'
|
|
6
|
+
import { WorkerProcessBase, STSNamespace, STSRoom, SocketIoServerHelper, STSSocketIONamespace, ProcessOptions } from './../index'
|
|
7
7
|
|
|
8
8
|
//import { Socket, Namespace } from "socket.io";
|
|
9
9
|
import { Socket } from "socket.io";
|
|
@@ -39,7 +39,7 @@ export class WorkerProcess extends WorkerProcessBase
|
|
|
39
39
|
{
|
|
40
40
|
#terminate = false;
|
|
41
41
|
|
|
42
|
-
constructor(options:
|
|
42
|
+
constructor(options: ProcessOptions)
|
|
43
43
|
{
|
|
44
44
|
super(options);
|
|
45
45
|
|
|
@@ -52,18 +52,26 @@ export class WorkerProcess extends WorkerProcessBase
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
#LogErrorMessage(message: any) {
|
|
56
|
+
this.options.logger.error(message);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#LogInfoMessage(message: any) {
|
|
60
|
+
this.options.logger.info(message);
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
64
|
ReceivedMessageFromMaster = async (messageData: any) => {
|
|
57
65
|
// Only response to these message types (note should be part of generic pub/sub pattern in framework)
|
|
58
66
|
if (messageData.subCommand) {
|
|
59
67
|
if (messageData.subCommand.localeCompare(InstrumentManagerSubCommand.OUTPUT_SUBSCRIPTION) === 0) {
|
|
60
|
-
//
|
|
61
|
-
|
|
68
|
+
//this.#LogInfoMessage(chalk.gray(`WorkerProcess.ReceivedMessageFromMaster: messageData: [${JSON.stringify(messageData)}]`));
|
|
69
|
+
this.#LogInfoMessage(chalk.gray(`WorkerProcess.ReceivedMessageFromMaster`));
|
|
62
70
|
const { socketId, workerId } = messageData; //@@ type
|
|
63
71
|
|
|
64
72
|
if (cluster.worker && cluster.worker.id !== workerId) {
|
|
65
73
|
// Invalid data - this workerId must match
|
|
66
|
-
|
|
74
|
+
this.#LogInfoMessage(chalk.red(`WorkerProcess.ReceivedMessageFromMaster: Invalid workerId: [${workerId}]. Should have been: [${cluster.worker.id}].`));
|
|
67
75
|
} else {
|
|
68
76
|
const workerProcess: WorkerProcess = this as WorkerProcess;
|
|
69
77
|
if (workerProcess.stsMonitorNamespace !== null) {
|
|
@@ -71,16 +79,16 @@ export class WorkerProcess extends WorkerProcessBase
|
|
|
71
79
|
const sockets = await stsMonitorNamespace.fetchSockets();
|
|
72
80
|
for (const socket of sockets) {
|
|
73
81
|
if (socket.id.localeCompare(socketId) === 0) {
|
|
74
|
-
|
|
82
|
+
this.#LogInfoMessage(chalk.green(`WorkerProcess.ReceivedMessageFromMaster: Sending payload to subscribed client.`));
|
|
75
83
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
84
|
//socket.emit(STSEvent.STSSubInstrumentData as any, model);
|
|
77
85
|
return;
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
|
-
|
|
88
|
+
this.#LogInfoMessage(chalk.red(`WorkerProcess.ReceivedMessageFromMaster: Invalid socketId. Expecting socket to existing in socket namespace collection.`));
|
|
81
89
|
// Invalid - could not find matching socketid to send to
|
|
82
90
|
} else {
|
|
83
|
-
|
|
91
|
+
this.#LogInfoMessage(chalk.red(`WorkerProcess.ReceivedMessageFromMaster: Invalid workerProcess.stsMonitorNamespace is null. Expecting non-null value.`));
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
}
|
|
@@ -90,22 +98,22 @@ export class WorkerProcess extends WorkerProcessBase
|
|
|
90
98
|
#SendIPCMessageToMaster(socket: Socket, eventName: any, data: any): void {
|
|
91
99
|
try {
|
|
92
100
|
if (cluster.worker) {
|
|
93
|
-
|
|
101
|
+
this.#LogInfoMessage(chalk.gray(`WorkerProcess.#SendIPCMessageToMaster: eventName: [${eventName}]`));
|
|
94
102
|
const payload: IIPCSocketMessage = {
|
|
95
103
|
socketId: socket.id,
|
|
96
104
|
workerId: cluster.worker.id,
|
|
97
105
|
data: data
|
|
98
106
|
}
|
|
99
|
-
//
|
|
100
|
-
|
|
107
|
+
//this.#LogInfoMessage(chalk.gray(`WorkerProcess.#SendIPCMessageToMaster: payload: [${JSON.stringify(payload)}]`));
|
|
108
|
+
this.#LogInfoMessage(chalk.gray(`WorkerProcess.#SendIPCMessageToMaster`));
|
|
101
109
|
(process as any).send( { command: eventName, payload }, null, { swallowErrors: true }, (error: any) => {
|
|
102
110
|
if (error) {
|
|
103
|
-
|
|
111
|
+
this.#LogErrorMessage(chalk.red(`Error with WorkerProcess:SendIPCMessageToMaster(1): [${error}]`));
|
|
104
112
|
}
|
|
105
113
|
});
|
|
106
114
|
}
|
|
107
115
|
} catch (error) {
|
|
108
|
-
|
|
116
|
+
this.#LogErrorMessage(chalk.red(`Error with WorkerProcess:SendIPCMessageToMaster(2): [${error}]`));
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
119
|
|
|
@@ -125,7 +133,7 @@ export class WorkerProcess extends WorkerProcessBase
|
|
|
125
133
|
|
|
126
134
|
// Connect call back when a client connects
|
|
127
135
|
(socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => {
|
|
128
|
-
|
|
136
|
+
this.#LogInfoMessage(chalk.gray(`WorkerProcess.#SendIPCMessageToMaster: Id: [${socket.id}] eventName: [${InstrumentManagerEventName.CONNECT}]`));
|
|
129
137
|
},
|
|
130
138
|
|
|
131
139
|
// Custom client to server events
|
package/src/testing/appsolo.ts
CHANGED
|
@@ -9,10 +9,13 @@ const oldResRx: number[] = []
|
|
|
9
9
|
const newResRx: number[] = []
|
|
10
10
|
const newResTx: number[] = []
|
|
11
11
|
|
|
12
|
+
const LogInfoMessage = (message: any) => console.log(message)
|
|
13
|
+
const LogErrorMessage = (message: any) => console.error(message)
|
|
14
|
+
|
|
12
15
|
function getNetworkUsage(pidArray: number[]) {
|
|
13
16
|
try {
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
LogInfoMessage(chalk.white.bgCyan.bold('Hello World'));
|
|
16
19
|
|
|
17
20
|
for (let i=0; i < pidArray.length; i++) {
|
|
18
21
|
|
|
@@ -28,7 +31,7 @@ function getNetworkUsage(pidArray: number[]) {
|
|
|
28
31
|
const lines = content.trim().split('\n');
|
|
29
32
|
|
|
30
33
|
|
|
31
|
-
//
|
|
34
|
+
//this.#LogInfoMessage(lines[3]);
|
|
32
35
|
|
|
33
36
|
|
|
34
37
|
const headers1 = lines[0].split('|').map(header => header.trim());
|
|
@@ -42,19 +45,19 @@ function getNetworkUsage(pidArray: number[]) {
|
|
|
42
45
|
|
|
43
46
|
const result = mystr.replace(/\s+/g, ' ').trim().split(' ');
|
|
44
47
|
|
|
45
|
-
//
|
|
48
|
+
//this.#LogInfoMessage(`${result}`);
|
|
46
49
|
|
|
47
50
|
newResRx[i] = parseFloat(result[0]);
|
|
48
51
|
newResTx[i] = parseFloat(result[8]);
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
LogInfoMessage(`${pid} ${i}: ${newResRx[i]} ${newResTx[i]} : ${(newResRx[i] - oldResRx[i])/1000000.0} ${(newResTx[i] - oldResTx[i])/1000000.0}`);
|
|
51
54
|
|
|
52
55
|
oldResTx[i] = newResTx[i];
|
|
53
56
|
oldResRx[i] = newResRx[i];
|
|
54
57
|
|
|
55
|
-
//
|
|
58
|
+
//this.#LogInfoMessage(uint8Array);
|
|
56
59
|
|
|
57
|
-
//
|
|
60
|
+
//this.#LogInfoMessage(data2[1].split('\t'));
|
|
58
61
|
|
|
59
62
|
// Find the index of the relevant network statistics (e.g., bytes received and transmitted)
|
|
60
63
|
//const rxIndex = headers.indexOf('Receive');
|
|
@@ -63,26 +66,26 @@ function getNetworkUsage(pidArray: number[]) {
|
|
|
63
66
|
|
|
64
67
|
// Display network usage information
|
|
65
68
|
/*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
this.#LogInfoMessage(`Network Usage for Process ${pid}:`);
|
|
70
|
+
this.#LogInfoMessage(` Incoming: ${data[rxIndex]} bytes`);
|
|
71
|
+
this.#LogInfoMessage(` Outgoing: ${data[txIndex]} bytes`);
|
|
69
72
|
*/
|
|
70
73
|
}
|
|
71
|
-
} catch (
|
|
72
|
-
|
|
74
|
+
} catch (error) {
|
|
75
|
+
LogErrorMessage(`Error reading file: [${error}]`);
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
setInterval(function() {
|
|
77
80
|
/*
|
|
78
81
|
si.networkStats().then(data => {
|
|
79
|
-
|
|
82
|
+
this.#LogInfoMessage(data);
|
|
80
83
|
});
|
|
81
84
|
*/
|
|
82
85
|
|
|
83
86
|
getNetworkUsage([ 523493, 523552, 523553, 523554]);
|
|
84
87
|
|
|
85
|
-
//
|
|
88
|
+
//this.#LogInfoMessage(process.pid)
|
|
86
89
|
|
|
87
90
|
//getNetworkUsage()
|
|
88
91
|
|