Merge remote-tracking branch 'upstream/develop' into feat/accept-status-codes-backend

# Conflicts:
#	server/src/service/infrastructure/network/HttpProvider.ts
This commit is contained in:
harsh-aghara committed 2026-06-05 00:58:35 +05:30
commit d2c13fac5a
34 files changed
+1887 -540

No files matched your search

@@ -4,6 +4,7 @@ import { IStatusProvider } from "@/service/infrastructure/network/IStatusProvide
import { HttpStatusPayload } from "@/types/network.js";
import { MonitorStatusResponse } from "@/types/network.js";
import { Agent as HttpsAgent } from "https";
import { Agent as HttpAgent } from "http";
import { Monitor, MonitorType } from "@/types/monitor.js";
import { NETWORK_ERROR, isStatusUp } from "@/service/infrastructure/network/utils.js";
import CacheableLookup from "cacheable-lookup";
@@ -11,6 +12,11 @@ import CacheableLookup from "cacheable-lookup";
export class HttpProvider implements IStatusProvider<HttpStatusPayload> {
readonly type = "http";
// Shared, pooled agents reused across every check
private readonly httpAgent: HttpAgent;
private readonly httpsAgent: HttpsAgent;
private readonly httpsAgentInsecure: HttpsAgent;
constructor(
private got: Got,
private advancedMatcher: IAdvancedMatcher
@@ -23,6 +29,11 @@ export class HttpProvider implements IStatusProvider<HttpStatusPayload> {
},
retry: { limit: 1 },
});
const agentOptions = { keepAlive: true, maxSockets: 256, maxFreeSockets: 256 };
this.httpAgent = new HttpAgent(agentOptions);
this.httpsAgent = new HttpsAgent({ ...agentOptions, rejectUnauthorized: true });
this.httpsAgentInsecure = new HttpsAgent({ ...agentOptions, rejectUnauthorized: false });
}
supports(type: MonitorType) {
@@ -33,7 +44,7 @@ export class HttpProvider implements IStatusProvider<HttpStatusPayload> {
if (error instanceof HTTPError || error instanceof RequestError) {
const statusCode = error.response?.statusCode;
const statusUp = isStatusUp(statusCode, monitor.customUpCodes);
const responseTime = error.timings?.phases?.total ?? 0;
const responseTime = error.timings?.phases?.firstByte ?? error.timings?.phases?.total ?? 0;
if (!statusUp) {
return {
@@ -119,7 +130,8 @@ export class HttpProvider implements IStatusProvider<HttpStatusPayload> {
};
options.agent = {
https: new HttpsAgent({ rejectUnauthorized: !ignoreTlsErrors }),
http: this.httpAgent,
https: ignoreTlsErrors ? this.httpsAgentInsecure : this.httpsAgent,
};
try {
@@ -135,7 +147,7 @@ export class HttpProvider implements IStatusProvider<HttpStatusPayload> {
status: false,
code: response.statusCode,
message: "Response is not JSON",
responseTime: response.timings.phases.total ?? 0,
responseTime: response.timings.phases.firstByte ?? 0,
timings: response.timings,
payload: response.body as unknown as T,
};
@@ -161,7 +173,7 @@ export class HttpProvider implements IStatusProvider<HttpStatusPayload> {
status: statusUp && matchResult.ok,
code: response.statusCode,
message: matchResult.ok ? (response.statusMessage ?? "OK") : matchResult.message,
responseTime: response.timings.phases.total ?? 0,
responseTime: response.timings.phases.firstByte ?? 0,
timings: response.timings,
payload,
extracted: matchResult.extracted,