Merge pull request #16519 from overleaf/bg-clsi-timeouts-add-metrics
add metrics for clsi cache operations GitOrigin-RevId: c5ec221afd235434c8b81bafa2f482f11422ac4e
This commit is contained in:
@@ -121,12 +121,13 @@ class Timer {
|
||||
this.buckets = buckets
|
||||
}
|
||||
|
||||
done() {
|
||||
// any labels passed into the done method override labels from constructor
|
||||
done(labels = {}) {
|
||||
const timeSpan = new Date() - this.start
|
||||
if (this.buckets) {
|
||||
histogram(this.key, timeSpan, this.buckets, this.labels)
|
||||
histogram(this.key, timeSpan, this.buckets, { ...this.labels, ...labels })
|
||||
} else {
|
||||
timing(this.key, timeSpan, this.sampleRate, this.labels)
|
||||
timing(this.key, timeSpan, this.sampleRate, { ...this.labels, ...labels })
|
||||
}
|
||||
return timeSpan
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@overleaf/metrics",
|
||||
"version": "4.1.0",
|
||||
"version": "4.2.0",
|
||||
"description": "A drop-in metrics and monitoring module for node.js apps",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -94,11 +94,16 @@ describe('Metrics module', function () {
|
||||
beforeEach('collect timings', async function () {
|
||||
const buckets = [10, 100, 1000]
|
||||
for (const duration of [1, 1, 1, 15, 15, 15, 105, 105, 105]) {
|
||||
const withBuckets = new Metrics.Timer('height', 1, {}, buckets)
|
||||
const withOutBuckets = new Metrics.Timer('depth', 1, {})
|
||||
const withBuckets = new Metrics.Timer(
|
||||
'height',
|
||||
1,
|
||||
{ label_1: 'a' },
|
||||
buckets
|
||||
)
|
||||
const withOutBuckets = new Metrics.Timer('depth', 1, { label_2: 'b' })
|
||||
await sleep(duration)
|
||||
withBuckets.done()
|
||||
withOutBuckets.done()
|
||||
withOutBuckets.done({ label_3: 'c' })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -109,6 +114,8 @@ describe('Metrics module', function () {
|
||||
1000: 9,
|
||||
'+Inf': 9,
|
||||
})
|
||||
const labelNames = await getMetric('histogram_height').labelNames
|
||||
expect(labelNames).to.deep.equal(['label_1'])
|
||||
})
|
||||
|
||||
it('without buckets', async function () {
|
||||
@@ -121,6 +128,8 @@ describe('Metrics module', function () {
|
||||
0.99: 105,
|
||||
0.999: 105,
|
||||
})
|
||||
const labelNames = await getMetric('timer_depth').labelNames
|
||||
expect(labelNames).to.deep.equal(['label_2', 'label_3'])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user