Skip to content

Commit

Permalink
Add Kafka lag metrics handling to both QueueProcessor and Replication…
Browse files Browse the repository at this point in the history
…StatusProcessor

Issue: BB-561
  • Loading branch information
KillianG committed Nov 7, 2024
1 parent 0d3062d commit da30c21
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions extensions/notification/queueProcessor/QueueProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ function onQueueProcessorEventProcessed(destination, eventType) {
});
}

const kafkaLagMetric = ZenkoMetrics.createGauge({
name: 's3_replication_queue_lag',
help: 'Number of update entries waiting to be consumed from the Kafka topic',
labelNames: ['origin', 'containerName', 'partition', 'serviceName'],
});


/**
* Contains methods to incrememt different metrics
* @typedef {Object} MetricsHandler
* @property {CounterInc} dataReplicationStatus - Increments the replication status metric for data operation
* @property {CounterInc} metadataReplicationStatus - Increments the replication status metric for metadata operation
* @property {CounterInc} dataReplicationBytes - Increments the replication bytes metric for data operation
* @property {CounterInc} metadataReplicationBytes - Increments the replication bytes metric for metadata operation
* @property {CounterInc} sourceDataBytes - Increments the source data bytes metric
* @property {CounterInc} reads - Increments the read metric
* @property {CounterInc} writes - Increments the write metric
* @property {HistogramObserve} timeElapsed - Observes the time elapsed metric
*/
const metricsHandler = {
lag: wrapGaugeSet(kafkaLagMetric, defaultLabels),

Check failure on line 50 in extensions/notification/queueProcessor/QueueProcessor.js

View workflow job for this annotation

GitHub Actions / tests

'wrapGaugeSet' is not defined

Check failure on line 50 in extensions/notification/queueProcessor/QueueProcessor.js

View workflow job for this annotation

GitHub Actions / tests

'defaultLabels' is not defined
};

class QueueProcessor extends EventEmitter {
/**
* Create a queue processor object to activate notification from a
Expand Down Expand Up @@ -329,6 +352,19 @@ class QueueProcessor extends EventEmitter {
*/
async handleMetrics(res, log) {
log.debug('metrics requested');

if (this.repConfig.queueProcessor.logConsumerMetricsIntervalS && this._consumer) {
// consumer stats lag is on a different update cycle so we need to
// update the metrics when requested
const lagStats = this._consumer.consumerStats.lag;
Object.keys(lagStats).forEach(partition => {
metricsHandler.lag({
partition,
serviceName: this.serviceName,
}, lagStats[partition]);
});
}

res.writeHead(200, {
'Content-Type': ZenkoMetrics.asPrometheusContentType(),
});
Expand Down
2 changes: 1 addition & 1 deletion extensions/replication/queueProcessor/QueueProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ class QueueProcessor extends EventEmitter {
static async handleMetrics(res, log) {
log.debug('metrics requested');

if (this.repConfig.queueProcessor.logConsumerMetricsIntervalS) {
if (this.repConfig.queueProcessor.logConsumerMetricsIntervalS && this._consumer) {
// consumer stats lag is on a different update cycle so we need to
// update the metrics when requested
const lagStats = this._consumer.consumerStats.lag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ class ReplicationStatusProcessor {
log.debug('metrics requested');
const metrics = await ZenkoMetrics.asPrometheus();

if (this.repConfig.queueProcessor.logConsumerMetricsIntervalS) {
if (this.repConfig.queueProcessor.logConsumerMetricsIntervalS && this._consumer) {
// consumer stats lag is on a different update cycle so we need to
// update the metrics when requested
const lagStats = this._consumer.consumerStats.lag;
Expand Down

0 comments on commit da30c21

Please sign in to comment.