Skip to content

Commit

Permalink
Add metrics for GC duration
Browse files Browse the repository at this point in the history
Issue: BB-447
  • Loading branch information
francoisferrand committed Nov 22, 2023
1 parent 42c0b28 commit 94e19de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions extensions/gc/GarbageCollectorMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const gcS3Operations = ZenkoMetrics.createCounter({
],
});

const gcDuration = ZenkoMetrics.createHistogram({
name: 's3_gc_duration_seconds',
help: 'Duration of the garbage collector operation, calculated from the time when the GC is ' +
'requested to the end of the operation',
labelNames: [GC_LABEL_ORIGIN],
buckets: [0.2, 0.1, 0.5, 2.5, 10, 50],
});

class GarbageCollectorMetrics {
static handleError(log, err, method) {
if (log) {
Expand All @@ -33,6 +41,16 @@ class GarbageCollectorMetrics {
GarbageCollectorMetrics.handleError(log, err, 'GarbageCollectorMetrics.onS3Request');
}
}

static onGcCompleted(log, process, duration) {
try {
gcDuration.observe({
[GC_LABEL_ORIGIN]: process,
}, duration / 1000);
} catch (err) {
GarbageCollectorMetrics.handleError(log, err, 'GarbageCollectorMetrics.onGcComplete');
}
}
}

module.exports = {
Expand Down
5 changes: 5 additions & 0 deletions extensions/gc/tasks/GarbageCollectorTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class GarbageCollectorTask extends BackbeatTask {
}, entry.getLogInfo()));
return done(err);
}

GarbageCollectorMetrics.onGcCompleted(log, entry.ruleType,
Date.now() - entry.timestamp);
return done();
});
}
Expand Down Expand Up @@ -254,6 +257,8 @@ class GarbageCollectorTask extends BackbeatTask {
if (!err) {
log.end().info('completed expiration of archived data',
entry.getLogInfo());
GarbageCollectorMetrics.onGcCompleted(log, 'archive',
Date.now() - entry.timestamp);
}

next(err);
Expand Down

0 comments on commit 94e19de

Please sign in to comment.