refactor(server): use a reusable http.Agent (#1644)

This commit is contained in:
Sander Bruens 2025-02-21 16:15:14 -05:00 committed by GitHub
parent 47f24520d3
commit 15a9e54e5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -102,12 +102,17 @@ export interface PrometheusClient {
}
export class ApiPrometheusClient implements PrometheusClient {
constructor(private address: string) {}
private readonly agent: http.Agent;
constructor(private address: string) {
this.agent = new http.Agent({ keepAlive: true });
}
private request(url: string): Promise<QueryResultData> {
return new Promise<QueryResultData>((fulfill, reject) => {
const options = {agent: this.agent};
http
.get(url, (response) => {
.get(url, options, (response) => {
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error(`Got error ${response.statusCode}`));
response.resume();