@nsshunt/stsappframework 3.1.50 → 3.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -1
- package/types/index.d.ts +0 -1
- package/types/index.d.ts.map +1 -1
- package/dist/instrumentationsubscriber.js +0 -304
- package/dist/instrumentationsubscriber.js.map +0 -1
- package/src/instrumentationsubscriber.ts +0 -336
- package/types/instrumentationsubscriber.d.ts +0 -18
- package/types/instrumentationsubscriber.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -37,7 +37,6 @@ __exportStar(require("./influxdb/influxDBManagerAgent"), exports);
|
|
|
37
37
|
__exportStar(require("./influxdb/influxDBManagerLambda"), exports);
|
|
38
38
|
__exportStar(require("./publishertransports/publishTransportUtils"), exports);
|
|
39
39
|
__exportStar(require("./publishertransports/publishTransportDirect"), exports);
|
|
40
|
-
__exportStar(require("./instrumentationsubscriber"), exports);
|
|
41
40
|
__exportStar(require("./stsTransportWinston"), exports);
|
|
42
41
|
__exportStar(require("./stsTransportLoggerWinston"), exports);
|
|
43
42
|
__exportStar(require("./globalServiceDefinitions"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,mDAAgC;AAChC,6CAA0B;AAC1B,kDAA+B;AAC/B,kDAA+B;AAC/B,sDAAmC;AACnC,sDAAmC;AACnC,sDAAmC;AACnC,sDAAmC;AACnC,yDAAsC;AACtC,yDAAsC;AACtC,oDAAiC;AACjC,uDAAoC;AACpC,wDAAqC;AACrC,wDAAqC;AACrC,yDAAsC;AACtC,6DAA0C;AAC1C,iEAA8C;AAC9C,oEAAiD;AACjD,kEAA+C;AAC/C,mEAAgD;AAChD,8EAA2D;AAC3D,+EAA4D;AAC5D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,mDAAgC;AAChC,6CAA0B;AAC1B,kDAA+B;AAC/B,kDAA+B;AAC/B,sDAAmC;AACnC,sDAAmC;AACnC,sDAAmC;AACnC,sDAAmC;AACnC,yDAAsC;AACtC,yDAAsC;AACtC,oDAAiC;AACjC,uDAAoC;AACpC,wDAAqC;AACrC,wDAAqC;AACrC,yDAAsC;AACtC,6DAA0C;AAC1C,iEAA8C;AAC9C,oEAAiD;AACjD,kEAA+C;AAC/C,mEAAgD;AAChD,8EAA2D;AAC3D,+EAA4D;AAC5D,wDAAqC;AACrC,8DAA2C;AAC3C,6DAA0C"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -21,7 +21,6 @@ export * from './influxdb/influxDBManagerAgent'
|
|
|
21
21
|
export * from './influxdb/influxDBManagerLambda'
|
|
22
22
|
export * from './publishertransports/publishTransportUtils'
|
|
23
23
|
export * from './publishertransports/publishTransportDirect'
|
|
24
|
-
export * from './instrumentationsubscriber'
|
|
25
24
|
export * from './stsTransportWinston'
|
|
26
25
|
export * from './stsTransportLoggerWinston'
|
|
27
26
|
export * from './globalServiceDefinitions'
|
package/types/index.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ export * from './influxdb/influxDBManagerAgent';
|
|
|
21
21
|
export * from './influxdb/influxDBManagerLambda';
|
|
22
22
|
export * from './publishertransports/publishTransportUtils';
|
|
23
23
|
export * from './publishertransports/publishTransportDirect';
|
|
24
|
-
export * from './instrumentationsubscriber';
|
|
25
24
|
export * from './stsTransportWinston';
|
|
26
25
|
export * from './stsTransportLoggerWinston';
|
|
27
26
|
export * from './globalServiceDefinitions';
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"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CAAA;AAC/C,cAAc,kCAAkC,CAAA;AAChD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,8CAA8C,CAAA;AAC5D,cAAc,uBAAuB,CAAA;AACrC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,4BAA4B,CAAA"}
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.InstrumentationSubscriber = void 0;
|
|
7
|
-
const stssocketio_client_1 = require("@nsshunt/stssocketio-client");
|
|
8
|
-
const kafkamanager_1 = require("./kafka/kafkamanager");
|
|
9
|
-
const influxDBManager_1 = require("./influxdb/influxDBManager");
|
|
10
|
-
const uuid_1 = require("uuid");
|
|
11
|
-
const stsconfig_1 = require("@nsshunt/stsconfig");
|
|
12
|
-
const stsutils_1 = require("@nsshunt/stsutils");
|
|
13
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
-
const goptions = (0, stsconfig_1.$Options)();
|
|
15
|
-
/**
|
|
16
|
-
* Maintain list of instrumentation subscriptions.
|
|
17
|
-
*/
|
|
18
|
-
class InstrumentationSubscriber extends stsutils_1.STSOptionsBase {
|
|
19
|
-
#subscriptions = {};
|
|
20
|
-
#influxDBManager;
|
|
21
|
-
#timeout = null;
|
|
22
|
-
#km;
|
|
23
|
-
#stop = true;
|
|
24
|
-
constructor(options) {
|
|
25
|
-
super(options);
|
|
26
|
-
this.#influxDBManager = new influxDBManager_1.InfluxDBManager(this.options?.logger);
|
|
27
|
-
const kmc = {
|
|
28
|
-
clientId: `${goptions.kafka_clientId}_${(0, uuid_1.v4)()}`,
|
|
29
|
-
brokers: goptions.kafka_brokers.split(','),
|
|
30
|
-
keepAlive: goptions.kafka_keep_alive,
|
|
31
|
-
adminTimeout: goptions.kafka_admin_timeout,
|
|
32
|
-
connectionTimeout: goptions.kafka_connection_timeout,
|
|
33
|
-
logLevel: goptions.kafka_log_level,
|
|
34
|
-
useSSL: goptions.kafka_use_ssl,
|
|
35
|
-
requestTimeout: goptions.kafka_request_timeout,
|
|
36
|
-
logger: this.options?.logger
|
|
37
|
-
};
|
|
38
|
-
if (goptions.kafka_use_ssl) {
|
|
39
|
-
kmc.ssl = {
|
|
40
|
-
rejectUnauthorized: goptions.kafka_ssl_rejectUnauthorized,
|
|
41
|
-
cafile: goptions.kafka_ssl_cafile,
|
|
42
|
-
certfileFile: goptions.kafka_ssl_certfile,
|
|
43
|
-
keyfile: goptions.kafka_ssl_keyfile
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
this.#km = new kafkamanager_1.KafkaManager(kmc);
|
|
47
|
-
}
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
-
#LogDebugMessage(message) {
|
|
50
|
-
this.options?.logger.debug(message);
|
|
51
|
-
}
|
|
52
|
-
async #UnSubscribeKafka(subscription) {
|
|
53
|
-
const unsubscribeKafka = async () => {
|
|
54
|
-
const kafka = subscription.kafka;
|
|
55
|
-
if (kafka) {
|
|
56
|
-
// Un-Subscribe from this kafka topic
|
|
57
|
-
this.#LogDebugMessage(chalk_1.default.yellow(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Starting`));
|
|
58
|
-
await kafka.kafkaConsumer?.Stop((error) => {
|
|
59
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Stop Error: [${error}]`));
|
|
60
|
-
});
|
|
61
|
-
await kafka.kafkaConsumer?.Disconnect((error) => {
|
|
62
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Disconnect Error: [${error}]`));
|
|
63
|
-
});
|
|
64
|
-
this.#LogDebugMessage(chalk_1.default.yellow(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Completed.`));
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.#LogDebugMessage(chalk_1.default.magenta(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka details do not exist for this topc: [${JSON.stringify(subscription.subscriptionKey)}].`));
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
return unsubscribeKafka();
|
|
71
|
-
}
|
|
72
|
-
async #SubscribeKafka(subscription) {
|
|
73
|
-
const kafkaSubscribe = async () => {
|
|
74
|
-
if (subscription.subscriptionKey.id) {
|
|
75
|
-
const kafkaSafeKey = `${subscription.subscriptionKey.key}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
76
|
-
const kafkaGroupId = (0, uuid_1.v4)();
|
|
77
|
-
subscription.kafka = {
|
|
78
|
-
kafkaTopic: kafkaSafeKey,
|
|
79
|
-
kafkaGroupId: kafkaGroupId,
|
|
80
|
-
kafkaConsumer: this.#km.CreateConsumer(kafkaGroupId),
|
|
81
|
-
kafkaFromBeginning: goptions.kafka_consume_from_beginning
|
|
82
|
-
};
|
|
83
|
-
this.#LogDebugMessage(chalk_1.default.yellow(`InstrumentationSubscriber:#SubscribeKafka(): Subscribe to Kafka topc: [${subscription.kafka.kafkaTopic}] Starting`));
|
|
84
|
-
const kafka = subscription.kafka;
|
|
85
|
-
let connectError = false;
|
|
86
|
-
await kafka.kafkaConsumer.Connect((error) => {
|
|
87
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Connect: Error: [${error}]`));
|
|
88
|
-
connectError = true;
|
|
89
|
-
});
|
|
90
|
-
if (!connectError) {
|
|
91
|
-
let subscribeError = false;
|
|
92
|
-
await kafka.kafkaConsumer.Subscribe([kafka.kafkaTopic], subscription.kafka.kafkaFromBeginning, (error) => {
|
|
93
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Subscribe: Error: [${error}]`));
|
|
94
|
-
subscribeError = true;
|
|
95
|
-
});
|
|
96
|
-
if (!subscribeError) {
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
98
|
-
await kafka.kafkaConsumer.StartConsumingMessages((topic, key, partition, value, headers) => {
|
|
99
|
-
try {
|
|
100
|
-
if (key != "" && value != "") {
|
|
101
|
-
if (topic.localeCompare(key) === 0) {
|
|
102
|
-
subscription.cb({
|
|
103
|
-
subscriptionKey: subscription.subscriptionKey, // Original requested topic (may be kafka un-safe)
|
|
104
|
-
data: {
|
|
105
|
-
kafkaTopic: kafka.kafkaTopic, // Safe kafka topic key with prefix. kafkaTopic, topic and key should be same value
|
|
106
|
-
kafkaGroupId: kafka.kafkaGroupId,
|
|
107
|
-
partition,
|
|
108
|
-
topic, // kafkaTopic, topic and key should be same value
|
|
109
|
-
key, // kafkaTopic, topic and key should be same value
|
|
110
|
-
value
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}] and key: [${key}] do not match`));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}], key: [${key}], value: [${value}]`));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#SubscribeKafka(): Error: [${error}]`));
|
|
124
|
-
}
|
|
125
|
-
}, (error) => {
|
|
126
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.StartConsumingMessages: Error: [${error}]`));
|
|
127
|
-
});
|
|
128
|
-
this.#LogDebugMessage(chalk_1.default.yellow(`InstrumentationSubscriber:#SubscribeKafka(): Subscribe to Kafka topc: [${kafka.kafkaTopic}] Completed`));
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], Could not subscribe to topic, StartConsumingMessages aborted.`));
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], Could not connect to topic, subscribe aborted.`));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
this.#LogDebugMessage(chalk_1.default.magenta(`InstrumentationSubscriber:#SubscribeKafka(): Could not subscribe to Kafka topc, missing combinedKey for topic: [${JSON.stringify(subscription.subscriptionKey)}]`));
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
return kafkaSubscribe();
|
|
143
|
-
}
|
|
144
|
-
async #OutputSubscription(subscription) {
|
|
145
|
-
// Service subscriptions
|
|
146
|
-
const { subscriptionKey } = subscription;
|
|
147
|
-
switch (subscriptionKey.topic) {
|
|
148
|
-
// Services -------------------------------------------------------------------------------------------
|
|
149
|
-
case stssocketio_client_1.SubscriptionTopic.AllServicesCombined:
|
|
150
|
-
return this.#influxDBManager.serviceManager.GetInfluxDBResultsRootService(subscriptionKey);
|
|
151
|
-
case stssocketio_client_1.SubscriptionTopic.Services:
|
|
152
|
-
return this.#influxDBManager.serviceManager.GetInfluxDBResultsService(subscriptionKey);
|
|
153
|
-
case stssocketio_client_1.SubscriptionTopic.ServiceInstances:
|
|
154
|
-
if (subscriptionKey.key) { // key = service_id
|
|
155
|
-
return this.#influxDBManager.serviceManager.GetInfluxDBResultsServiceInstances(subscriptionKey);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
throw new Error(`#OutputSubscription: key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
159
|
-
}
|
|
160
|
-
case stssocketio_client_1.SubscriptionTopic.ServiceInstance:
|
|
161
|
-
if (subscriptionKey.key && subscriptionKey.subkey) { // key = service instance id
|
|
162
|
-
return this.#influxDBManager.serviceManager.GetInfluxDBResultsServiceInstance(subscriptionKey);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
throw new Error(`#OutputSubscription: key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
166
|
-
}
|
|
167
|
-
// User Agents -------------------------------------------------------------------------------------------
|
|
168
|
-
case stssocketio_client_1.SubscriptionTopic.AllAgentsCombined:
|
|
169
|
-
return this.#influxDBManager.agentManager.GetInfluxDBResultsRootAgent(subscriptionKey);
|
|
170
|
-
case stssocketio_client_1.SubscriptionTopic.Agents:
|
|
171
|
-
return this.#influxDBManager.agentManager.GetInfluxDBResultsAgent(subscriptionKey);
|
|
172
|
-
case stssocketio_client_1.SubscriptionTopic.AgentWorkers:
|
|
173
|
-
if (subscriptionKey.key) { // key = agent instance id
|
|
174
|
-
return this.#influxDBManager.agentManager.GetInfluxDBResultsAgentThreads(subscriptionKey);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
throw new Error(`#OutputSubscription: key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
178
|
-
}
|
|
179
|
-
case stssocketio_client_1.SubscriptionTopic.AgentWorker:
|
|
180
|
-
if (subscriptionKey.key && subscriptionKey.subkey) { // key = agent instance id, subkey = agent instance worker id
|
|
181
|
-
return this.#influxDBManager.agentManager.GetInfluxDBResultsAgentThread(subscriptionKey);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
throw new Error(`#OutputSubscription: key and/or subkey not provided for subscription: [${JSON.stringify(subscriptionKey.topic)}]`);
|
|
185
|
-
}
|
|
186
|
-
// Logging (both service and agent) -----------------------------------------------------------------------
|
|
187
|
-
case stssocketio_client_1.SubscriptionTopic.LogProcessing:
|
|
188
|
-
// Kafka processing will be handled by a dedicated kafka run consumer
|
|
189
|
-
return { subscriptionKey, data: null };
|
|
190
|
-
default:
|
|
191
|
-
return { subscriptionKey, data: null };
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
#ExecuteSubscriptions = async () => {
|
|
195
|
-
const promArray = [];
|
|
196
|
-
const indexArray = [];
|
|
197
|
-
for (const [, subscription] of Object.entries(this.#subscriptions)) {
|
|
198
|
-
// If NOT Kafka, go get the data from influxdb
|
|
199
|
-
if (subscription.subscriptionKey.topic.localeCompare(stssocketio_client_1.SubscriptionTopic.LogProcessing.toString()) !== 0) {
|
|
200
|
-
promArray.push(this.#OutputSubscription(subscription));
|
|
201
|
-
indexArray.push(subscription);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
const retVal = await Promise.all(promArray);
|
|
205
|
-
try {
|
|
206
|
-
for (let i = 0; i < retVal.length; i++) {
|
|
207
|
-
// Provided we have data, invoke the callback
|
|
208
|
-
if (retVal[i].data) {
|
|
209
|
-
indexArray[i].cb(retVal[i]);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
catch (error) {
|
|
214
|
-
this.#LogDebugMessage(chalk_1.default.red(`InstrumentationSubscriber:#ExecuteSubscriptions(): Error: [${error}], [${JSON.stringify(retVal)}]`));
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
#SetupTimeout = (timeout) => {
|
|
218
|
-
if (!this.#timeout && (Object.keys(this.#subscriptions).length > 0)) {
|
|
219
|
-
this.#timeout = setTimeout(async () => {
|
|
220
|
-
const start = performance.now();
|
|
221
|
-
await this.#ExecuteSubscriptions();
|
|
222
|
-
this.#timeout = null;
|
|
223
|
-
if (!this.#stop) {
|
|
224
|
-
let requiredTimeout = 1000; //@@ default
|
|
225
|
-
if (this.options) {
|
|
226
|
-
requiredTimeout = this.options.SubscriptionInterval;
|
|
227
|
-
}
|
|
228
|
-
const end = performance.now();
|
|
229
|
-
const diff = end - start;
|
|
230
|
-
let newTimeout = requiredTimeout - diff;
|
|
231
|
-
if (newTimeout < 500) {
|
|
232
|
-
newTimeout = 500;
|
|
233
|
-
}
|
|
234
|
-
this.#LogDebugMessage(chalk_1.default.grey(`InstrumentationSubscriber.#SetupTimeout(): ExecuteSubscriptions time: [${diff}], next timeout: [${newTimeout}]`));
|
|
235
|
-
this.#SetupTimeout(newTimeout);
|
|
236
|
-
}
|
|
237
|
-
}, timeout);
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
Subscribe(subscriptionKey, cb) {
|
|
241
|
-
if (this.#timeout) {
|
|
242
|
-
clearTimeout(this.#timeout);
|
|
243
|
-
this.#timeout = null;
|
|
244
|
-
}
|
|
245
|
-
if (this.#subscriptions[subscriptionKey.id]) {
|
|
246
|
-
// Subscription already exists - ignoring
|
|
247
|
-
this.#LogDebugMessage(chalk_1.default.magenta(`InstrumentationSubscriber.Subscribe(): Subscription already exists: [${subscriptionKey.id}] - ignoring.`));
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
this.#subscriptions[subscriptionKey.id] = {
|
|
251
|
-
subscriptionKey,
|
|
252
|
-
cb
|
|
253
|
-
};
|
|
254
|
-
if (subscriptionKey.topic.localeCompare(stssocketio_client_1.SubscriptionTopic.LogProcessing) === 0) {
|
|
255
|
-
this.#SubscribeKafka(this.#subscriptions[subscriptionKey.id]);
|
|
256
|
-
}
|
|
257
|
-
this.#LogDebugMessage(chalk_1.default.grey(`InstrumentationSubscriber.Subscribe(): subscriptionKey.id: [${subscriptionKey.id}] successfully subscribed.`));
|
|
258
|
-
if (!this.#timeout) {
|
|
259
|
-
(async () => {
|
|
260
|
-
// Output subscription immediately and then iterate ...
|
|
261
|
-
await this.#ExecuteSubscriptions();
|
|
262
|
-
let timeout = 1000; //@@ default
|
|
263
|
-
if (this.options) {
|
|
264
|
-
timeout = this.options.SubscriptionInterval;
|
|
265
|
-
}
|
|
266
|
-
this.#SetupTimeout(timeout);
|
|
267
|
-
})();
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
UnSubscribe(subscriptionKey) {
|
|
272
|
-
if (!this.#subscriptions[subscriptionKey.id]) {
|
|
273
|
-
this.#LogDebugMessage(chalk_1.default.magenta(`UnSubscribe(): Warning, subscriptionKey.id: [${subscriptionKey.id}] does not exist within subscription records`));
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
if (subscriptionKey.topic.localeCompare(stssocketio_client_1.SubscriptionTopic.LogProcessing) === 0) {
|
|
277
|
-
this.#UnSubscribeKafka(this.#subscriptions[subscriptionKey.id]);
|
|
278
|
-
}
|
|
279
|
-
delete this.#subscriptions[subscriptionKey.id];
|
|
280
|
-
if (Object.keys(this.#subscriptions).length === 0) {
|
|
281
|
-
if (this.#timeout) {
|
|
282
|
-
clearTimeout(this.#timeout);
|
|
283
|
-
this.#timeout = null;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
#UnSubscribeAll() {
|
|
289
|
-
for (const [, subscription] of Object.entries(this.#subscriptions)) {
|
|
290
|
-
this.UnSubscribe(subscription.subscriptionKey);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async Start() {
|
|
294
|
-
this.#stop = false;
|
|
295
|
-
return this.#influxDBManager.Start();
|
|
296
|
-
}
|
|
297
|
-
async Stop() {
|
|
298
|
-
this.#stop = true;
|
|
299
|
-
this.#UnSubscribeAll();
|
|
300
|
-
return this.#influxDBManager.Terminate();
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
exports.InstrumentationSubscriber = InstrumentationSubscriber;
|
|
304
|
-
//# sourceMappingURL=instrumentationsubscriber.js.map
|
|
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L,CAAC;IACL,CAAC;IAED,eAAe;QACX,KAAK,MAAM,CAAC,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;YACjE,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;QACnD,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACP,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,IAAI;QACN,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC;IAC7C,CAAC;CACJ;AA1SD,8DA0SC"}
|
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import { IKafkaConsumer } from './commonTypes'
|
|
2
|
-
import { ISubscriptionPayload, ISubscriptionKey, SubscriptionTopic, IKafkaData } from '@nsshunt/stssocketio-client'
|
|
3
|
-
|
|
4
|
-
import { KafkaManager, IKafkaManagerConfig } from './kafka/kafkamanager'
|
|
5
|
-
import { InfluxDBManager } from './influxdb/influxDBManager'
|
|
6
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
7
|
-
|
|
8
|
-
import { $Options } from '@nsshunt/stsconfig'
|
|
9
|
-
import { STSOptionsBase, ISTSLogger } from '@nsshunt/stsutils';
|
|
10
|
-
|
|
11
|
-
import chalk from 'chalk';
|
|
12
|
-
|
|
13
|
-
const goptions = $Options()
|
|
14
|
-
|
|
15
|
-
declare interface IKafkaSubscription {
|
|
16
|
-
kafkaTopic: string
|
|
17
|
-
kafkaGroupId: string
|
|
18
|
-
kafkaConsumer: IKafkaConsumer
|
|
19
|
-
kafkaFromBeginning: boolean
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
declare interface ISubscription {
|
|
23
|
-
subscriptionKey: ISubscriptionKey
|
|
24
|
-
kafka?: IKafkaSubscription
|
|
25
|
-
cb: (payload: ISubscriptionPayload) => void
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
declare type ISubscriptions = Record<string, ISubscription>;
|
|
29
|
-
|
|
30
|
-
export interface IInstrumentationSubscriberOptions {
|
|
31
|
-
SubscriptionInterval: number
|
|
32
|
-
logger: ISTSLogger
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Maintain list of instrumentation subscriptions.
|
|
37
|
-
*/
|
|
38
|
-
export class InstrumentationSubscriber extends STSOptionsBase {
|
|
39
|
-
#subscriptions: ISubscriptions = { };
|
|
40
|
-
#influxDBManager: InfluxDBManager;
|
|
41
|
-
#timeout: NodeJS.Timer | null = null;
|
|
42
|
-
#km: KafkaManager;
|
|
43
|
-
#stop: boolean = true;
|
|
44
|
-
|
|
45
|
-
constructor(options: IInstrumentationSubscriberOptions) {
|
|
46
|
-
super(options);
|
|
47
|
-
|
|
48
|
-
this.#influxDBManager = new InfluxDBManager(this.options?.logger);
|
|
49
|
-
|
|
50
|
-
const kmc: IKafkaManagerConfig = {
|
|
51
|
-
clientId: `${goptions.kafka_clientId}_${uuidv4()}`,
|
|
52
|
-
brokers: goptions.kafka_brokers.split(','),
|
|
53
|
-
keepAlive: goptions.kafka_keep_alive,
|
|
54
|
-
adminTimeout: goptions.kafka_admin_timeout,
|
|
55
|
-
connectionTimeout: goptions.kafka_connection_timeout,
|
|
56
|
-
logLevel: goptions.kafka_log_level,
|
|
57
|
-
useSSL: goptions.kafka_use_ssl,
|
|
58
|
-
requestTimeout: goptions.kafka_request_timeout,
|
|
59
|
-
logger: this.options?.logger
|
|
60
|
-
}
|
|
61
|
-
if (goptions.kafka_use_ssl) {
|
|
62
|
-
kmc.ssl = {
|
|
63
|
-
rejectUnauthorized: goptions.kafka_ssl_rejectUnauthorized,
|
|
64
|
-
cafile: goptions.kafka_ssl_cafile,
|
|
65
|
-
certfileFile: goptions.kafka_ssl_certfile,
|
|
66
|
-
keyfile: goptions.kafka_ssl_keyfile
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
this.#km = new KafkaManager(kmc);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
#LogDebugMessage(message: any) {
|
|
74
|
-
this.options?.logger.debug(message);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async #UnSubscribeKafka(subscription: ISubscription): Promise<void> {
|
|
78
|
-
const unsubscribeKafka = async () => {
|
|
79
|
-
const kafka = subscription.kafka;
|
|
80
|
-
if (kafka) {
|
|
81
|
-
// Un-Subscribe from this kafka topic
|
|
82
|
-
this.#LogDebugMessage(chalk.yellow(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Starting`));
|
|
83
|
-
|
|
84
|
-
await kafka.kafkaConsumer?.Stop((error) => {
|
|
85
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Stop Error: [${error}]`));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
await kafka.kafkaConsumer?.Disconnect((error) => {
|
|
89
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Disconnect Error: [${error}]`));
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
this.#LogDebugMessage(chalk.yellow(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Completed.`));
|
|
93
|
-
} else {
|
|
94
|
-
this.#LogDebugMessage(chalk.magenta(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka details do not exist for this topc: [${JSON.stringify(subscription.subscriptionKey)}].`));
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
return unsubscribeKafka();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async #SubscribeKafka(subscription: ISubscription): Promise<void> {
|
|
101
|
-
const kafkaSubscribe = async () => {
|
|
102
|
-
if (subscription.subscriptionKey.id) {
|
|
103
|
-
|
|
104
|
-
const kafkaSafeKey = `${subscription.subscriptionKey.key}`.replace(/@/g, '_').replace(/\|/g, '_');
|
|
105
|
-
|
|
106
|
-
const kafkaGroupId = uuidv4();
|
|
107
|
-
subscription.kafka = {
|
|
108
|
-
kafkaTopic: kafkaSafeKey,
|
|
109
|
-
kafkaGroupId: kafkaGroupId,
|
|
110
|
-
kafkaConsumer: this.#km.CreateConsumer(kafkaGroupId),
|
|
111
|
-
kafkaFromBeginning: goptions.kafka_consume_from_beginning
|
|
112
|
-
};
|
|
113
|
-
this.#LogDebugMessage(chalk.yellow(`InstrumentationSubscriber:#SubscribeKafka(): Subscribe to Kafka topc: [${subscription.kafka.kafkaTopic}] Starting`));
|
|
114
|
-
|
|
115
|
-
const kafka = subscription.kafka;
|
|
116
|
-
|
|
117
|
-
let connectError = false;
|
|
118
|
-
await kafka.kafkaConsumer.Connect((error) => {
|
|
119
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Connect: Error: [${error}]`));
|
|
120
|
-
connectError = true;
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
if (!connectError) {
|
|
124
|
-
let subscribeError = false;
|
|
125
|
-
await kafka.kafkaConsumer.Subscribe([kafka.kafkaTopic], subscription.kafka.kafkaFromBeginning, (error) => {
|
|
126
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.Subscribe: Error: [${error}]`));
|
|
127
|
-
subscribeError = true;
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
if (!subscribeError) {
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
132
|
-
await kafka.kafkaConsumer.StartConsumingMessages((topic, key, partition, value, headers) => {
|
|
133
|
-
try {
|
|
134
|
-
if (key != "" && value != "") {
|
|
135
|
-
if (topic.localeCompare(key) === 0) {
|
|
136
|
-
subscription.cb({
|
|
137
|
-
subscriptionKey: subscription.subscriptionKey,// Original requested topic (may be kafka un-safe)
|
|
138
|
-
data: {
|
|
139
|
-
kafkaTopic: kafka.kafkaTopic, // Safe kafka topic key with prefix. kafkaTopic, topic and key should be same value
|
|
140
|
-
kafkaGroupId: kafka.kafkaGroupId,
|
|
141
|
-
partition,
|
|
142
|
-
topic, // kafkaTopic, topic and key should be same value
|
|
143
|
-
key, // kafkaTopic, topic and key should be same value
|
|
144
|
-
value
|
|
145
|
-
} as IKafkaData
|
|
146
|
-
});
|
|
147
|
-
} else {
|
|
148
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}] and key: [${key}] do not match`));
|
|
149
|
-
}
|
|
150
|
-
} else {
|
|
151
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}], key: [${key}], value: [${value}]`));
|
|
152
|
-
}
|
|
153
|
-
} catch (error) {
|
|
154
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Error: [${error}]`));
|
|
155
|
-
}
|
|
156
|
-
}, (error) => {
|
|
157
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], kafkaConsumer.StartConsumingMessages: Error: [${error}]`));
|
|
158
|
-
});
|
|
159
|
-
this.#LogDebugMessage(chalk.yellow(`InstrumentationSubscriber:#SubscribeKafka(): Subscribe to Kafka topc: [${kafka.kafkaTopic}] Completed`));
|
|
160
|
-
} else {
|
|
161
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], Could not subscribe to topic, StartConsumingMessages aborted.`));
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#SubscribeKafka(): Kafka topic: [${kafka.kafkaTopic}], Could not connect to topic, subscribe aborted.`));
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
this.#LogDebugMessage(chalk.magenta(`InstrumentationSubscriber:#SubscribeKafka(): Could not subscribe to Kafka topc, missing combinedKey for topic: [${JSON.stringify(subscription.subscriptionKey)}]`));
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return kafkaSubscribe();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async #OutputSubscription(subscription: ISubscription): Promise<ISubscriptionPayload> {
|
|
174
|
-
// Service subscriptions
|
|
175
|
-
const { subscriptionKey } = subscription;
|
|
176
|
-
switch (subscriptionKey.topic) {
|
|
177
|
-
// Services -------------------------------------------------------------------------------------------
|
|
178
|
-
case SubscriptionTopic.AllServicesCombined :
|
|
179
|
-
return this.#influxDBManager.serviceManager.GetInfluxDBResultsRootService(subscriptionKey);
|
|
180
|
-
case SubscriptionTopic.Services :
|
|
181
|
-
return this.#influxDBManager.serviceManager.GetInfluxDBResultsService(subscriptionKey);
|
|
182
|
-
case SubscriptionTopic.ServiceInstances :
|
|
183
|
-
if (subscriptionKey.key) { // key = service_id
|
|
184
|
-
return this.#influxDBManager.serviceManager.GetInfluxDBResultsServiceInstances(subscriptionKey);
|
|
185
|
-
} else {
|
|
186
|
-
throw new Error(`#OutputSubscription: key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
187
|
-
}
|
|
188
|
-
case SubscriptionTopic.ServiceInstance :
|
|
189
|
-
if (subscriptionKey.key && subscriptionKey.subkey) { // key = service instance id
|
|
190
|
-
return this.#influxDBManager.serviceManager.GetInfluxDBResultsServiceInstance(subscriptionKey);
|
|
191
|
-
} else {
|
|
192
|
-
throw new Error(`#OutputSubscription: key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// User Agents -------------------------------------------------------------------------------------------
|
|
196
|
-
case SubscriptionTopic.AllAgentsCombined :
|
|
197
|
-
return this.#influxDBManager.agentManager.GetInfluxDBResultsRootAgent(subscriptionKey);
|
|
198
|
-
case SubscriptionTopic.Agents :
|
|
199
|
-
return this.#influxDBManager.agentManager.GetInfluxDBResultsAgent(subscriptionKey);
|
|
200
|
-
case SubscriptionTopic.AgentWorkers :
|
|
201
|
-
if (subscriptionKey.key) { // key = agent instance id
|
|
202
|
-
return this.#influxDBManager.agentManager.GetInfluxDBResultsAgentThreads(subscriptionKey);
|
|
203
|
-
} else {
|
|
204
|
-
throw new Error(`#OutputSubscription: key not provided for subscription: [${JSON.stringify(subscriptionKey)}]`);
|
|
205
|
-
}
|
|
206
|
-
case SubscriptionTopic.AgentWorker :
|
|
207
|
-
if (subscriptionKey.key && subscriptionKey.subkey) { // key = agent instance id, subkey = agent instance worker id
|
|
208
|
-
return this.#influxDBManager.agentManager.GetInfluxDBResultsAgentThread(subscriptionKey);
|
|
209
|
-
} else {
|
|
210
|
-
throw new Error(`#OutputSubscription: key and/or subkey not provided for subscription: [${JSON.stringify(subscriptionKey.topic)}]`);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Logging (both service and agent) -----------------------------------------------------------------------
|
|
214
|
-
case SubscriptionTopic.LogProcessing :
|
|
215
|
-
// Kafka processing will be handled by a dedicated kafka run consumer
|
|
216
|
-
return { subscriptionKey, data: null };
|
|
217
|
-
default :
|
|
218
|
-
return { subscriptionKey, data: null };
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
#ExecuteSubscriptions = async () => {
|
|
223
|
-
const promArray: Promise<ISubscriptionPayload>[] = [ ];
|
|
224
|
-
const indexArray: ISubscription[] = [ ];
|
|
225
|
-
|
|
226
|
-
for (const [, subscription] of Object.entries(this.#subscriptions)) {
|
|
227
|
-
// If NOT Kafka, go get the data from influxdb
|
|
228
|
-
if (subscription.subscriptionKey.topic.localeCompare(SubscriptionTopic.LogProcessing.toString()) !== 0) {
|
|
229
|
-
promArray.push(this.#OutputSubscription(subscription));
|
|
230
|
-
indexArray.push(subscription);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
const retVal = await Promise.all(promArray);
|
|
234
|
-
try {
|
|
235
|
-
for (let i=0; i < retVal.length; i++) {
|
|
236
|
-
// Provided we have data, invoke the callback
|
|
237
|
-
if (retVal[i].data) {
|
|
238
|
-
indexArray[i].cb(retVal[i]);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
} catch (error) {
|
|
242
|
-
this.#LogDebugMessage(chalk.red(`InstrumentationSubscriber:#ExecuteSubscriptions(): Error: [${error}], [${JSON.stringify(retVal)}]`));
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
#SetupTimeout = (timeout: number) => {
|
|
247
|
-
if (!this.#timeout && (Object.keys(this.#subscriptions).length > 0)) {
|
|
248
|
-
this.#timeout = setTimeout(async () => {
|
|
249
|
-
const start = performance.now();
|
|
250
|
-
await this.#ExecuteSubscriptions();
|
|
251
|
-
this.#timeout = null;
|
|
252
|
-
if (!this.#stop) {
|
|
253
|
-
let requiredTimeout = 1000; //@@ default
|
|
254
|
-
if (this.options) {
|
|
255
|
-
requiredTimeout = this.options.SubscriptionInterval
|
|
256
|
-
}
|
|
257
|
-
const end = performance.now();
|
|
258
|
-
const diff = end - start;
|
|
259
|
-
let newTimeout = requiredTimeout - diff;
|
|
260
|
-
if (newTimeout < 500) {
|
|
261
|
-
newTimeout = 500;
|
|
262
|
-
}
|
|
263
|
-
this.#LogDebugMessage(chalk.grey(`InstrumentationSubscriber.#SetupTimeout(): ExecuteSubscriptions time: [${diff}], next timeout: [${newTimeout}]`));
|
|
264
|
-
this.#SetupTimeout(newTimeout);
|
|
265
|
-
}
|
|
266
|
-
}, timeout);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
Subscribe(subscriptionKey: ISubscriptionKey, cb: (payload: ISubscriptionPayload) => void) {
|
|
271
|
-
if (this.#timeout) {
|
|
272
|
-
clearTimeout(this.#timeout);
|
|
273
|
-
this.#timeout = null;
|
|
274
|
-
}
|
|
275
|
-
if (this.#subscriptions[subscriptionKey.id]) {
|
|
276
|
-
// Subscription already exists - ignoring
|
|
277
|
-
this.#LogDebugMessage(chalk.magenta(`InstrumentationSubscriber.Subscribe(): Subscription already exists: [${subscriptionKey.id}] - ignoring.`));
|
|
278
|
-
} else {
|
|
279
|
-
this.#subscriptions[subscriptionKey.id] = {
|
|
280
|
-
subscriptionKey,
|
|
281
|
-
cb
|
|
282
|
-
}
|
|
283
|
-
if (subscriptionKey.topic.localeCompare(SubscriptionTopic.LogProcessing) === 0) {
|
|
284
|
-
this.#SubscribeKafka(this.#subscriptions[subscriptionKey.id]);
|
|
285
|
-
}
|
|
286
|
-
this.#LogDebugMessage(chalk.grey(`InstrumentationSubscriber.Subscribe(): subscriptionKey.id: [${subscriptionKey.id}] successfully subscribed.`));
|
|
287
|
-
|
|
288
|
-
if (!this.#timeout) {
|
|
289
|
-
(async () => {
|
|
290
|
-
// Output subscription immediately and then iterate ...
|
|
291
|
-
await this.#ExecuteSubscriptions();
|
|
292
|
-
let timeout = 1000; //@@ default
|
|
293
|
-
if (this.options) {
|
|
294
|
-
timeout = this.options.SubscriptionInterval
|
|
295
|
-
}
|
|
296
|
-
this.#SetupTimeout(timeout);
|
|
297
|
-
})();
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
UnSubscribe(subscriptionKey: ISubscriptionKey) {
|
|
303
|
-
if (!this.#subscriptions[subscriptionKey.id]) {
|
|
304
|
-
this.#LogDebugMessage(chalk.magenta(`UnSubscribe(): Warning, subscriptionKey.id: [${subscriptionKey.id}] does not exist within subscription records`));
|
|
305
|
-
} else {
|
|
306
|
-
if (subscriptionKey.topic.localeCompare(SubscriptionTopic.LogProcessing) === 0) {
|
|
307
|
-
this.#UnSubscribeKafka(this.#subscriptions[subscriptionKey.id]);
|
|
308
|
-
}
|
|
309
|
-
delete this.#subscriptions[subscriptionKey.id];
|
|
310
|
-
|
|
311
|
-
if (Object.keys(this.#subscriptions).length === 0) {
|
|
312
|
-
if (this.#timeout) {
|
|
313
|
-
clearTimeout(this.#timeout);
|
|
314
|
-
this.#timeout = null;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
#UnSubscribeAll() {
|
|
321
|
-
for (const [, subscription] of Object.entries(this.#subscriptions)) {
|
|
322
|
-
this.UnSubscribe(subscription.subscriptionKey);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
async Start() {
|
|
327
|
-
this.#stop = false;
|
|
328
|
-
return this.#influxDBManager.Start();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
async Stop() {
|
|
332
|
-
this.#stop = true;
|
|
333
|
-
this.#UnSubscribeAll();
|
|
334
|
-
return this.#influxDBManager.Terminate();
|
|
335
|
-
}
|
|
336
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ISubscriptionPayload, ISubscriptionKey } from '@nsshunt/stssocketio-client';
|
|
2
|
-
import { STSOptionsBase, ISTSLogger } from '@nsshunt/stsutils';
|
|
3
|
-
export interface IInstrumentationSubscriberOptions {
|
|
4
|
-
SubscriptionInterval: number;
|
|
5
|
-
logger: ISTSLogger;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Maintain list of instrumentation subscriptions.
|
|
9
|
-
*/
|
|
10
|
-
export declare class InstrumentationSubscriber extends STSOptionsBase {
|
|
11
|
-
#private;
|
|
12
|
-
constructor(options: IInstrumentationSubscriberOptions);
|
|
13
|
-
Subscribe(subscriptionKey: ISubscriptionKey, cb: (payload: ISubscriptionPayload) => void): void;
|
|
14
|
-
UnSubscribe(subscriptionKey: ISubscriptionKey): void;
|
|
15
|
-
Start(): Promise<void>;
|
|
16
|
-
Stop(): Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=instrumentationsubscriber.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentationsubscriber.d.ts","sourceRoot":"","sources":["../src/instrumentationsubscriber.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAiC,MAAM,6BAA6B,CAAA;AAOnH,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAqB/D,MAAM,WAAW,iCAAiC;IAC9C,oBAAoB,EAAE,MAAM,CAAA;IAC5B,MAAM,EAAE,UAAU,CAAA;CACrB;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,cAAc;;gBAO7C,OAAO,EAAE,iCAAiC;IAiOtD,SAAS,CAAC,eAAe,EAAE,gBAAgB,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI;IAgCxF,WAAW,CAAC,eAAe,EAAE,gBAAgB;IAwBvC,KAAK;IAKL,IAAI;CAKb"}
|