Build(deps): bump prom-client from 11.5.3 to 13.0.0 (#5962)

* Build(deps): bump prom-client from 11.5.3 to 13.0.0

Bumps [prom-client](https://github.com/siimon/prom-client) from 11.5.3 to 13.0.0.
- [Release notes](https://github.com/siimon/prom-client/releases)
- [Changelog](https://github.com/siimon/prom-client/blob/master/CHANGELOG.md)
- [Commits](https://github.com/siimon/prom-client/compare/v11.5.3...v13.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* deps: apply updates for prom version bump

* register.getMetricsAsJSON is async now

* PrometheusMetrics#metrics is async

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Caleb Cartwright <caleb.cartwright@outlook.com>
Co-authored-by: Marcin Mielnicki <marcin.mielnicki@gmail.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
dependabot-preview[bot]
2020-12-23 23:32:08 +00:00
committed by GitHub
parent 6ccd24815f
commit e202b73c3c
8 changed files with 47 additions and 45 deletions

View File

@@ -519,7 +519,7 @@ describe('BaseService', function () {
await serviceInstance._request({ url })
expect(register.getSingleMetricAsString('service_response_bytes'))
expect(await register.getSingleMetricAsString('service_response_bytes'))
.to.contain(
'service_response_bytes_bucket{le="65536",category="other",family="undefined",service="dummy_service_with_service_response_size_metric_enabled"} 0\n'
)
@@ -545,7 +545,7 @@ describe('BaseService', function () {
await serviceInstance._request({ url })
expect(
register.getSingleMetricAsString('service_response_bytes')
await register.getSingleMetricAsString('service_response_bytes')
).to.not.contain('service_response_bytes_bucket')
})
})

View File

@@ -22,7 +22,7 @@ module.exports = class InfluxMetrics {
const request = {
uri: this._config.url,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: this.metrics(),
body: await this.metrics(),
timeout: this._config.timeoutMillseconds,
auth,
}
@@ -51,8 +51,8 @@ module.exports = class InfluxMetrics {
)
}
metrics() {
return promClientJsonToInfluxV2(this._metricInstance.metrics(), {
async metrics() {
return promClientJsonToInfluxV2(await this._metricInstance.metrics(), {
env: this._config.envLabel,
application: 'shields',
instance: this._instanceId,

View File

@@ -36,7 +36,7 @@ describe('Influx metrics', function () {
instanceIdEnvVarName: 'INSTANCE_ID',
})
expect(influxMetrics.metrics()).to.contain('instance=instance3')
expect(await influxMetrics.metrics()).to.contain('instance=instance3')
})
it('should use a hostname as an instance label', async function () {
@@ -46,7 +46,9 @@ describe('Influx metrics', function () {
}
const influxMetrics = new InfluxMetrics(metricInstance, customConfig)
expect(influxMetrics.metrics()).to.be.contain('instance=test-hostname')
expect(await influxMetrics.metrics()).to.be.contain(
'instance=test-hostname'
)
})
it('should use a random string as an instance label', async function () {
@@ -55,7 +57,7 @@ describe('Influx metrics', function () {
}
const influxMetrics = new InfluxMetrics(metricInstance, customConfig)
expect(influxMetrics.metrics()).to.be.match(/instance=\w+ /)
expect(await influxMetrics.metrics()).to.be.match(/instance=\w+ /)
})
it('should use a hostname alias as an instance label', async function () {
@@ -66,7 +68,7 @@ describe('Influx metrics', function () {
}
const influxMetrics = new InfluxMetrics(metricInstance, customConfig)
expect(influxMetrics.metrics()).to.be.contain(
expect(await influxMetrics.metrics()).to.be.contain(
'instance=test-hostname-alias'
)
})

View File

@@ -2,26 +2,26 @@
const groupBy = require('lodash.groupby')
function promClientJsonToInfluxV2(metrics, extraLabels = {}) {
// TODO Replace with Array.prototype.flatMap() after migrating to Node.js >= 11
const flatMap = (f, arr) => arr.reduce((acc, x) => acc.concat(f(x)), [])
return flatMap(metric => {
const valuesByLabels = groupBy(metric.values, value =>
JSON.stringify(Object.entries(value.labels).sort())
)
return Object.values(valuesByLabels).map(metricsWithSameLabel => {
const labels = Object.entries(metricsWithSameLabel[0].labels)
.concat(Object.entries(extraLabels))
.sort((a, b) => a[0].localeCompare(b[0]))
.map(labelEntry => `${labelEntry[0]}=${labelEntry[1]}`)
.join(',')
const labelsFormatted = labels ? `,${labels}` : ''
const values = metricsWithSameLabel
.sort((a, b) => a.metricName.localeCompare(b.metricName))
.map(value => `${value.metricName || metric.name}=${value.value}`)
.join(',')
return `prometheus${labelsFormatted} ${values}`
})
}, metrics).join('\n')
return metrics
.flatMap(metric => {
const valuesByLabels = groupBy(metric.values, value =>
JSON.stringify(Object.entries(value.labels).sort())
)
return Object.values(valuesByLabels).map(metricsWithSameLabel => {
const labels = Object.entries(metricsWithSameLabel[0].labels)
.concat(Object.entries(extraLabels))
.sort((a, b) => a[0].localeCompare(b[0]))
.map(labelEntry => `${labelEntry[0]}=${labelEntry[1]}`)
.join(',')
const labelsFormatted = labels ? `,${labels}` : ''
const values = metricsWithSameLabel
.sort((a, b) => a.metricName.localeCompare(b.metricName))
.map(value => `${value.metricName || metric.name}=${value.value}`)
.join(',')
return `prometheus${labelsFormatted} ${values}`
})
}, metrics)
.join('\n')
}
module.exports = { promClientJsonToInfluxV2 }

View File

@@ -22,7 +22,7 @@ describe('Metric format converters', function () {
expect(influx).to.be.equal('prometheus counter1=11')
})
it('converts a counter (from prometheus registry)', function () {
it('converts a counter (from prometheus registry)', async function () {
const register = new prometheus.Registry()
const counter = new prometheus.Counter({
name: 'counter1',
@@ -31,7 +31,7 @@ describe('Metric format converters', function () {
})
counter.inc(11)
const influx = promClientJsonToInfluxV2(register.getMetricsAsJSON())
const influx = promClientJsonToInfluxV2(await register.getMetricsAsJSON())
expect(influx).to.be.equal('prometheus counter1=11')
})
@@ -52,7 +52,7 @@ describe('Metric format converters', function () {
expect(influx).to.be.equal('prometheus gauge1=20')
})
it('converts a gauge (from prometheus registry)', function () {
it('converts a gauge (from prometheus registry)', async function () {
const register = new prometheus.Registry()
const gauge = new prometheus.Gauge({
name: 'gauge1',
@@ -61,7 +61,7 @@ describe('Metric format converters', function () {
})
gauge.inc(20)
const influx = promClientJsonToInfluxV2(register.getMetricsAsJSON())
const influx = promClientJsonToInfluxV2(await register.getMetricsAsJSON())
expect(influx).to.be.equal('prometheus gauge1=20')
})
@@ -101,7 +101,7 @@ prometheus histogram1_count=3,histogram1_sum=111`)
)
})
it('converts a histogram (from prometheus registry)', function () {
it('converts a histogram (from prometheus registry)', async function () {
const register = new prometheus.Registry()
const histogram = new prometheus.Histogram({
name: 'histogram1',
@@ -113,7 +113,7 @@ prometheus histogram1_count=3,histogram1_sum=111`)
histogram.observe(10)
histogram.observe(1)
const influx = promClientJsonToInfluxV2(register.getMetricsAsJSON())
const influx = promClientJsonToInfluxV2(await register.getMetricsAsJSON())
expect(sortLines(influx)).to.be.equal(
sortLines(`prometheus,le=+Inf histogram1_bucket=3
@@ -151,7 +151,7 @@ prometheus summary1_count=3,summary1_sum=111`)
)
})
it('converts a summary (from prometheus registry)', function () {
it('converts a summary (from prometheus registry)', async function () {
const register = new prometheus.Registry()
const summary = new prometheus.Summary({
name: 'summary1',
@@ -163,7 +163,7 @@ prometheus summary1_count=3,summary1_sum=111`)
summary.observe(10)
summary.observe(1)
const influx = promClientJsonToInfluxV2(register.getMetricsAsJSON())
const influx = promClientJsonToInfluxV2(await register.getMetricsAsJSON())
expect(sortLines(influx)).to.be.equal(
sortLines(`prometheus,quantile=0.99 summary1=100

View File

@@ -76,9 +76,9 @@ module.exports = class PrometheusMetrics {
async registerMetricsEndpoint(server) {
const { register } = this
server.route(/^\/metrics$/, (data, match, end, ask) => {
server.route(/^\/metrics$/, async (data, match, end, ask) => {
ask.res.setHeader('Content-Type', register.contentType)
ask.res.end(register.metrics())
ask.res.end(await register.metrics())
})
}
@@ -90,8 +90,8 @@ module.exports = class PrometheusMetrics {
}
}
metrics() {
return this.register.getMetricsAsJSON()
async metrics() {
return await this.register.getMetricsAsJSON()
}
/**

6
package-lock.json generated
View File

@@ -29310,9 +29310,9 @@
"dev": true
},
"prom-client": {
"version": "11.5.3",
"resolved": "https://registry.npmjs.org/prom-client/-/prom-client-11.5.3.tgz",
"integrity": "sha512-iz22FmTbtkyL2vt0MdDFY+kWof+S9UB/NACxSn2aJcewtw+EERsen0urSkZ2WrHseNdydsvcxCTAnPcSMZZv4Q==",
"version": "13.0.0",
"resolved": "https://registry.npmjs.org/prom-client/-/prom-client-13.0.0.tgz",
"integrity": "sha512-M7ZNjIO6x+2R/vjSD13yjJPjpoZA8eEwH2Bp2Re0/PvzozD7azikv+SaBtZes4Q1ca/xHjZ4RSCuTag3YZLg1A==",
"requires": {
"tdigest": "^0.1.1"
}

View File

@@ -53,7 +53,7 @@
"path-to-regexp": "^6.2.0",
"pretty-bytes": "^5.4.1",
"priorityqueuejs": "^2.0.0",
"prom-client": "^11.5.3",
"prom-client": "^13.0.0",
"query-string": "^6.13.7",
"request": "~2.88.2",
"semver": "~7.3.4",