Skip to content

Commit 15a9e54

Browse files
authored
refactor(server): use a reusable http.Agent (#1644)
1 parent 47f2452 commit 15a9e54

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/shadowbox/infrastructure/prometheus_scraper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,17 @@ export interface PrometheusClient {
102102
}
103103

104104
export class ApiPrometheusClient implements PrometheusClient {
105-
constructor(private address: string) {}
105+
private readonly agent: http.Agent;
106+
107+
constructor(private address: string) {
108+
this.agent = new http.Agent({ keepAlive: true });
109+
}
106110

107111
private request(url: string): Promise<QueryResultData> {
108112
return new Promise<QueryResultData>((fulfill, reject) => {
113+
const options = {agent: this.agent};
109114
http
110-
.get(url, (response) => {
115+
.get(url, options, (response) => {
111116
if (response.statusCode < 200 || response.statusCode > 299) {
112117
reject(new Error(`Got error ${response.statusCode}`));
113118
response.resume();

0 commit comments

Comments
 (0)