mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Decaf cleanup: use default parameters
This commit is contained in:
parent
d7e4b3fe33
commit
afecfd5212
1 changed files with 12 additions and 56 deletions
|
@ -1,8 +1,3 @@
|
||||||
/*
|
|
||||||
* decaffeinate suggestions:
|
|
||||||
* DS207: Consider shorter variations of null checks
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
let Metrics
|
let Metrics
|
||||||
console.log('using prometheus')
|
console.log('using prometheus')
|
||||||
|
|
||||||
|
@ -21,10 +16,7 @@ require('./uv_threadpool_size')
|
||||||
module.exports = Metrics = {
|
module.exports = Metrics = {
|
||||||
register: prom.registry,
|
register: prom.registry,
|
||||||
|
|
||||||
initialize(_name, opts) {
|
initialize(_name, opts = {}) {
|
||||||
if (opts == null) {
|
|
||||||
opts = {}
|
|
||||||
}
|
|
||||||
appname = _name
|
appname = _name
|
||||||
collectDefaultMetrics({ timeout: 5000, prefix: Metrics.buildPromKey() })
|
collectDefaultMetrics({ timeout: 5000, prefix: Metrics.buildPromKey() })
|
||||||
if (opts.ttlInMinutes) {
|
if (opts.ttlInMinutes) {
|
||||||
|
@ -87,10 +79,7 @@ module.exports = Metrics = {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
buildPromKey(key) {
|
buildPromKey(key = '') {
|
||||||
if (key == null) {
|
|
||||||
key = ''
|
|
||||||
}
|
|
||||||
return key.replace(/[^a-zA-Z0-9]/g, '_')
|
return key.replace(/[^a-zA-Z0-9]/g, '_')
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -98,20 +87,11 @@ module.exports = Metrics = {
|
||||||
return parseFloat(value)
|
return parseFloat(value)
|
||||||
},
|
},
|
||||||
|
|
||||||
set(key, value, sampleRate) {
|
set(key, value, sampleRate = 1) {
|
||||||
if (sampleRate == null) {
|
|
||||||
sampleRate = 1
|
|
||||||
}
|
|
||||||
console.log('counts are not currently supported')
|
console.log('counts are not currently supported')
|
||||||
},
|
},
|
||||||
|
|
||||||
inc(key, sampleRate, opts) {
|
inc(key, sampleRate = 1, opts = {}) {
|
||||||
if (sampleRate == null) {
|
|
||||||
sampleRate = 1
|
|
||||||
}
|
|
||||||
if (opts == null) {
|
|
||||||
opts = {}
|
|
||||||
}
|
|
||||||
key = Metrics.buildPromKey(key)
|
key = Metrics.buildPromKey(key)
|
||||||
opts.app = appname
|
opts.app = appname
|
||||||
opts.host = hostname
|
opts.host = hostname
|
||||||
|
@ -121,13 +101,7 @@ module.exports = Metrics = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
count(key, count, sampleRate, opts) {
|
count(key, count, sampleRate = 1, opts = {}) {
|
||||||
if (sampleRate == null) {
|
|
||||||
sampleRate = 1
|
|
||||||
}
|
|
||||||
if (opts == null) {
|
|
||||||
opts = {}
|
|
||||||
}
|
|
||||||
key = Metrics.buildPromKey(key)
|
key = Metrics.buildPromKey(key)
|
||||||
opts.app = appname
|
opts.app = appname
|
||||||
opts.host = hostname
|
opts.host = hostname
|
||||||
|
@ -137,10 +111,7 @@ module.exports = Metrics = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
summary(key, value, opts) {
|
summary(key, value, opts = {}) {
|
||||||
if (opts == null) {
|
|
||||||
opts = {}
|
|
||||||
}
|
|
||||||
key = Metrics.buildPromKey(key)
|
key = Metrics.buildPromKey(key)
|
||||||
opts.app = appname
|
opts.app = appname
|
||||||
opts.host = hostname
|
opts.host = hostname
|
||||||
|
@ -150,10 +121,7 @@ module.exports = Metrics = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
timing(key, timeSpan, sampleRate, opts) {
|
timing(key, timeSpan, sampleRate, opts = {}) {
|
||||||
if (opts == null) {
|
|
||||||
opts = {}
|
|
||||||
}
|
|
||||||
key = Metrics.buildPromKey('timer_' + key)
|
key = Metrics.buildPromKey('timer_' + key)
|
||||||
opts.app = appname
|
opts.app = appname
|
||||||
opts.host = hostname
|
opts.host = hostname
|
||||||
|
@ -164,10 +132,7 @@ module.exports = Metrics = {
|
||||||
},
|
},
|
||||||
|
|
||||||
Timer: class {
|
Timer: class {
|
||||||
constructor(key, sampleRate, opts) {
|
constructor(key, sampleRate = 1, opts = {}) {
|
||||||
if (sampleRate == null) {
|
|
||||||
sampleRate = 1
|
|
||||||
}
|
|
||||||
this.start = new Date()
|
this.start = new Date()
|
||||||
key = Metrics.buildPromKey(key)
|
key = Metrics.buildPromKey(key)
|
||||||
this.key = key
|
this.key = key
|
||||||
|
@ -182,16 +147,13 @@ module.exports = Metrics = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
gauge(key, value, sampleRate, opts) {
|
gauge(key, value, sampleRate = 1, opts = {}) {
|
||||||
if (sampleRate == null) {
|
|
||||||
sampleRate = 1
|
|
||||||
}
|
|
||||||
key = Metrics.buildPromKey(key)
|
key = Metrics.buildPromKey(key)
|
||||||
prom.metric('gauge', key).set(
|
prom.metric('gauge', key).set(
|
||||||
{
|
{
|
||||||
app: appname,
|
app: appname,
|
||||||
host: hostname,
|
host: hostname,
|
||||||
status: opts != null ? opts.status : undefined
|
status: opts.status
|
||||||
},
|
},
|
||||||
this.sanitizeValue(value)
|
this.sanitizeValue(value)
|
||||||
)
|
)
|
||||||
|
@ -200,17 +162,11 @@ module.exports = Metrics = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
globalGauge(key, value, sampleRate, opts) {
|
globalGauge(key, value, sampleRate = 1, opts = {}) {
|
||||||
if (sampleRate == null) {
|
|
||||||
sampleRate = 1
|
|
||||||
}
|
|
||||||
key = Metrics.buildPromKey(key)
|
key = Metrics.buildPromKey(key)
|
||||||
prom
|
prom
|
||||||
.metric('gauge', key)
|
.metric('gauge', key)
|
||||||
.set(
|
.set({ app: appname, status: opts.status }, this.sanitizeValue(value))
|
||||||
{ app: appname, status: opts != null ? opts.status : undefined },
|
|
||||||
this.sanitizeValue(value)
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mongodb: require('./mongodb'),
|
mongodb: require('./mongodb'),
|
||||||
|
|
Loading…
Reference in a new issue