@lucaapp/service-utils 1.4.0 → 1.4.1
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/lib/kafka/kafkaClient.js +29 -11
- package/package.json +1 -1
|
@@ -38,11 +38,21 @@ const messageProducedSizeCounter = new metrics_1.metricsClient.Histogram({
|
|
|
38
38
|
labelNames: ['topic'],
|
|
39
39
|
buckets: [64, 128, 256, 512, 1024, 2048, 4096, 8182],
|
|
40
40
|
});
|
|
41
|
+
const messageProduceError = new metrics_1.metricsClient.Counter({
|
|
42
|
+
name: 'kafka_message_produce_error_count',
|
|
43
|
+
help: 'Total number of errors during message produce',
|
|
44
|
+
labelNames: ['topic'],
|
|
45
|
+
});
|
|
41
46
|
const messageConsumedCounter = new metrics_1.metricsClient.Counter({
|
|
42
47
|
name: 'kafka_message_consume_count',
|
|
43
48
|
help: 'Total number of messages consumed',
|
|
44
49
|
labelNames: ['topic', 'groupId'],
|
|
45
50
|
});
|
|
51
|
+
const messageConsumedErrorCounter = new metrics_1.metricsClient.Counter({
|
|
52
|
+
name: 'kafka_message_consume_error_count',
|
|
53
|
+
help: 'Total number of errors during message consume',
|
|
54
|
+
labelNames: ['topic', 'groupId'],
|
|
55
|
+
});
|
|
46
56
|
const messageAcknowledgedCounter = new metrics_1.metricsClient.Counter({
|
|
47
57
|
name: 'kafka_message_consume_ack_count',
|
|
48
58
|
help: 'Total number of messages acknowledged',
|
|
@@ -153,17 +163,24 @@ class KafkaClient {
|
|
|
153
163
|
await consumer.run({
|
|
154
164
|
autoCommit: true,
|
|
155
165
|
eachMessage: async ({ message }) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
try {
|
|
167
|
+
messageConsumedCounter
|
|
168
|
+
.labels({ topic: kafkaTopic.valueOf(), groupId })
|
|
169
|
+
.inc();
|
|
170
|
+
const decryptedValue = await this.decryptValue(kafkaTopic, message.value);
|
|
171
|
+
await this.verifySignature(kafkaTopic, decryptedValue, message.headers);
|
|
172
|
+
const value = this.parseValue(decryptedValue);
|
|
173
|
+
this.logger.debug({ key: message.key, value, timestamp: message.timestamp }, 'Record received');
|
|
174
|
+
await handler({ ...message, value });
|
|
175
|
+
messageAcknowledgedCounter
|
|
176
|
+
.labels({ topic: kafkaTopic.valueOf(), groupId })
|
|
177
|
+
.inc();
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
messageConsumedErrorCounter
|
|
181
|
+
.labels({ topic: kafkaTopic.valueOf(), groupId })
|
|
182
|
+
.inc();
|
|
183
|
+
}
|
|
167
184
|
},
|
|
168
185
|
});
|
|
169
186
|
return consumer;
|
|
@@ -195,6 +212,7 @@ class KafkaClient {
|
|
|
195
212
|
.observe(Buffer.byteLength(encryptedValue));
|
|
196
213
|
}
|
|
197
214
|
catch (error) {
|
|
215
|
+
messageProduceError.labels({ topic }).inc();
|
|
198
216
|
throw (0, utils_1.logAndGetError)(this.logger, `Could not create producer for topic=${topic}`, error);
|
|
199
217
|
}
|
|
200
218
|
};
|