@nsshunt/stsappframework 3.1.160 → 3.1.162

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 (41) hide show
  1. package/dist/testertesting/app.js +198 -0
  2. package/dist/testertesting/app.js.map +1 -0
  3. package/dist/testertesting/commonTypes.js +39 -0
  4. package/dist/testertesting/commonTypes.js.map +1 -0
  5. package/dist/testertesting/requestResponseHelper.js +83 -0
  6. package/dist/testertesting/requestResponseHelper.js.map +1 -0
  7. package/dist/testertesting/telemetryProcessor.js +114 -0
  8. package/dist/testertesting/telemetryProcessor.js.map +1 -0
  9. package/dist/testertesting/workerInstance.js +141 -0
  10. package/dist/testertesting/workerInstance.js.map +1 -0
  11. package/dist/testertesting/workerManager.js +339 -0
  12. package/dist/testertesting/workerManager.js.map +1 -0
  13. package/dist/testertesting/workerPrimaryTestRunner01.js +62 -0
  14. package/dist/testertesting/workerPrimaryTestRunner01.js.map +1 -0
  15. package/dist/testertesting/workerWorkerTestRunner01.js +146 -0
  16. package/dist/testertesting/workerWorkerTestRunner01.js.map +1 -0
  17. package/package.json +1 -1
  18. package/src/testertesting/app.ts +243 -0
  19. package/src/testertesting/commonTypes.ts +197 -0
  20. package/src/testertesting/requestResponseHelper.ts +95 -0
  21. package/src/testertesting/telemetryProcessor.ts +128 -0
  22. package/src/testertesting/workerInstance.ts +165 -0
  23. package/src/testertesting/workerManager.ts +386 -0
  24. package/src/testertesting/workerPrimaryTestRunner01.ts +81 -0
  25. package/src/testertesting/workerWorkerTestRunner01.ts +184 -0
  26. package/types/testertesting/app.d.ts +2 -0
  27. package/types/testertesting/app.d.ts.map +1 -0
  28. package/types/testertesting/commonTypes.d.ts +167 -0
  29. package/types/testertesting/commonTypes.d.ts.map +1 -0
  30. package/types/testertesting/requestResponseHelper.d.ts +8 -0
  31. package/types/testertesting/requestResponseHelper.d.ts.map +1 -0
  32. package/types/testertesting/telemetryProcessor.d.ts +6 -0
  33. package/types/testertesting/telemetryProcessor.d.ts.map +1 -0
  34. package/types/testertesting/workerInstance.d.ts +18 -0
  35. package/types/testertesting/workerInstance.d.ts.map +1 -0
  36. package/types/testertesting/workerManager.d.ts +14 -0
  37. package/types/testertesting/workerManager.d.ts.map +1 -0
  38. package/types/testertesting/workerPrimaryTestRunner01.d.ts +8 -0
  39. package/types/testertesting/workerPrimaryTestRunner01.d.ts.map +1 -0
  40. package/types/testertesting/workerWorkerTestRunner01.d.ts +16 -0
  41. package/types/testertesting/workerWorkerTestRunner01.d.ts.map +1 -0
@@ -0,0 +1,243 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
2
+ import cluster from 'cluster';
3
+ import { Worker } from 'worker_threads';
4
+
5
+ import { IWorkerFactory, IWorkerOptions, IPrimaryWorker, IRunnerOptions } from './commonTypes'
6
+
7
+ import { WorkerPrimaryTestRunner01 } from './workerPrimaryTestRunner01'
8
+ import { STSWorkerManager } from './workerManager';
9
+
10
+ import chalk from 'chalk';
11
+ // Force chalk level
12
+ chalk.level = 3;
13
+
14
+ import { IContextBase, AgentInstrumentController, IPublishInstrumentControllerOptions, Gauge, GaugeTypes,
15
+ InstrumentDefinitions, InstrumentLogOptions, InstrumentGaugeOptions, PublishTransportRESTServer,
16
+ TransportType, IPublishTransportRESTServerOptions } from '@nsshunt/stsobservability'
17
+
18
+ import { ModelDelimeter, type ISTSLogger, defaultLogger } from '@nsshunt/stsutils'
19
+
20
+ import { v4 as uuidv4 } from 'uuid';
21
+
22
+ import { goptions } from '@nsshunt/stsconfig'
23
+
24
+ declare interface IAsyncRunnerContext extends IContextBase {
25
+ id: string;
26
+ hostName: string;
27
+ agentName: string;
28
+ threadId: string;
29
+ asyncRunnerId: number;
30
+ }
31
+
32
+ const LogInfoMessage = (message: any) => console.log(chalk.grey(message))
33
+ const LogErrorMessage = (message: any) => console.error(chalk.red(message))
34
+
35
+ if (cluster.isPrimary) {
36
+
37
+ //new MasterProcessBase(ServiceConfigOptions(true, cluster.isPrimary)).SetupServer();
38
+
39
+ LogInfoMessage(`Primary ${process.pid} is running`);
40
+
41
+ // Fork workers.
42
+ cluster.fork();
43
+
44
+ cluster.on('exit', (worker, code, signal) => {
45
+ LogInfoMessage(`worker ${worker.process.pid} died`);
46
+ });
47
+
48
+
49
+ /*
50
+ const fileName ='./dist/webworkertesting/worker.js';
51
+
52
+ const publishCollectorWebWorker = new Worker(fileName);
53
+ publishCollectorWebWorker.unref();
54
+
55
+ publishCollectorWebWorker.postMessage({cmd: 'text', message: 'Hello World'});
56
+
57
+ publishCollectorWebWorker.on('message', (data) => {
58
+ LogInfoMessage(`cluster.primary (${process.pid}): message from worker = [${JSON.stringify(data)}]`);
59
+ });
60
+
61
+ const { port1, port2 } = new MessageChannel();
62
+
63
+ publishCollectorWebWorker.postMessage({cmd: 'portmessage', port: port2}, [ port2 ]);
64
+ port1.postMessage('sending to port1');
65
+ port1.on('message', (data) => {
66
+ LogInfoMessage(`cluster.primary (${process.pid}): message from message port = [${data}]`);
67
+ });
68
+ */
69
+
70
+ LogInfoMessage(`cluster primary completed ...`);
71
+
72
+
73
+ } else {
74
+
75
+
76
+ LogInfoMessage(`Worker ${process.pid} started`);
77
+
78
+ //const worker = new WorkerProcessBase(ServiceConfigOptions(true, cluster.isPrimary));
79
+ //worker.SetupServer();
80
+
81
+ const hostName = 'host01';
82
+ const agentId = 'agent01';
83
+ const userAgent = 'userAgent01'
84
+
85
+ const asyncRunnerContext: IAsyncRunnerContext = {
86
+ nid: `\
87
+ ${hostName}${ModelDelimeter.COMPONENT_SEPERATOR}${agentId}-${userAgent}\
88
+ ${ModelDelimeter.NID_SEPERATOR}\
89
+ MainProcess\
90
+ ${ModelDelimeter.SEPERATOR}\
91
+ 0`,
92
+ id: uuidv4(),
93
+ // id: `${applicationStore.applicationConfig.HOST}${ModelDelimeter.COMPONENT_SEPERATOR}${applicationStore.applicationConfig.AGENT_ID}-${applicationStore.applicationConfig.USER_AGENT}`,
94
+ hostName: (hostName ? hostName : 'host01'),
95
+ agentName: `${agentId}-${userAgent}`,
96
+ threadId: 'MainProcess',
97
+ asyncRunnerId: 0
98
+ }
99
+
100
+ const url = `https://stscore.stsmda.org:3001/stsinstrumentmanager/v1/publishmessage`;
101
+
102
+ const publishTransportOptions: IPublishTransportRESTServerOptions = {
103
+ transportType: TransportType.RESTAPI,
104
+ //url: `${goptions.imendpoint}:${goptions.import}${goptions.imapiroot}/publishmessage`,
105
+ url,
106
+ logger: defaultLogger,
107
+ agentOptions: {
108
+ keepAlive: goptions.keepAlive,
109
+ maxSockets: goptions.maxSockets,
110
+ maxTotalSockets: goptions.maxTotalSockets,
111
+ maxFreeSockets: goptions.maxFreeSockets,
112
+ timeout: 30000, //@@ config
113
+ rejectUnauthorized: goptions.isProduction // Allows self signed certs in non production mode(s)
114
+ },
115
+ showPublishPayload: false
116
+ };
117
+
118
+ LogInfoMessage(`publishTransportOptions: [${publishTransportOptions.url}]`);
119
+
120
+ const standardInstruments: InstrumentDefinitions = [
121
+ [ Gauge.TIMER_GAUGE, GaugeTypes.INSTRUMENT_TIMER ],
122
+ [ Gauge.LOGGER, GaugeTypes.INSTRUMENT_LOG, {
123
+ consoleLogging: process.env.consoleLogging,
124
+ instrumentLogging: process.env.instrumentLogging } as InstrumentLogOptions],
125
+ [ Gauge.NETWORK_RX_GAUGE , GaugeTypes.INSTRUMENT_VELOCITY ],
126
+ [ Gauge.NETWORK_TX_GAUGE, GaugeTypes.INSTRUMENT_VELOCITY ]
127
+ ];
128
+
129
+ const agentInstruments: InstrumentDefinitions = [
130
+ [ Gauge.REQUEST_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of requests serviced
131
+ [ Gauge.ERROR_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
132
+ [ Gauge.RETRY_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ],
133
+ [ Gauge.AUTHENTICATION_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests
134
+ [ Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests errors
135
+ [ Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Total number of new token requests retries
136
+ [ Gauge.ACTIVE_REQUEST_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, { // Total number of runners (in-flight) requests
137
+ interval: process.env.instrumentationObservationInterval,
138
+ sampleSize: process.env.instrumentationTimeWindow } as InstrumentGaugeOptions],
139
+ [ Gauge.DURATION_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, { // Duration of latest http(s) request.
140
+ interval: process.env.instrumentationObservationInterval,
141
+ sampleSize: process.env.instrumentationTimeWindow } as InstrumentGaugeOptions],
142
+ [ Gauge.DURATION_HISTOGRAM_GAUGE, GaugeTypes.INSTRUMENT_HISTOGRAM ],
143
+ [ Gauge.VELOCITY_GAUGE, GaugeTypes.INSTRUMENT_VELOCITY ], // Requests per second
144
+ [ Gauge.CORE_COUNT_GAUGE, GaugeTypes.INSTRUMENT_GAUGE ], // Thread count (for http agents)
145
+ [ Gauge.LATENCY_GAUGE, GaugeTypes.INSTRUMENT_GAUGE, {
146
+ interval: process.env.instrumentationObservationInterval,
147
+ sampleSize: process.env.instrumentationTimeWindow } as InstrumentGaugeOptions],
148
+ [ Gauge.LATENCY_HISTOGRAM_GAUGE, GaugeTypes.INSTRUMENT_HISTOGRAM ],
149
+ [ Gauge.CHILD_COUNT, GaugeTypes.INSTRUMENT_GAUGE ] // Number of async runners idle or running
150
+ ]
151
+
152
+ const instrumentControllerOptions: IPublishInstrumentControllerOptions = {
153
+ processContext: asyncRunnerContext,
154
+ instrumentationObservationInterval: 1000, //@@
155
+ instrumentationTimeWindow: 600, //@@
156
+ publisherTransport: new PublishTransportRESTServer(publishTransportOptions),
157
+ logger: defaultLogger,
158
+ publishInterval: 1000, //@@
159
+ //instrumentDefinitions: GetInstruments('agent')
160
+ instrumentDefinitions: [
161
+ ...standardInstruments,
162
+ ...agentInstruments
163
+ ]
164
+ }
165
+
166
+ const agentInstrumentController = new AgentInstrumentController(instrumentControllerOptions);
167
+ agentInstrumentController.StartPublish();
168
+
169
+ const workerFactory: IWorkerFactory = {
170
+
171
+ createPrimaryThreadWorker: (app: any, options: IWorkerOptions): IPrimaryWorker => {
172
+ return new WorkerPrimaryTestRunner01(app, options);
173
+ },
174
+ createWorkerThreadWorker: (): Worker => {
175
+
176
+ LogInfoMessage(`createWorkerThreadWorker`);
177
+
178
+ const fileName ='./dist/testertesting/workerWorkerTestRunner01.js';
179
+
180
+ const publishCollectorWebWorker = new Worker(fileName);
181
+ publishCollectorWebWorker.unref();
182
+
183
+ return publishCollectorWebWorker;
184
+ },
185
+ get workerThreadWorkerOptions(): IWorkerOptions {
186
+ return {
187
+ agentId,
188
+ hostName,
189
+ userAgent,
190
+ workdata: 'worker - hello world'
191
+ } as IWorkerOptions;
192
+ },
193
+ get primaryThreadWorkerOptions(): IWorkerOptions {
194
+ return {
195
+ agentId,
196
+ hostName,
197
+ userAgent,
198
+ primaryoptions: 'primary - hello world'
199
+ } as IWorkerOptions;
200
+ }
201
+ }
202
+
203
+ const PerformTesting = async () => {
204
+ const wm = new STSWorkerManager(null, {
205
+ workerFactory,
206
+ publishInstrumentController: agentInstrumentController
207
+ });
208
+ const worker = await wm.AddWorker();
209
+
210
+ const runnerOptions: IRunnerOptions = {
211
+ iterations: 100000,
212
+ sleepDuration: 250,
213
+ messageMod: 1,
214
+ logMessageMod: 1
215
+ } as IRunnerOptions;
216
+
217
+ const runner1 = worker.AddRunner(runnerOptions);
218
+ runner1.Start();
219
+
220
+ const runner2 = wm.AddRunnerToWorker(worker, runnerOptions);
221
+ runner2.Start();
222
+
223
+ wm.AddRunnerToWorker(worker, runnerOptions).Start();
224
+ };
225
+ PerformTesting();
226
+
227
+
228
+ /*
229
+ const fileName ='./dist/webworkertesting/worker.js';
230
+
231
+ const clusterWorker = new Worker(fileName);
232
+ clusterWorker.unref();
233
+
234
+ clusterWorker.postMessage({cmd: 'text', message: 'Hello World'});
235
+
236
+ clusterWorker.on('message', (data: any) => {
237
+ LogInfoMessage(`cluster.worker (${process.pid}): message from worker = [${JSON.stringify(data)}]`);
238
+ });
239
+ */
240
+
241
+ LogInfoMessage(`cluster work completed ...`);
242
+
243
+ }
@@ -0,0 +1,197 @@
1
+ import { Worker, MessagePort } from 'worker_threads';
2
+
3
+ import { PublishInstrumentController } from '@nsshunt/stsobservability'
4
+
5
+ import { IContextBase } from '@nsshunt/stsobservability'
6
+
7
+ export const URI_BASE_VUEUTILS: string = '/';
8
+
9
+ export interface IAsyncRunnerContext extends IContextBase {
10
+ id: string
11
+ hostName: string
12
+ agentName: string
13
+ threadId: string
14
+ asyncRunnerId: number
15
+ }
16
+
17
+ /**
18
+ * Inter-Worker (IW) Payload context base.
19
+ */
20
+ export interface IIWMessagePayloadContentBase {
21
+ messageId?: string
22
+ }
23
+
24
+ /**
25
+ * Inter-Worker (IW) message commands.
26
+ */
27
+ export enum eIWMessageCommands {
28
+ InstrumentTelemetry ='__STS__InstrumentTelemetry', // Used to send instrument telemetry
29
+ MessagePort = '__STS__MessagePort',
30
+ MessagePortResponse = '__STS__MessagePortResponse',
31
+ AddAsyncRunner = '__STS__AddAsyncRunner',
32
+ StopAllAsyncRunners = '__STS__StopAllAsyncRunners',
33
+ StartRunner = '__STS__StartRunner',
34
+ }
35
+
36
+ /**
37
+ * Inter-Worker (IW) message command.
38
+ */
39
+ export type IIWMessageCommand = eIWMessageCommands
40
+
41
+ /**
42
+ * Inter-Worker (IW) message payload.
43
+ */
44
+ export interface IIWMessagePayload {
45
+ command: IIWMessageCommand
46
+ payload: IIWMessagePayloadContentBase
47
+ }
48
+
49
+ export interface IObservabilitySubscriberManagerOptions {
50
+ modelId: string
51
+ consumeInstrumentationMode: string
52
+ instrumentManagerEndpoint: string
53
+ instrumentManagerPort: string
54
+ instrumentManagerAPIRoot: string
55
+ }
56
+
57
+ export interface ISTSAgentWorkerMessagePort extends IIWMessagePayloadContentBase {
58
+ port: MessagePort
59
+ options: IWorkerOptions
60
+ }
61
+
62
+ export enum IRunnerState {
63
+ created = 'created',
64
+ running = 'running',
65
+ stopped = 'stopped',
66
+ paused = 'paused',
67
+ error = 'error',
68
+ }
69
+
70
+ export interface IRunnerTelemetry {
71
+ requestCount: number // requestCount
72
+ errorCount: number
73
+ retryCount: number
74
+ authenticationCount: number
75
+ authenticationErrorCount: number
76
+ authenticationRetryCount: number
77
+ velocity: number
78
+ coreCount: number
79
+ timer: number
80
+ duration: number
81
+ latency: number
82
+ activeRequestCount: number
83
+ message: string[]
84
+ childCount: number
85
+ rx: number
86
+ tx: number
87
+ }
88
+
89
+ export interface IRunner {
90
+ id: number
91
+ asyncRunnerContext: IAsyncRunnerContext
92
+ options: IRunnerOptions
93
+ state: IRunnerState
94
+ instrumentData: IRunnerTelemetry
95
+ }
96
+
97
+ export interface IRunnerEx extends IRunner {
98
+ publishInstrumentController: PublishInstrumentController
99
+ Start: () => Promise<boolean>
100
+ Pause: () => Promise<boolean>
101
+ Resume: () => Promise<boolean>
102
+ Stop: () => Promise<boolean>
103
+ ApplyConfig: (config: IRunnerOptions) => Promise<boolean>
104
+ GetConfig(): IRunnerOptions
105
+ }
106
+
107
+ export enum IWorkerState {
108
+ starting = 'starting',
109
+ started = 'started',
110
+ stopped = 'stopped'
111
+ }
112
+
113
+
114
+ export interface IWorkerOptions {
115
+ hostName: string
116
+ agentId: string
117
+ userAgent: string
118
+ }
119
+
120
+ export type Runners = Record<string, IRunner>
121
+
122
+ export interface IWorker {
123
+ id: number
124
+ state: IWorkerState
125
+ primaryThreadWorkerOptions: IWorkerOptions
126
+ workerThreadWorkerOptions: IWorkerOptions
127
+ runners?: Runners // Will be created by utility helper
128
+ }
129
+
130
+ export type Workers = Record<string, IWorker>
131
+
132
+ export interface IPrimaryWorker {
133
+ ProcessMessageFromWorker(workerPort: MessagePort, publishMessagePayload: IIWMessagePayload): Promise<void>
134
+ }
135
+
136
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
137
+ export interface IRunnerOptions {
138
+
139
+ }
140
+
141
+ export interface IWorkerEx extends IWorker {
142
+ worker: Worker
143
+ primaryWorker: IPrimaryWorker
144
+ runnersEx: Record<string, IRunnerEx>
145
+ GetRunner(id: string): IRunnerEx | null
146
+ AddRunner: (runnerOptions: IRunnerOptions) => IRunnerEx
147
+ StartRunner: (runner: IRunnerEx) => Promise<boolean>
148
+ StopRunner: (runner: IRunnerEx) => Promise<boolean>
149
+ Stop: () => Promise<boolean>
150
+ }
151
+
152
+ export interface ISTSTestWorkerOptions {
153
+ messageMod: number
154
+ iterations: number
155
+ }
156
+
157
+ export interface ITelemetryStore {
158
+ workers: Workers
159
+ }
160
+
161
+ export interface ITestRunnerTelemetryPayload extends IIWMessagePayloadContentBase {
162
+ runner: IRunner
163
+ }
164
+
165
+ export interface IWorkerFactory {
166
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
167
+ createPrimaryThreadWorker: (app: any, options: IWorkerOptions) => IPrimaryWorker
168
+ createWorkerThreadWorker: () => Worker // | wt.Worker
169
+ get workerThreadWorkerOptions(): IWorkerOptions // These options will be passed as a message to the thread worker once setup
170
+ get primaryThreadWorkerOptions(): IWorkerOptions // These options will be passed as a message to the thread worker once setup
171
+ }
172
+
173
+ export interface IWorkerManagerOptions {
174
+ workerFactory: IWorkerFactory
175
+ publishInstrumentController: PublishInstrumentController
176
+ }
177
+
178
+ export const PublishMessageCommandsTestRunner = {
179
+ ...eIWMessageCommands,
180
+ GetAccessToken: '__GetAccessToken',
181
+ GetAccessTokenResponse: '__GetAccessTokenResponse',
182
+ GetDataFromPrimary: '__GetDataFromPrimary',
183
+ ExecuteRefreshToken: '__ExecuteRefreshToken',
184
+ ExecuteRefreshTokenResponse: '__ExecuteRefreshTokenResponse'
185
+ } as const
186
+
187
+ export type PublishMessageCommandsTestRunner = typeof PublishMessageCommandsTestRunner[keyof typeof PublishMessageCommandsTestRunner];
188
+
189
+ export interface IIWMessagePayloadContentBase {
190
+ messageId?: string;
191
+ }
192
+
193
+ export interface IIWMessagePayload {
194
+ command: IIWMessageCommand;
195
+ payload: IIWMessagePayloadContentBase;
196
+ }
197
+
@@ -0,0 +1,95 @@
1
+ /* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
2
+ import { MessagePort } from 'worker_threads';
3
+
4
+ import type { IIWMessagePayload } from './commonTypes'
5
+
6
+ import { defaultLogger } from '@nsshunt/stsutils'
7
+
8
+ declare interface RequestResponseMessage {
9
+ publishMessagePayload: IIWMessagePayload
10
+ publishMessagePayloadResponse?: IIWMessagePayload
11
+ cb: () => void,
12
+ timeout: NodeJS.Timeout
13
+ }
14
+
15
+ declare type RequestResponseMessages = Record<string, RequestResponseMessage>;
16
+
17
+ //@@ this should become a low level stsutils type helper
18
+ export class RequestResponseHelper
19
+ {
20
+ #requestResponseMessages: RequestResponseMessages = { }
21
+ #requestResponseMessageTimeout = 10000; //@@ config
22
+ #port: MessagePort
23
+
24
+ constructor(port: MessagePort) {
25
+ this.#port = port
26
+ this.#SetupListener();
27
+ }
28
+
29
+
30
+ #debug = (message: any) => {
31
+ defaultLogger.debug(message);
32
+ }
33
+
34
+ PostMessage = (message: IIWMessagePayload): Promise<IIWMessagePayload> => {
35
+ return new Promise((resolve, reject) => {
36
+ const { messageId } = message.payload;
37
+ if (messageId) {
38
+ if (this.#requestResponseMessages[messageId]) {
39
+ reject(`RequestResponseHelper: Message with id: [${messageId}] already exists within the Request/Response record structure`);
40
+ } else {
41
+ this.#requestResponseMessages[messageId] = {
42
+ publishMessagePayload: { ...message },
43
+ cb: () => {
44
+ const detail = this.#requestResponseMessages[messageId].publishMessagePayloadResponse;
45
+ clearTimeout(this.#requestResponseMessages[messageId].timeout);
46
+ setTimeout(() => {
47
+ delete this.#requestResponseMessages[messageId];
48
+ }, 0);
49
+ if (detail) {
50
+ this.#debug(`RequestResponseHelper: Resolving response message with id: [${messageId}] from target worker port. Details: [${JSON.stringify(detail)}]`);
51
+ resolve(detail);
52
+ } else {
53
+ const msg = `Could not get detail from this.#requestResponseMessages[messageId].publishMessagePayloadResponse`;
54
+ this.#debug(msg);
55
+ reject(msg);
56
+ }
57
+ },
58
+ timeout: setTimeout(() => {
59
+ setTimeout(() => {
60
+ delete this.#requestResponseMessages[messageId];
61
+ }, 0);
62
+ this.#debug(`RequestResponseHelper: Timeout has occurred after: [${this.#requestResponseMessageTimeout}]ms with message id: [${messageId}]. Details: [${JSON.stringify(this.#requestResponseMessages[messageId].publishMessagePayload)}]`);
63
+ reject('RequestResponseHelper: Did not receive response form parent process.');
64
+ }, this.#requestResponseMessageTimeout) // max message timeout allowed
65
+ };
66
+ //debug(`RequestResponseHelper: Sending message with id: [${messageId}] to target worker port. Details: [${JSON.stringify(this.#requestResponseMessages[messageId].publishMessagePayload)}]`);
67
+ this.#port.postMessage(message);
68
+ }
69
+ } else {
70
+ const msg = `RequestResponseHelper: Response did not include a message id`;
71
+ this.#debug(msg);
72
+ reject(msg);
73
+ }
74
+ });
75
+ }
76
+
77
+ #SetupListener = () => {
78
+ //this.#port.onmessage = async (msg: MessageEvent) => {
79
+ this.#port.on('message', (msg: any) => {
80
+ const publishMessagePayload: IIWMessagePayload = msg.data as IIWMessagePayload;
81
+ if (publishMessagePayload.payload.messageId) {
82
+ const messageId = publishMessagePayload.payload.messageId;
83
+ if (messageId && messageId !== '') {
84
+ if (this.#requestResponseMessages[messageId]) {
85
+ const requestResponseMessage: RequestResponseMessage = this.#requestResponseMessages[messageId];
86
+ requestResponseMessage.publishMessagePayloadResponse = { ...publishMessagePayload };
87
+ requestResponseMessage.cb();
88
+ } else {
89
+ throw new Error(`RequestResponseHelper: Could not find Request/Response message with id: [${messageId}]`);
90
+ }
91
+ }
92
+ }
93
+ });
94
+ }
95
+ }
@@ -0,0 +1,128 @@
1
+ import { PublishInstrumentController, InstrumentGaugeTelemetry, Gauge } from "@nsshunt/stsobservability";
2
+ import { IRunnerTelemetry } from "./commonTypes";
3
+
4
+ export class TelemetryProcessor {
5
+ ProcessTelemetry = (publishInstrumentController: PublishInstrumentController, telemetry: IRunnerTelemetry): boolean => {
6
+ let update = false;
7
+
8
+ if (telemetry.message) {
9
+ telemetry.message.forEach((message) => {
10
+ publishInstrumentController.LogEx(message);
11
+ });
12
+ update = true;
13
+ }
14
+
15
+ if (telemetry.requestCount) {
16
+ publishInstrumentController.UpdateInstrument(Gauge.REQUEST_COUNT_GAUGE, {
17
+ val: telemetry.requestCount
18
+ } as InstrumentGaugeTelemetry);
19
+ update = true;
20
+ }
21
+
22
+ if (telemetry.errorCount) {
23
+ publishInstrumentController.UpdateInstrument(Gauge.ERROR_COUNT_GAUGE, {
24
+ val: telemetry.errorCount
25
+ } as InstrumentGaugeTelemetry);
26
+ update = true;
27
+ }
28
+
29
+ if (telemetry.retryCount) {
30
+ publishInstrumentController.UpdateInstrument(Gauge.RETRY_COUNT_GAUGE, {
31
+ val: telemetry.retryCount
32
+ } as InstrumentGaugeTelemetry);
33
+ update = true;
34
+ }
35
+
36
+ if (telemetry.authenticationCount) {
37
+ publishInstrumentController.UpdateInstrument(Gauge.AUTHENTICATION_COUNT_GAUGE, {
38
+ val: telemetry.authenticationCount
39
+ } as InstrumentGaugeTelemetry);
40
+ update = true;
41
+ }
42
+
43
+ if (telemetry.authenticationErrorCount) {
44
+ publishInstrumentController.UpdateInstrument(Gauge.AUTHENTICATION_ERROR_COUNT_GAUGE, {
45
+ val: telemetry.authenticationCount
46
+ } as InstrumentGaugeTelemetry);
47
+ update = true;
48
+ }
49
+
50
+ if (telemetry.authenticationRetryCount) {
51
+ publishInstrumentController.UpdateInstrument(Gauge.AUTHENTICATION_RETRY_COUNT_GAUGE, {
52
+ val: telemetry.authenticationCount
53
+ } as InstrumentGaugeTelemetry);
54
+ update = true;
55
+ }
56
+
57
+ if (telemetry.coreCount) {
58
+ publishInstrumentController.UpdateInstrument(Gauge.CORE_COUNT_GAUGE, {
59
+ val: telemetry.coreCount
60
+ } as InstrumentGaugeTelemetry);
61
+ update = true;
62
+ }
63
+
64
+ if (telemetry.timer) {
65
+ publishInstrumentController.UpdateInstrument(Gauge.TIMER_GAUGE, {
66
+ val: telemetry.timer
67
+ } as InstrumentGaugeTelemetry);
68
+ update = true;
69
+ }
70
+
71
+ if (telemetry.activeRequestCount) {
72
+ publishInstrumentController.UpdateInstrument(Gauge.ACTIVE_REQUEST_GAUGE, {
73
+ val: telemetry.activeRequestCount
74
+ } as InstrumentGaugeTelemetry);
75
+ update = true;
76
+ }
77
+
78
+ if (telemetry.velocity) {
79
+ publishInstrumentController.UpdateInstrument(Gauge.VELOCITY_GAUGE, {
80
+ Inc: telemetry.velocity
81
+ } as InstrumentGaugeTelemetry);
82
+ update = true;
83
+ }
84
+
85
+ if (telemetry.duration) {
86
+ publishInstrumentController.UpdateInstrument(Gauge.DURATION_GAUGE, {
87
+ val: telemetry.duration
88
+ } as InstrumentGaugeTelemetry);
89
+ publishInstrumentController.UpdateInstrument(Gauge.DURATION_HISTOGRAM_GAUGE, {
90
+ val: telemetry.duration
91
+ } as InstrumentGaugeTelemetry);
92
+ update = true;
93
+ }
94
+
95
+ if (telemetry.latency) {
96
+ publishInstrumentController.UpdateInstrument(Gauge.LATENCY_GAUGE, {
97
+ val: telemetry.latency
98
+ } as InstrumentGaugeTelemetry);
99
+ publishInstrumentController.UpdateInstrument(Gauge.LATENCY_HISTOGRAM_GAUGE, {
100
+ val: telemetry.latency
101
+ } as InstrumentGaugeTelemetry);
102
+ update = true;
103
+ }
104
+
105
+ if (telemetry.childCount) {
106
+ publishInstrumentController.UpdateInstrument(Gauge.CHILD_COUNT, {
107
+ val: telemetry.childCount
108
+ } as InstrumentGaugeTelemetry);
109
+ update = true;
110
+ }
111
+
112
+ if (telemetry.rx) {
113
+ publishInstrumentController.UpdateInstrument(Gauge.NETWORK_RX_GAUGE, {
114
+ Inc: telemetry.rx
115
+ } as InstrumentGaugeTelemetry);
116
+ update = true;
117
+ }
118
+
119
+ if (telemetry.tx) {
120
+ publishInstrumentController.UpdateInstrument(Gauge.NETWORK_TX_GAUGE, {
121
+ Inc: telemetry.tx
122
+ } as InstrumentGaugeTelemetry);
123
+ update = true;
124
+ }
125
+
126
+ return update;
127
+ }
128
+ }