1
0
mirror of synced 2026-01-06 06:02:35 -05:00

Merge branch 'main' into repo-sync

This commit is contained in:
Octomerger Bot
2022-05-27 11:25:46 -05:00
committed by GitHub

View File

@@ -1,5 +1,8 @@
import crypto from 'crypto'
import { Agent } from 'https'
import got from 'got'
import statsd from '../lib/statsd.js'
import FailBot from '../lib/failbot.js'
@@ -12,6 +15,21 @@ const TIME_OUT_TEXT = 'ms has passed since batch creation'
// linger within the thread.
const POST_TIMEOUT_MS = 3000
let _agent
function getHttpsAgent() {
if (!_agent) {
const agentOptions = {
// The most important option. This is false by default.
keepAlive: true,
// 32 because it's what's recommended here
// https://docs.microsoft.com/en-us/azure/app-service/app-service-web-nodejs-best-practices-and-troubleshoot-guide#my-node-application-is-making-excessive-outbound-calls
maxSockets: 32,
}
_agent = new Agent(agentOptions)
}
return _agent
}
export default class Hydro {
constructor({ secret, endpoint } = {}) {
this.secret = secret || process.env.HYDRO_SECRET
@@ -51,6 +69,8 @@ export default class Hydro {
})
const token = this.generatePayloadHmac(body)
const agent = getHttpsAgent()
const doPost = () =>
got(this.endpoint, {
method: 'POST',
@@ -64,6 +84,11 @@ export default class Hydro {
throwHttpErrors: false,
// The default is no timeout.
timeout: POST_TIMEOUT_MS,
agent: {
// Deliberately not setting up a `http` or `http2` agent
// because it won't be used for this particular `got` request.
https: agent,
},
})
const res = await statsd.asyncTimer(doPost, 'hydro.response_time')()