@nsshunt/stsappframework 3.0.90 → 3.0.92

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.
Files changed (88) hide show
  1. package/dist/authutilsnode.js +15 -14
  2. package/dist/authutilsnode.js.map +1 -1
  3. package/dist/influxdb/influxDBManager.js +21 -20
  4. package/dist/influxdb/influxDBManager.js.map +1 -1
  5. package/dist/influxdb/influxDBManagerAgent.js +13 -9
  6. package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
  7. package/dist/influxdb/influxDBManagerBase.js +6 -2
  8. package/dist/influxdb/influxDBManagerBase.js.map +1 -1
  9. package/dist/influxdb/influxDBManagerService.js +14 -10
  10. package/dist/influxdb/influxDBManagerService.js.map +1 -1
  11. package/dist/instrumentationsubscriber.js +19 -15
  12. package/dist/instrumentationsubscriber.js.map +1 -1
  13. package/dist/kafka/IMKafkaManager.js +6 -2
  14. package/dist/kafka/IMKafkaManager.js.map +1 -1
  15. package/dist/kafka/kafkaconsumer.js.map +1 -1
  16. package/dist/kafka/kafkamanager.js +1 -1
  17. package/dist/kafka/kafkamanager.js.map +1 -1
  18. package/dist/kafka/kafkaproducer.js.map +1 -1
  19. package/dist/kafkatesting/consume.js.map +1 -1
  20. package/dist/kafkatesting/produce.js +5 -1
  21. package/dist/kafkatesting/produce.js.map +1 -1
  22. package/dist/masterprocessbase.js +20 -19
  23. package/dist/masterprocessbase.js.map +1 -1
  24. package/dist/middleware/serverNetworkMiddleware.js.map +1 -1
  25. package/dist/network.js.map +1 -1
  26. package/dist/processbase.js +8 -8
  27. package/dist/processbase.js.map +1 -1
  28. package/dist/publishertransports/publishTransportDirect.js.map +1 -1
  29. package/dist/publishertransports/publishTransportUtils.js.map +1 -1
  30. package/dist/server.js +1 -1
  31. package/dist/server.js.map +1 -1
  32. package/dist/serverprocessbase.js.map +1 -1
  33. package/dist/singleprocessbase.js +4 -3
  34. package/dist/singleprocessbase.js.map +1 -1
  35. package/dist/socketIoServerHelper.js.map +1 -1
  36. package/dist/stslatencycontroller.js.map +1 -1
  37. package/dist/tcpclient/app2.js +2 -2
  38. package/dist/tcpclient/app2.js.map +1 -1
  39. package/dist/tcpserver/app.js.map +1 -1
  40. package/dist/tcpserver/appConfig.js.map +1 -1
  41. package/dist/tcpserver/appmaster.js +16 -39
  42. package/dist/tcpserver/appmaster.js.map +1 -1
  43. package/dist/testing/app.js.map +1 -1
  44. package/dist/testing/appConfig.js.map +1 -1
  45. package/dist/testing/appWorkerWSS.js +7 -6
  46. package/dist/testing/appWorkerWSS.js.map +1 -1
  47. package/dist/testing/appsolo.js.map +1 -1
  48. package/dist/testing/singleservertest.test.js +10 -9
  49. package/dist/testing/singleservertest.test.js.map +1 -1
  50. package/dist/webworkertesting/app.js.map +1 -1
  51. package/dist/webworkertesting/worker.js.map +1 -1
  52. package/dist/workerprocessbase.js +4 -3
  53. package/dist/workerprocessbase.js.map +1 -1
  54. package/package.json +13 -13
  55. package/src/authutilsnode.ts +10 -8
  56. package/src/influxdb/influxDBManager.ts +18 -16
  57. package/src/influxdb/influxDBManagerAgent.ts +11 -9
  58. package/src/influxdb/influxDBManagerBase.ts +4 -2
  59. package/src/influxdb/influxDBManagerService.ts +12 -10
  60. package/src/instrumentationsubscriber.ts +14 -11
  61. package/src/kafka/IMKafkaManager.ts +4 -2
  62. package/src/kafkatesting/produce.ts +3 -1
  63. package/src/masterprocessbase.ts +24 -32
  64. package/src/processbase.ts +9 -7
  65. package/src/server.ts +1 -1
  66. package/src/singleprocessbase.ts +5 -3
  67. package/src/tcpclient/app2.ts +2 -2
  68. package/src/tcpserver/appmaster.ts +17 -39
  69. package/src/testing/appWorkerWSS.ts +8 -6
  70. package/src/testing/singleservertest.test.ts +10 -8
  71. package/src/workerprocessbase.ts +5 -3
  72. package/types/authutilsnode.d.ts.map +1 -1
  73. package/types/commonTypes.d.ts +10 -10
  74. package/types/commonTypes.d.ts.map +1 -1
  75. package/types/influxdb/influxDBManager.d.ts.map +1 -1
  76. package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
  77. package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
  78. package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
  79. package/types/instrumentationsubscriber.d.ts.map +1 -1
  80. package/types/kafka/IMKafkaManager.d.ts.map +1 -1
  81. package/types/masterprocessbase.d.ts.map +1 -1
  82. package/types/processbase.d.ts +2 -2
  83. package/types/processbase.d.ts.map +1 -1
  84. package/types/singleprocessbase.d.ts.map +1 -1
  85. package/types/tcpserver/appmaster.d.ts.map +1 -1
  86. package/types/testing/appWorkerWSS.d.ts +1 -1
  87. package/types/testing/appWorkerWSS.d.ts.map +1 -1
  88. package/types/workerprocessbase.d.ts.map +1 -1
@@ -117,6 +117,8 @@ import { InfluxDBManagerBase } from './influxDBManagerBase'
117
117
  import { IInfluxDBManagerOptions, InstrumentPayload } from './../commonTypes'
118
118
  import { ISubscriptionPayload, ISubscriptionKey } from '@nsshunt/stssocketio-client'
119
119
 
120
+ import chalk from 'chalk';
121
+
120
122
  const _logPrefix = 'InfluxDBManagerService:'
121
123
 
122
124
  /*
@@ -179,7 +181,7 @@ data
179
181
 
180
182
  return this.queryApi.collectRows(query)
181
183
  } catch (error) {
182
- console.error(`${_logPrefix}#GetSTSCountGeneric: Error: [${error}]`.red);
184
+ console.error(chalk.red(`${_logPrefix}#GetSTSCountGeneric: Error: [${error}]`));
183
185
  }
184
186
  }
185
187
 
@@ -195,7 +197,7 @@ data
195
197
  |> difference()`;
196
198
  return this.queryApi.collectRows(query)
197
199
  } catch (error) {
198
- console.error(`${_logPrefix}#GetSTSHistoGeneric: Error: [${error}]`.red);
200
+ console.error(chalk.red(`${_logPrefix}#GetSTSHistoGeneric: Error: [${error}]`));
199
201
  }
200
202
  }
201
203
 
@@ -226,7 +228,7 @@ data
226
228
 
227
229
  return this.queryApi.collectRows(query)
228
230
  } catch (error) {
229
- console.error(`${_logPrefix}#GetSTSQuantileGeneric: Error: [${error}]`.red);
231
+ console.error(chalk.red(`${_logPrefix}#GetSTSQuantileGeneric: Error: [${error}]`));
230
232
  }
231
233
  }
232
234
 
@@ -241,7 +243,7 @@ data
241
243
  this.#GetSTSHistoGenericService(SERVICE_STATS_GLOBAL, '')],
242
244
  [ ])
243
245
  } catch (error) {
244
- console.error(`${_logPrefix}GetInfluxDBResultsRoot: Error: [${error}]`.red);
246
+ console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsRoot: Error: [${error}]`));
245
247
  }
246
248
  return {
247
249
  subscriptionKey,
@@ -259,7 +261,7 @@ data
259
261
  this.#GetSTSHistoGenericService(SERVICE_STATS_BY_SERVICE, '')],
260
262
  ['serviceId'])
261
263
  } catch (error) {
262
- console.error(`${_logPrefix}GetInfluxDBResultsService: Error: [${error}]`.red);
264
+ console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsService: Error: [${error}]`));
263
265
  }
264
266
  return {
265
267
  subscriptionKey,
@@ -279,7 +281,7 @@ data
279
281
  this.#GetSTSHistoGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE, `and r["serviceId"] == "${serviceId}"`)],
280
282
  ['serviceId', 'serviceInstanceId'])
281
283
  } catch (error) {
282
- console.error(`${_logPrefix}GetInfluxDBResultsServiceInstances: Error: [${error}]`.red);
284
+ console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsServiceInstances: Error: [${error}]`));
283
285
  }
284
286
  return {
285
287
  subscriptionKey,
@@ -298,7 +300,7 @@ data
298
300
  this.#GetSTSHistoGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE_PROCESS, `and r["serviceInstanceId"] == "${serviceInstanceId}"`)],
299
301
  ['serviceId', 'serviceInstanceId', 'serviceInstanceProcessId'])
300
302
  } catch (error) {
301
- console.error(`${_logPrefix}GetInfluxDBResultsServiceInstance: Error: [${error}]`.red);
303
+ console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsServiceInstance: Error: [${error}]`));
302
304
  }
303
305
  return {
304
306
  subscriptionKey,
@@ -361,12 +363,12 @@ data
361
363
  writeApi.writePoint(point);
362
364
  return true;
363
365
  } catch (error: any) {
364
- console.error(`${_logPrefix}OutputInfluxDB: Could not write data point: [${error}]`.red);
365
- console.error(`${JSON.stringify(instrumentPayload.context)}`.red);
366
+ console.error(chalk.red(`${_logPrefix}OutputInfluxDB: Could not write data point: [${error}]`));
367
+ console.error(chalk.red(`${JSON.stringify(instrumentPayload.context)}`));
366
368
  return false;
367
369
  }
368
370
  } else {
369
- console.error(`${_logPrefix}OutputInfluxDBService: Could not write data point as writeClient is null`.red);
371
+ console.error(chalk.red(`${_logPrefix}OutputInfluxDBService: Could not write data point as writeClient is null`));
370
372
  return false;
371
373
  }
372
374
  }
@@ -7,6 +7,9 @@ import { v4 as uuidv4 } from 'uuid';
7
7
 
8
8
  import { $Options } from '@nsshunt/stsconfig'
9
9
  import { STSOptionsBase } from '@nsshunt/stsutils';
10
+
11
+ import chalk from 'chalk';
12
+
10
13
  const goptions = $Options()
11
14
 
12
15
  declare interface IKafkaSubscription {
@@ -80,12 +83,12 @@ export class InstrumentationSubscriber extends STSOptionsBase {
80
83
  const kafka = subscription.kafka;
81
84
  if (kafka) {
82
85
  // Un-Subscribe from this kafka topic
83
- this.#Log(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Starting`.yellow)
86
+ this.#Log(chalk.yellow(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Starting`));
84
87
  await kafka.kafkaConsumer?.Stop();
85
88
  await kafka.kafkaConsumer?.Disconnect();
86
- this.#Log(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Completed.`.yellow)
89
+ this.#Log(chalk.yellow(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Completed.`));
87
90
  } else {
88
- this.#Log(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka details do not exist for this topc: [${JSON.stringify(subscription.subscriptionKey)}].`.magenta)
91
+ this.#Log(chalk.magenta(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka details do not exist for this topc: [${JSON.stringify(subscription.subscriptionKey)}].`));
89
92
  }
90
93
  };
91
94
  return unsubscribeKafka();
@@ -126,18 +129,18 @@ export class InstrumentationSubscriber extends STSOptionsBase {
126
129
  } as IKafkaData
127
130
  });
128
131
  } else {
129
- this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}] and key: [${key}] do not match`.red);
132
+ this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}] and key: [${key}] do not match`));
130
133
  }
131
134
  } else {
132
- this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}], key: [${key}], value: [${value}]`.red);
135
+ this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}], key: [${key}], value: [${value}]`));
133
136
  }
134
137
  } catch (error) {
135
- this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Error: [${error}]`.red);
138
+ this.#Log(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Error: [${error}]`));
136
139
  }
137
140
  });
138
- this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Subscribe to Kafka topc: [${kafka.kafkaTopic}] Completed`.yellow)
141
+ this.#Log(chalk.yellow(`InstrumentationSubscriber:#SubscribeKafka(): Subscribe to Kafka topc: [${kafka.kafkaTopic}] Completed`));
139
142
  } else {
140
- this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Could not subscribe to Kafka topc, missing combinedKey for topic: [${JSON.stringify(subscription.subscriptionKey)}]`.magenta);
143
+ this.#Log(chalk.magenta(`InstrumentationSubscriber:#SubscribeKafka(): Could not subscribe to Kafka topc, missing combinedKey for topic: [${JSON.stringify(subscription.subscriptionKey)}]`));
141
144
  }
142
145
  }
143
146
  return kafkaSubscribe();
@@ -212,7 +215,7 @@ export class InstrumentationSubscriber extends STSOptionsBase {
212
215
  }
213
216
  }
214
217
  } catch (error) {
215
- this.#Log(`InstrumentationSubscriber:#ExecuteSubscriptions(): Error: [${error}], [${JSON.stringify(retVal)}]`.red);
218
+ this.#Log(chalk.red(`InstrumentationSubscriber:#ExecuteSubscriptions(): Error: [${error}], [${JSON.stringify(retVal)}]`));
216
219
  }
217
220
  }
218
221
 
@@ -223,7 +226,7 @@ export class InstrumentationSubscriber extends STSOptionsBase {
223
226
  }
224
227
  if (this.#subscriptions[subscriptionKey.id]) {
225
228
  // Subscription already exists - ignoring
226
- this.#Log(`InstrumentationSubscriber.Subscribe(): Subscription already exists: [${subscriptionKey.id}] - ignoring.`.magenta);
229
+ this.#Log(chalk.magenta(`InstrumentationSubscriber.Subscribe(): Subscription already exists: [${subscriptionKey.id}] - ignoring.`));
227
230
  } else {
228
231
  this.#subscriptions[subscriptionKey.id] = {
229
232
  subscriptionKey,
@@ -250,7 +253,7 @@ export class InstrumentationSubscriber extends STSOptionsBase {
250
253
 
251
254
  UnSubscribe(subscriptionKey: ISubscriptionKey) {
252
255
  if (!this.#subscriptions[subscriptionKey.id]) {
253
- this.#Log(`UnSubscribe(): Warning, subscriptionKey.id: [${subscriptionKey.id}] does not exist within subscription records`.magenta);
256
+ this.#Log(chalk.magenta(`UnSubscribe(): Warning, subscriptionKey.id: [${subscriptionKey.id}] does not exist within subscription records`));
254
257
  } else {
255
258
  if (subscriptionKey.topic.localeCompare(SubscriptionTopic.LogProcessing) === 0) {
256
259
  this.#UnSubscribeKafka(this.#subscriptions[subscriptionKey.id]);
@@ -9,6 +9,8 @@ import { KafkaProducer } from './kafkaproducer'
9
9
  import { JSONObject } from '@nsshunt/stsutils'
10
10
  import { v4 as uuidv4 } from 'uuid';
11
11
 
12
+ import chalk from 'chalk';
13
+
12
14
  import { $Options } from '@nsshunt/stsconfig'
13
15
  const goptions = $Options()
14
16
 
@@ -69,7 +71,7 @@ export class IMKafkaManager {
69
71
  }
70
72
  }
71
73
  } catch (error) {
72
- console.error(`${_logPrefix}#Terminate: Error: [${error}]`.red);
74
+ console.error(chalk.red(`${_logPrefix}#Terminate: Error: [${error}]`));
73
75
  }
74
76
  }
75
77
 
@@ -145,7 +147,7 @@ export class IMKafkaManager {
145
147
  }
146
148
  return true;
147
149
  } catch (error: any) {
148
- console.error(`${_logPrefix}OutputLogs: Could not output log data to kafka: [${error}]`.red);
150
+ console.error(chalk.red(`${_logPrefix}OutputLogs: Could not output log data to kafka: [${error}]`));
149
151
  return false;
150
152
  }
151
153
  }
@@ -56,6 +56,8 @@ import { KafkaManager } from './../kafka/kafkamanager'
56
56
 
57
57
  import 'colors'
58
58
 
59
+ import chalk from 'chalk';
60
+
59
61
  async function Sleep(milliseconds = 1000) {
60
62
  return new Promise(resolve => setTimeout(resolve, milliseconds))
61
63
  }
@@ -92,7 +94,7 @@ const runme = async () => {
92
94
  for (let i=0; i < count; i++) {
93
95
  if (i % 100 === 0) console.log(i);
94
96
  const retVal = await producer.SendMessages(TOPIC, [
95
- { key: 'key1', value: `hello world - ${i}`.green },
97
+ { key: 'key1', value: chalk.green(`hello world - ${i}`) },
96
98
  { key: 'key2', value: 'hey hey! -2' },
97
99
  { key: 'key3', value: 'hey hey! -3' },
98
100
  { key: 'key4', value: 'hey hey! -4' },
@@ -7,9 +7,7 @@ import axios from 'axios';
7
7
 
8
8
  import cluster, { Worker } from 'node:cluster'
9
9
 
10
- import os from 'os';
11
-
12
- import colors from 'colors'
10
+ import chalk from 'chalk';
13
11
 
14
12
  import express from 'express'
15
13
 
@@ -24,7 +22,6 @@ const goptions = $Options()
24
22
  import debugModule from 'debug'
25
23
 
26
24
  import { Gauge, GaugeTypes, InstrumentGaugeTelemetry, InstrumentGaugeOptions, InstrumentHistogramTelemetry } from '@nsshunt/stsinstrumentation'
27
- import { GetFirstNetworkInterface } from './network'
28
25
 
29
26
  import { ProcessOptions, STSServerType } from './processoptions'
30
27
  import { ProcessBase } from './processbase';
@@ -32,7 +29,6 @@ import { IMasterProcessBase } from './commonTypes';
32
29
 
33
30
  import { InstrumentDefinitions } from '@nsshunt/stspublisherserver'
34
31
  import { IPCMessagePayload, IPCMessageCommand } from './commonTypes'
35
- import { REQUEST_HEADER_FIELDS_TOO_LARGE } from "http-status-codes";
36
32
 
37
33
 
38
34
  export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
@@ -190,15 +186,15 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
190
186
  ,httpsAgent: this.#httpsAgent
191
187
  });
192
188
  if (retVal.status !== 200) {
193
- this.#debug(`Error (MasterProcessBase:#GetLatency): Invalid response from server: [${retVal.status}]`.magenta);
189
+ this.#debug(chalk.magenta(`Error (MasterProcessBase:#GetLatency): Invalid response from server: [${retVal.status}]`));
194
190
  return null;
195
191
  }
196
192
  return retVal.data.detail;
197
193
  } catch (error: any) {
198
- this.#debug(`Error (MasterProcessBase:#GetLatency:catch): [${error}]`.red);
199
- this.#debug(` url: [${url}]`.red);
194
+ this.#debug(chalk.red(`Error (MasterProcessBase:#GetLatency:catch): [${error}]`));
195
+ this.#debug(chalk.red(` url: [${url}]`));
200
196
  if (error.response && error.response.data) {
201
- this.#debug(` Details: [${JSON.stringify(error.response.data)}]`.red);
197
+ this.#debug(chalk.red(` Details: [${JSON.stringify(error.response.data)}]`));
202
198
  }
203
199
  }
204
200
  }
@@ -236,11 +232,11 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
236
232
  worker.process.send( { command } );
237
233
  return true;
238
234
  } else {
239
- this.LogEx(`Could not kill worker with id: [${id}]. The process does not exists`.red);
235
+ this.LogEx(chalk.red(`Could not kill worker with id: [${id}]. The process does not exists`));
240
236
  return false;
241
237
  }
242
238
  } else {
243
- this.LogEx(`Could not kill worker with id: [${id}]. Worker does not exist within workers collection`.red);
239
+ this.LogEx(chalk.red(`Could not kill worker with id: [${id}]. Worker does not exist within workers collection`));
244
240
  return false;
245
241
  }
246
242
  }
@@ -342,7 +338,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
342
338
  }
343
339
  default : {
344
340
  const errorMessage = `Could not process command: [${iPCMessagePayload.command}].`;
345
- this.#debug(` ${errorMessage}`.red);
341
+ this.#debug(chalk.red(` ${errorMessage}`));
346
342
  throw new Error(errorMessage);
347
343
  }
348
344
  }
@@ -381,9 +377,9 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
381
377
  // Only handle request/response message types here ...
382
378
  if (payload.requestResponse) {
383
379
  const iPCMessagePayload: IPCMessagePayload = payload as IPCMessagePayload;
384
- this.#debug(`Received message with id: [${iPCMessagePayload.id}] from worker: [${worker.process.pid}]. Details: [${JSON.stringify(iPCMessagePayload)}]`.yellow);
380
+ this.#debug(chalk.yellow(`Received message with id: [${iPCMessagePayload.id}] from worker: [${worker.process.pid}]. Details: [${JSON.stringify(iPCMessagePayload)}]`));
385
381
  const response: IPCMessagePayload = await this.#processIPCCommand(iPCMessagePayload);
386
- this.#debug(`Sending response message with id: [${iPCMessagePayload.id}] to worker: [${worker.process.pid}]. Details: [${JSON.stringify(response)}]`.green);
382
+ this.#debug(chalk.green(`Sending response message with id: [${iPCMessagePayload.id}] to worker: [${worker.process.pid}]. Details: [${JSON.stringify(response)}]`));
387
383
  worker.send(response);
388
384
  } else {
389
385
  this.#WorkerMessageEvent(payload);
@@ -447,25 +443,21 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
447
443
  LogEx(`Worker process ${worker.process.pid} is online`);
448
444
  });
449
445
 
450
- cluster.on('exit', (worker, code, signal) =>
451
- {
452
- if ((code !== null && code === 0) || (signal === 'SIGINT'))
453
- {
454
- LogEx(`Process ${worker.process.pid} terminated gracefully with code: ${code}, signal: ${signal}`.green);
446
+ cluster.on('exit', (worker, code, signal) => {
447
+ if ((code !== null && code === 0) || (signal === 'SIGINT')) {
448
+ LogEx(chalk.green(`Process ${worker.process.pid} terminated gracefully with code: ${code}, signal: ${signal}`));
455
449
  this.DecWorkers();
456
- } else if ((code !== null && code === 15) || (signal === 'SIGTERM'))
457
- {
450
+ } else if ((code !== null && code === 15) || (signal === 'SIGTERM')) {
458
451
  this.DecWorkers();
459
- LogEx(`Process ${worker.process.pid} terminated with code: ${code}, signal: ${signal}`.red);
452
+ LogEx(chalk.red(`Process ${worker.process.pid} terminated with code: ${code}, signal: ${signal}`));
460
453
  } else {
461
454
  this.DecWorkers();
462
- LogEx(`worker ${worker.process.pid} died`.red);
463
- LogEx(`code: ${code}`.red);
464
- LogEx(`signal: ${signal}`.red);
465
- LogEx('process terminated in an error state'.red);
466
- if (goptions.respawnOnFail === true)
467
- {
468
- LogEx(`Attemping to respawn worker`);
455
+ LogEx(chalk.red(`worker ${worker.process.pid} died`));
456
+ LogEx(chalk.red(`code: ${code}`));
457
+ LogEx(chalk.red(`signal: ${signal}`));
458
+ LogEx(chalk.red('process terminated in an error state'));
459
+ if (goptions.respawnOnFail === true) {
460
+ LogEx(chalk.magenta(`Attemping to respawn worker`));
469
461
  this.#SpawnWorker();
470
462
  }
471
463
  }
@@ -564,9 +556,9 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
564
556
  {
565
557
  if (code === 0)
566
558
  {
567
- LogEx(`Main Process: ${process.pid} terminated gracefully with code: ${code}`.green);
559
+ LogEx(chalk.green(`Main Process: ${process.pid} terminated gracefully with code: ${code}`));
568
560
  } else {
569
- LogEx(`Main Process: ${process.pid} terminated with code: ${code}`.red);
561
+ LogEx(chalk.red(`Main Process: ${process.pid} terminated with code: ${code}`));
570
562
  }
571
563
  });
572
564
 
@@ -578,7 +570,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
578
570
 
579
571
  this.MasterStarted();
580
572
 
581
- LogEx(`Master process:${process.pid} started`.green);
573
+ LogEx(chalk.green(`Master process:${process.pid} started`));
582
574
  }
583
575
 
584
576
  BroadcastDataToWorkers = (command: any, data: any) => {
@@ -7,6 +7,8 @@ import colors from 'colors'
7
7
  import si from 'systeminformation' // https://systeminformation.io/
8
8
  import { GetFirstNetworkInterface } from './network'
9
9
 
10
+ import chalk from 'chalk';
11
+
10
12
  import debugModule from 'debug'
11
13
  const debug = debugModule(`proc:${process.pid}:processBase`);
12
14
 
@@ -76,10 +78,10 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
76
78
  if (cluster.isPrimary)
77
79
  {
78
80
  prefix = 'M';
79
- col = colors.bold.cyan;
81
+ col = chalk.bold.cyan;
80
82
  } else {
81
83
  prefix = 'W';
82
- col = colors.green;
84
+ col = chalk.green;
83
85
  }
84
86
  const msgEx = col(`${prefix}(${process.pid}) [${appName}]: ${msg}`);
85
87
  debug(msgEx);
@@ -334,13 +336,13 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
334
336
  try {
335
337
  const retVal = await (this.accessLayer as PGAccessLayer).getResourceCount();
336
338
  if (retVal.status !== StatusCodes.OK) {
337
- this.LogEx(`Unable to get resources from the database. Is the database running? [${JSON.stringify(retVal)}]`.red);
339
+ this.LogEx(chalk.red(`Unable to get resources from the database. Is the database running? [${JSON.stringify(retVal)}]`));
338
340
  exit(1);
339
341
  } else {
340
- this.LogEx(`Database connection successful. Resources: [${retVal.detail.count}]`.green);
342
+ this.LogEx(chalk.green(`Database connection successful. Resources: [${retVal.detail.count}]`));
341
343
  }
342
344
  } catch (error) {
343
- this.LogEx(`Unable to get resources from the database. Is the database running? Error: [${error}]`.red);
345
+ this.LogEx(chalk.red(`Unable to get resources from the database. Is the database running? Error: [${error}]`));
344
346
  exit(1);
345
347
  }
346
348
  })();
@@ -402,9 +404,9 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
402
404
  GetSignalColour = (signal: any) => {
403
405
  let msgcolor = null;
404
406
  if (signal === 'SIGINT') {
405
- msgcolor = colors.yellow;
407
+ msgcolor = chalk.yellow;
406
408
  } else {
407
- msgcolor = colors.red;
409
+ msgcolor = chalk.red;
408
410
  }
409
411
  return msgcolor;
410
412
  };
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
- //console.log(`serverNetworkMiddleware: [${JSON.stringify(data)}]`.magenta)
36
+ //console.log(chalk.magenta(`serverNetworkMiddleware: [${JSON.stringify(data)}]`));
37
37
  stsApp.UpdateInstrument(Gauge.NETWORK_RX_GAUGE, {
38
38
  Inc: data.requestBytesRead
39
39
  } as InstrumentGaugeTelemetry);
@@ -2,6 +2,8 @@
2
2
  import { $Options } from '@nsshunt/stsconfig'
3
3
  const goptions = $Options()
4
4
 
5
+ import chalk from 'chalk';
6
+
5
7
  import { Gauge, GaugeTypes, InstrumentGaugeOptions, InstrumentGaugeTelemetry } from '@nsshunt/stsinstrumentation'
6
8
 
7
9
  import { ProcessOptions } from './processoptions'
@@ -97,9 +99,9 @@ export class SingleProcessBase extends ServerProcessBase implements ISingleProce
97
99
 
98
100
  process.on('exit', (code) => {
99
101
  if (code === 0) {
100
- this.LogEx(`Main Process: ${process.pid} terminated gracefully with code: ${code}`.green);
102
+ this.LogEx(chalk.green(`Main Process: ${process.pid} terminated gracefully with code: ${code}`));
101
103
  } else {
102
- this.LogEx(`Main Process: ${process.pid} terminated with code: ${code}`.red);
104
+ this.LogEx(chalk.red(`Main Process: ${process.pid} terminated with code: ${code}`));
103
105
  }
104
106
  });
105
107
 
@@ -107,7 +109,7 @@ export class SingleProcessBase extends ServerProcessBase implements ISingleProce
107
109
 
108
110
  this.ProcessStarted();
109
111
 
110
- this.LogEx(`Main process:${process.pid} started`.green);
112
+ this.LogEx(chalk.green(`Main process:${process.pid} started`));
111
113
  }
112
114
 
113
115
  async TerminateApplication()
@@ -48,9 +48,9 @@ socket2.on('secureConnect', () => {
48
48
  dosomework(socket2);
49
49
  });
50
50
  socket2.on('close', function(data: any) {
51
- console.log(`CLOSED: ${socket2.remoteAddress} ${socket2.remotePort}`.green);
51
+ console.log(chalk.green(`CLOSED: ${socket2.remoteAddress} ${socket2.remotePort}`));
52
52
  });
53
53
  socket2.on('data', function(data: any) {
54
- console.log(`DATA ${socket2.remoteAddress} ${socket2.remotePort} ${data}`.green);
54
+ console.log(chalk.green(`DATA ${socket2.remoteAddress} ${socket2.remotePort} ${data}`));
55
55
  });
56
56
  */
@@ -9,6 +9,8 @@ import { JSONObject } from '@nsshunt/stsutils';
9
9
  import { MasterProcessBase } from './../masterprocessbase'
10
10
  import { ProcessOptions } from './../processoptions'
11
11
 
12
+ import chalk from 'chalk';
13
+
12
14
  // Colour codes
13
15
  // ---------------------------------
14
16
  // Red - Error
@@ -122,7 +124,7 @@ export class AppMaster extends MasterProcessBase
122
124
  // Update my currentTerm
123
125
  this.#currentTerm = term;
124
126
  // Return my yes vote
125
- console.log(`${message} - Vote Yes`.green)
127
+ console.log(chalk.green(`${message} - Vote Yes`));
126
128
  callback(null, true); // YES vote
127
129
  }
128
130
 
@@ -130,7 +132,7 @@ export class AppMaster extends MasterProcessBase
130
132
  // Log the fact that I have now voted for this currentTerm
131
133
  this.#votedLog[term] = true;
132
134
  // Return my yes vote
133
- console.log(`${message} - Vote No`.yellow)
135
+ console.log(chalk.yellow(`${message} - Vote No`));
134
136
  callback(null, false); // NO vote
135
137
  }
136
138
 
@@ -229,19 +231,19 @@ export class AppMaster extends MasterProcessBase
229
231
  const retVal = this.#CheckMoreRecentTerm(term, lastLogItemTerm, lastLogItemIndex);
230
232
  if (retVal.retVal === true) {
231
233
  console.log(`${retVal.msg}`);
232
- console.log(`${this.#GetLogPrefix()}: New leader detected, Host: [${host}], Port: [${port}], while in CANDIDATE mode, reverting to FOLLOWER.`.magenta);
234
+ console.log(chalk.magenta(`${this.#GetLogPrefix()}: New leader detected, Host: [${host}], Port: [${port}], while in CANDIDATE mode, reverting to FOLLOWER.`));
233
235
  // This sending node is the leader so revert to follower
234
236
  this.#currentTerm = term;
235
237
  this.#ChangeState(AppMasterRAFTState.FOLLOWER);
236
238
  } else {
237
239
  console.log(`${retVal.msg}`);
238
- console.log(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`.magenta);
240
+ console.log(chalk.magenta(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`));
239
241
  // Reject this RPC and continue in the CANDIDATE state
240
242
  callback(null, false);
241
243
  return;
242
244
  }
243
245
  } else if (this.#RAFTState.localeCompare(AppMasterRAFTState.LEADER) === 0) {
244
- console.log(`${this.#GetLogPrefix()}: appendEntry called while I am the current leader, rejecting RPC call.`.red);
246
+ console.log(chalk.red(`${this.#GetLogPrefix()}: appendEntry called while I am the current leader, rejecting RPC call.`));
245
247
  // Reject this RPC and continue in the LEADER state
246
248
  callback(null, false);
247
249
  return;
@@ -258,7 +260,7 @@ export class AppMaster extends MasterProcessBase
258
260
  }
259
261
  } else {
260
262
  console.log(`${retVal.msg}`);
261
- console.log(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`.magenta);
263
+ console.log(chalk.magenta(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`));
262
264
  // Reject this RPC and continue in the CANDIDATE state
263
265
  callback(null, false);
264
266
  return;
@@ -270,13 +272,13 @@ export class AppMaster extends MasterProcessBase
270
272
  if (sentLeaderService) {
271
273
  if (sentLeaderService.host.localeCompare(this.#leaderNode.host) !== 0 || sentLeaderService.port !== this.#leaderNode.port) {
272
274
  this.#leaderNode = sentLeaderService;
273
- console.log(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`.white);
275
+ console.log(chalk.white(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`));
274
276
  }
275
277
  }
276
278
  } else {
277
279
  this.#leaderNode = this.#FindService(host, port);
278
280
  if (this.#leaderNode) {
279
- console.log(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`.white);
281
+ console.log(chalk.white(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`));
280
282
  }
281
283
  }
282
284
 
@@ -309,18 +311,6 @@ export class AppMaster extends MasterProcessBase
309
311
  };
310
312
 
311
313
  const client = jayson.client.tls(options);
312
- /*
313
- client.on('tcp socket', (socket: tls.TLSSocket) => {
314
- socket.setTimeout(200); //@@ config
315
- socket.on('timeout', () => {
316
- console.log('socket timeout');
317
- socket.end();
318
- });
319
- });
320
- client.on('tcp error', (error: any) => {
321
- console.log(`ERROR: [${error}]`.red);
322
- });
323
- */
324
314
 
325
315
  let lastLogItem: ILogItem;
326
316
  if (this.#log.length > 0) {
@@ -335,7 +325,7 @@ export class AppMaster extends MasterProcessBase
335
325
 
336
326
  client.request('vote', [ this.#currentTerm, lastLogItem.term, lastLogItem.index ], (error: any, response: any) => {
337
327
  if (error) {
338
- //console.log(`vote attempt fail: [${JSON.stringify(options)}: ${error}]`.red);
328
+ //console.log(chalk.red(`vote attempt fail: [${JSON.stringify(options)}: ${error}]`));
339
329
  } else {
340
330
  // Log the result
341
331
  if (response.result === true) {
@@ -353,18 +343,6 @@ export class AppMaster extends MasterProcessBase
353
343
  };
354
344
 
355
345
  const client = jayson.client.tls(options);
356
- /*
357
- client.on('tcp socket', (socket: tls.TLSSocket) => {
358
- socket.setTimeout(200); //@@ config
359
- socket.on('timeout', () => {
360
- console.log('socket timeout');
361
- socket.end();
362
- });
363
- });
364
- client.on('tcp error', (error: any) => {
365
- console.log(`ERROR: [${error}]`.red);
366
- });
367
- */
368
346
 
369
347
  let lastLogItem: ILogItem;
370
348
  if (this.#log.length > 0) {
@@ -379,7 +357,7 @@ export class AppMaster extends MasterProcessBase
379
357
 
380
358
  client.request('appendEntry', [ this.#thisService.host, this.#thisService.port, this.#currentTerm, lastLogItem.term, lastLogItem.index ], (error: any, response: any) => {
381
359
  if (error) {
382
- //console.log(`appendEntry attempt fail: [${JSON.stringify(options)}: ${error}]`.red);
360
+ //console.log(chalk.red(`appendEntry attempt fail: [${JSON.stringify(options)}: ${error}]`));
383
361
  } else {
384
362
  this.#appendedEntries[this.#GetServiceKey(service)] = 1;
385
363
  // Log the result
@@ -431,14 +409,14 @@ export class AppMaster extends MasterProcessBase
431
409
  if (majority) {
432
410
  this.#StartAppendEntries();
433
411
  } else {
434
- console.log(`${this.#GetLogPrefix()}: Not enough response for valid cluster state.`.red);
412
+ console.log(chalk.red(`${this.#GetLogPrefix()}: Not enough response for valid cluster state.`));
435
413
  }
436
414
  }, this.#heartBeatTimeout);
437
415
  }
438
416
 
439
417
  #Promote = () => {
440
418
  this.#ChangeState(AppMasterRAFTState.LEADER);
441
- console.log(`${this.#GetLogPrefix()}: New LEADER is elected: [${this.#GetSelfServiceKey()}]`.green);
419
+ console.log(chalk.green(`${this.#GetLogPrefix()}: New LEADER is elected: [${this.#GetSelfServiceKey()}]`));
442
420
  // As leader, now start the regular pings
443
421
  this.#StartAppendEntries();
444
422
  }
@@ -492,7 +470,7 @@ export class AppMaster extends MasterProcessBase
492
470
  // Log the result - Vote for myself
493
471
  this.#votes[this.#GetSelfServiceKey()] = 1;
494
472
  // Return my yes vote
495
- console.log(`${this.#GetLogPrefix()}: SELF VOTE: canidate currentTerm: [${this.#currentTerm}], vote YES`.green)
473
+ console.log(chalk.green(`${this.#GetLogPrefix()}: SELF VOTE: canidate currentTerm: [${this.#currentTerm}], vote YES`));
496
474
  this.#CheckMajority();
497
475
  } else {
498
476
  // Send vote request
@@ -526,13 +504,13 @@ export class AppMaster extends MasterProcessBase
526
504
  }
527
505
 
528
506
  #StartRAFTService = async () => {
529
- this.LogEx(`---[ RAFT Protocol Starting ]---`.green);
507
+ this.LogEx(chalk.green(`---[ RAFT Protocol Starting ]---`));
530
508
  this.#server = await this.#SetupJSONRPCServer();
531
509
  this.#StartElectionTimeout();
532
510
  }
533
511
 
534
512
  #ChangeState(newState: AppMasterRAFTState) {
535
- this.LogEx(`${this.#GetLogPrefix()}: State Change, From: [${this.#RAFTState.toString()}] --> To: [${newState.toString()}]`.magenta);
513
+ this.LogEx(chalk.magenta(`${this.#GetLogPrefix()}: State Change, From: [${this.#RAFTState.toString()}] --> To: [${newState.toString()}]`));
536
514
  this.#RAFTState = newState;
537
515
  }
538
516