Skip to content

Commit

Permalink
refactor(server): use a reusable http.Agent (#1644)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens authored Feb 21, 2025
1 parent 47f2452 commit 15a9e54
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/shadowbox/infrastructure/prometheus_scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 15a9e54

Please sign in to comment.