Merge pull request #47 from overleaf/jpa-drop-idle-background-loop

[misc] drop idle background loop
This commit is contained in:
Jakob Ackermann 2021-02-16 14:41:50 +00:00 committed by GitHub
commit 783a4f5c79
4 changed files with 23 additions and 12 deletions

View file

@ -30,6 +30,7 @@ function initialize(appName, opts = {}) {
appName = appName || DEFAULT_APP_NAME
configure({ ...opts, appName })
collectDefaultMetrics({ timeout: 5000, prefix: '' })
promWrapper.setupSweeping()
console.log(`ENABLE_TRACE_AGENT set to ${process.env.ENABLE_TRACE_AGENT}`)
if (process.env.ENABLE_TRACE_AGENT === 'true') {

View file

@ -1,6 +1,6 @@
{
"name": "@overleaf/metrics",
"version": "3.5.0",
"version": "3.5.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View file

@ -1,6 +1,6 @@
{
"name": "@overleaf/metrics",
"version": "3.5.0",
"version": "3.5.1",
"description": "A drop-in metrics and monitoring module for node.js apps",
"repository": {
"type": "git",

View file

@ -138,21 +138,31 @@ class MetricWrapper {
}
}
if (!PromWrapper.sweepRegistered) {
let sweepingInterval
PromWrapper.setupSweeping = function() {
if (sweepingInterval) {
clearInterval(sweepingInterval)
}
if (!PromWrapper.ttlInMinutes) {
if (process.env.DEBUG_METRICS) {
console.log('Not registering sweep method -- empty ttl')
}
return
}
if (process.env.DEBUG_METRICS) {
console.log('Registering sweep method')
}
PromWrapper.sweepRegistered = true
setInterval(function() {
if (PromWrapper.ttlInMinutes) {
if (process.env.DEBUG_METRICS) {
console.log('Sweeping metrics')
}
return metrics.forEach((metric, key) => {
return metric.sweep()
})
sweepingInterval = setInterval(function() {
if (process.env.DEBUG_METRICS) {
console.log('Sweeping metrics')
}
return metrics.forEach((metric, key) => {
return metric.sweep()
})
}, 60000)
const Metrics = require('./index')
Metrics.registerDestructor(() => clearInterval(sweepingInterval))
}
module.exports = PromWrapper