Skip to content

Commit

Permalink
Merge branch 'master' into 6254-liberapay
Browse files Browse the repository at this point in the history
  • Loading branch information
repo-ranger[bot] committed Mar 12, 2021
2 parents 6531230 + 9d404bc commit 0d7e9ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions core/server/influx-metrics.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'
const os = require('os')
const { promisify } = require('util')
const { post } = require('request')
const postAsync = promisify(post)
const got = require('got')
const generateInstanceId = require('./instance-id-generator')
const { promClientJsonToInfluxV2 } = require('./metrics/format-converters')
const log = require('./log')
Expand All @@ -15,21 +13,19 @@ module.exports = class InfluxMetrics {
}

async sendMetrics() {
const auth = {
user: this._config.username,
pass: this._config.password,
}
const request = {
uri: this._config.url,
url: this._config.url,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: await this.metrics(),
timeout: this._config.timeoutMillseconds,
auth,
username: this._config.username,
password: this._config.password,
throwHttpErrors: false,
}

let response
try {
response = await postAsync(request)
response = await got.post(request)
} catch (error) {
log.error(
new Error(`Cannot push metrics. Cause: ${error.name}: ${error.message}`)
Expand All @@ -38,7 +34,7 @@ module.exports = class InfluxMetrics {
if (response && response.statusCode >= 300) {
log.error(
new Error(
`Cannot push metrics. ${response.request.href} responded with status code ${response.statusCode}`
`Cannot push metrics. ${request.url} responded with status code ${response.statusCode}`
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion core/server/influx-metrics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('Influx metrics', function () {
.and(
sinon.match.has(
'message',
'Cannot push metrics. Cause: NetConnectNotAllowedError: Nock: Disallowed net connect for "shields-metrics.io:80/metrics"'
'Cannot push metrics. Cause: RequestError: Nock: Disallowed net connect for "shields-metrics.io:80/metrics"'
)
)
)
Expand Down

0 comments on commit 0d7e9ea

Please sign in to comment.