@nsshunt/stsappframework 3.0.91 → 3.0.93

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 (65) hide show
  1. package/dist/authutilsnode.js +7 -6
  2. package/dist/authutilsnode.js.map +1 -1
  3. package/dist/influxdb/influxDBManager.js +17 -16
  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 +15 -11
  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/kafkatesting/produce.js +5 -1
  16. package/dist/kafkatesting/produce.js.map +1 -1
  17. package/dist/masterprocessbase.js +20 -19
  18. package/dist/masterprocessbase.js.map +1 -1
  19. package/dist/processbase.js +8 -7
  20. package/dist/processbase.js.map +1 -1
  21. package/dist/server.js +1 -1
  22. package/dist/server.js.map +1 -1
  23. package/dist/singleprocessbase.js +4 -3
  24. package/dist/singleprocessbase.js.map +1 -1
  25. package/dist/tcpclient/app2.js +2 -2
  26. package/dist/tcpserver/appmaster.js +16 -39
  27. package/dist/tcpserver/appmaster.js.map +1 -1
  28. package/dist/testing/appWorkerWSS.js +7 -6
  29. package/dist/testing/appWorkerWSS.js.map +1 -1
  30. package/dist/testing/singleservertest.test.js +9 -8
  31. package/dist/testing/singleservertest.test.js.map +1 -1
  32. package/dist/workerprocessbase.js +4 -3
  33. package/dist/workerprocessbase.js.map +1 -1
  34. package/package.json +7 -7
  35. package/src/authutilsnode.ts +10 -8
  36. package/src/influxdb/influxDBManager.ts +18 -16
  37. package/src/influxdb/influxDBManagerAgent.ts +11 -9
  38. package/src/influxdb/influxDBManagerBase.ts +4 -2
  39. package/src/influxdb/influxDBManagerService.ts +12 -10
  40. package/src/instrumentationsubscriber.ts +14 -11
  41. package/src/kafka/IMKafkaManager.ts +4 -2
  42. package/src/kafkatesting/produce.ts +3 -1
  43. package/src/masterprocessbase.ts +24 -32
  44. package/src/processbase.ts +9 -7
  45. package/src/server.ts +1 -1
  46. package/src/singleprocessbase.ts +5 -3
  47. package/src/tcpclient/app2.ts +2 -2
  48. package/src/tcpserver/appmaster.ts +17 -39
  49. package/src/testing/appWorkerWSS.ts +8 -6
  50. package/src/testing/singleservertest.test.ts +10 -8
  51. package/src/workerprocessbase.ts +5 -3
  52. package/types/authutilsnode.d.ts.map +1 -1
  53. package/types/influxdb/influxDBManager.d.ts.map +1 -1
  54. package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
  55. package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
  56. package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
  57. package/types/instrumentationsubscriber.d.ts.map +1 -1
  58. package/types/kafka/IMKafkaManager.d.ts.map +1 -1
  59. package/types/masterprocessbase.d.ts.map +1 -1
  60. package/types/processbase.d.ts +2 -2
  61. package/types/processbase.d.ts.map +1 -1
  62. package/types/singleprocessbase.d.ts.map +1 -1
  63. package/types/tcpserver/appmaster.d.ts.map +1 -1
  64. package/types/testing/appWorkerWSS.d.ts.map +1 -1
  65. package/types/workerprocessbase.d.ts.map +1 -1
@@ -4,6 +4,8 @@ import { InfluxDB, WriteApi, QueryApi, DEFAULT_WriteOptions, WriteOptions } from
4
4
  //import { Agent } from 'https'
5
5
  import { Agent } from 'http'
6
6
 
7
+ import chalk from 'chalk';
8
+
7
9
  import { $Options } from '@nsshunt/stsconfig'
8
10
  import { JSONObject } from '@nsshunt/stsutils'
9
11
  const goptions = $Options()
@@ -274,15 +276,15 @@ export class InfluxDBManager
274
276
  org: 'my-org'
275
277
  });
276
278
  if (tasks.tasks) {
277
- console.log(`[InfluxDB Tasks] - Count: [${tasks.tasks.length}]`.cyan);
279
+ console.log(chalk.cyan(`[InfluxDB Tasks] - Count: [${tasks.tasks.length}]`));
278
280
  tasks.tasks.forEach((task: Task) => {
279
- console.log(`-- [ Start Task Definition ]--`.cyan);
280
- console.log(`${JSON.stringify(task)}`.green);
281
- console.log(`authorizationID: [${task.authorizationID}]`.yellow);
282
- console.log(`-- [ End Task Definition ]--`.cyan);
281
+ console.log(chalk.cyan(`-- [ Start Task Definition ]--`));
282
+ console.log(chalk.green(`${JSON.stringify(task)}`));
283
+ console.log(chalk.yellow(`authorizationID: [${task.authorizationID}]`));
284
+ console.log(chalk.cyan(`-- [ End Task Definition ]--`));
283
285
  });
284
286
  } else {
285
- console.log(`[InfluxDB Tasks] - Could not get tasks from the InfluxDB API`.magenta);
287
+ console.log(chalk.magenta(`[InfluxDB Tasks] - Could not get tasks from the InfluxDB API`));
286
288
  }
287
289
  }
288
290
 
@@ -332,9 +334,9 @@ export class InfluxDBManager
332
334
 
333
335
  this.#writeClient = null;
334
336
 
335
- console.log(`ProducerDisconnect`.yellow);
337
+ console.log(chalk.yellow(`ProducerDisconnect`));
336
338
  } catch (error) {
337
- console.error(`${_logPrefix}#Terminate: Error: [${error}]`.red);
339
+ console.error(chalk.red(`${_logPrefix}#Terminate: Error: [${error}]`));
338
340
  }
339
341
  }
340
342
  }
@@ -354,7 +356,7 @@ export class InfluxDBManager
354
356
  });
355
357
  return results;
356
358
  } catch (error) {
357
- console.error(`${_logPrefix}#CreateGlobalCountModel: Error: [${error}]`.red);
359
+ console.error(chalk.red(`${_logPrefix}#CreateGlobalCountModel: Error: [${error}]`));
358
360
  }
359
361
  }
360
362
 
@@ -428,13 +430,13 @@ export class InfluxDBManager
428
430
  // https://influxdata.github.io/influxdb-client-js/influxdb-client.writeoptions.html and
429
431
  // https://influxdata.github.io/influxdb-client-js/influxdb-client.writeretryoptions.html
430
432
  writeFailed(error, lines, attempt, expires) {
431
- debug(`writeOptions:writeSuccess(): Error: [${error}], Attempt: [${attempt}], Expires: [${expires}], Lines: [${lines}]`.red);
433
+ debug(chalk.red(`writeOptions:writeSuccess(): Error: [${error}], Attempt: [${attempt}], Expires: [${expires}], Lines: [${lines}]`));
432
434
  },
433
435
  writeSuccess(lines) {
434
- debug(`writeOptions:writeSuccess(): Lines: [${lines}]`.green);
436
+ debug(chalk.green(`writeOptions:writeSuccess(): Lines: [${lines}]`));
435
437
  },
436
438
  writeRetrySkipped(entry) {
437
- debug(`writeOptions:writeSuccess(): Expires: [${entry.expires}], Lines: [${entry.lines}]`.magenta);
439
+ debug(chalk.magenta(`writeOptions:writeSuccess(): Expires: [${entry.expires}], Lines: [${entry.lines}]`));
438
440
  }
439
441
  }
440
442
 
@@ -457,10 +459,10 @@ export class InfluxDBManager
457
459
  attemptCount = 0;
458
460
  StartWriteClient(normalFlushDelay);
459
461
  } catch (error) {
460
- console.error(`InfluxDBManager:StartWriteClient(): Attempt: [${attemptCount}], Error: [${error}]`.red)
462
+ console.error(chalk.red(`InfluxDBManager:StartWriteClient(): Attempt: [${attemptCount}], Error: [${error}]`));
461
463
  if (attemptCount === maxAttemptCount) {
462
- console.error(`InfluxDBManager:StartWriteClient(): Max Attempts reached. Will no longer retry.`.red);
463
- console.error(`InfluxDBManager:StartWriteClient(): InfluxDB data capture ended in permanent faiilure.`.red);
464
+ console.error(chalk.red(`InfluxDBManager:StartWriteClient(): Max Attempts reached. Will no longer retry.`));
465
+ console.error(chalk.red(`InfluxDBManager:StartWriteClient(): InfluxDB data capture ended in permanent faiilure.`));
464
466
  } else {
465
467
  StartWriteClient(retryFlushDelay);
466
468
  }
@@ -487,7 +489,7 @@ export class InfluxDBManager
487
489
  return this.#influxDBManagerClients['service'].OutputInfluxDB(this.writeClient, instrumentPayload);
488
490
  }
489
491
  } catch (error) {
490
- console.error(`${_logPrefix}OutputInfluxDB: Could not write data point: [${error}]`.red);
492
+ console.error(chalk.red(`${_logPrefix}OutputInfluxDB: Could not write data point: [${error}]`));
491
493
  return false;
492
494
  }
493
495
  }
@@ -105,6 +105,8 @@ import { InfluxDBManagerBase } from './influxDBManagerBase'
105
105
  import { IInfluxDBManagerOptions, InstrumentPayload } from './../commonTypes'
106
106
  import { ISubscriptionPayload, ISubscriptionKey } from '@nsshunt/stssocketio-client'
107
107
 
108
+ import chalk from 'chalk';
109
+
108
110
  const AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER = "sts-stats-by-agentthreadasyncunner";
109
111
  const AGENT_STATS_BY_AGENT_THREAD = "sts-stats-by-agentthread";
110
112
  const AGENT_STATS_BY_AGENT = "sts-stats-by-agent";
@@ -138,7 +140,7 @@ export class InfluxDBManagerAgent extends InfluxDBManagerBase
138
140
 
139
141
  return this.queryApi.collectRows(query)
140
142
  } catch (error) {
141
- console.error(`${_logPrefix}#GetSTSCountGeneric: Error: [${error}]`.red);
143
+ console.error(chalk.red(`${_logPrefix}#GetSTSCountGeneric: Error: [${error}]`));
142
144
  }
143
145
  }
144
146
 
@@ -154,7 +156,7 @@ export class InfluxDBManagerAgent extends InfluxDBManagerBase
154
156
  |> difference()`;
155
157
  return this.queryApi.collectRows(query)
156
158
  } catch (error) {
157
- console.error(`${_logPrefix}#GetSTSHistoGeneric: Error: [${error}]`.red);
159
+ console.error(chalk.red(`${_logPrefix}#GetSTSHistoGeneric: Error: [${error}]`));
158
160
  }
159
161
  }
160
162
 
@@ -183,7 +185,7 @@ export class InfluxDBManagerAgent extends InfluxDBManagerBase
183
185
 
184
186
  return this.queryApi.collectRows(query)
185
187
  } catch (error) {
186
- console.error(`${_logPrefix}#GetSTSQuantileGeneric: Error: [${error}]`.red);
188
+ console.error(chalk.red(`${_logPrefix}#GetSTSQuantileGeneric: Error: [${error}]`));
187
189
  }
188
190
  }
189
191
 
@@ -198,7 +200,7 @@ export class InfluxDBManagerAgent extends InfluxDBManagerBase
198
200
  this.#GetSTSHistoGenericService(AGENT_STATS_GLOBALAGENT, '')],
199
201
  [ ])
200
202
  } catch (error) {
201
- console.error(`${_logPrefix}GetInfluxDBResultsRootAgent: Error: [${error}]`.red);
203
+ console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsRootAgent: Error: [${error}]`));
202
204
  }
203
205
  return {
204
206
  subscriptionKey,
@@ -216,7 +218,7 @@ export class InfluxDBManagerAgent extends InfluxDBManagerBase
216
218
  this.#GetSTSHistoGenericService(AGENT_STATS_BY_AGENT, '')],
217
219
  ['agentName'])
218
220
  } catch (error) {
219
- console.error(`${_logPrefix}GetInfluxDBResultsAgent: Error: [${error}]`.red);
221
+ console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsAgent: Error: [${error}]`));
220
222
  }
221
223
  return {
222
224
  subscriptionKey,
@@ -235,7 +237,7 @@ export class InfluxDBManagerAgent extends InfluxDBManagerBase
235
237
  this.#GetSTSHistoGenericService(AGENT_STATS_BY_AGENT_THREAD, `and r["agentName"] == "${agentName}"`)],
236
238
  ['agentName', 'threadId'])
237
239
  } catch (error) {
238
- console.error(`${_logPrefix}GetInfluxDBResultsAgentThreads: Error: [${error}]`.red);
240
+ console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsAgentThreads: Error: [${error}]`));
239
241
  }
240
242
  return {
241
243
  subscriptionKey,
@@ -255,7 +257,7 @@ export class InfluxDBManagerAgent extends InfluxDBManagerBase
255
257
  this.#GetSTSHistoGenericService(AGENT_STATS_BY_AGENT_THREAD_ASYNCRUNNER, `and r["agentName"] == "${agentName}" and r["threadId"] == "${threadId}"`)],
256
258
  ['agentName', 'threadId', 'asyncRunnerId'])
257
259
  } catch (error) {
258
- console.error(`${_logPrefix}GetInfluxDBResultsAgentThread: Error: [${error}]`.red);
260
+ console.error(chalk.red(`${_logPrefix}GetInfluxDBResultsAgentThread: Error: [${error}]`));
259
261
  }
260
262
  return {
261
263
  subscriptionKey,
@@ -303,11 +305,11 @@ export class InfluxDBManagerAgent extends InfluxDBManagerBase
303
305
  writeApi.writePoint(point);
304
306
  return true;
305
307
  } catch (error: any) {
306
- console.error(`${_logPrefix}OutputInfluxDBAgent: Could not write data point: [${error}]`.red);
308
+ console.error(chalk.red(`${_logPrefix}OutputInfluxDBAgent: Could not write data point: [${error}]`));
307
309
  return false;
308
310
  }
309
311
  } else {
310
- console.error(`${_logPrefix}OutputInfluxDBAgent: Could not write data point as writeClient is null`.red);
312
+ console.error(chalk.red(`${_logPrefix}OutputInfluxDBAgent: Could not write data point as writeClient is null`));
311
313
  return false;
312
314
  }
313
315
  }
@@ -7,6 +7,8 @@ import { IInfluxDBManagerOptions, InstrumentPayload } from './../commonTypes'
7
7
 
8
8
  import { JSONObject } from '@nsshunt/stsutils'
9
9
 
10
+ import chalk from 'chalk';
11
+
10
12
  const _logPrefix = 'InfluxDBManager:'
11
13
 
12
14
  export class InfluxDBManagerBase
@@ -74,7 +76,7 @@ export class InfluxDBManagerBase
74
76
  }
75
77
  return combinedResults;
76
78
  } catch (error) {
77
- console.error(`${_logPrefix}ProcessInfluxDBResults: Error: [${error}]`.red);
79
+ console.error(chalk.red(`${_logPrefix}ProcessInfluxDBResults: Error: [${error}]`));
78
80
  }
79
81
  }
80
82
 
@@ -86,7 +88,7 @@ export class InfluxDBManagerBase
86
88
  });
87
89
  return results;
88
90
  } catch (error) {
89
- console.error(`${_logPrefix}#CreateGlobalCountModel: Error: [${error}]`.red);
91
+ console.error(chalk.red(`${_logPrefix}#CreateGlobalCountModel: Error: [${error}]`));
90
92
  }
91
93
  }
92
94
 
@@ -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 = colors.bold.cyan; // chalk.bold.cyan;
80
82
  } else {
81
83
  prefix = 'W';
82
- col = colors.green;
84
+ col = colors.green; // 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()