Skip to content

Commit

Permalink
Health check returns HTTP status 200 even when unhealthy (#371)
Browse files Browse the repository at this point in the history
* fix: return 500 if health check result is unhealthy

* fix: allow status 500 for a successful health check result in sdk

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
tnotheis and mergify[bot] authored Feb 13, 2025
1 parent fcaca45 commit 71c93eb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/sdk/src/endpoints/Endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { ConnectorHttpResponse } from "../types/ConnectorHttpResponse";
export abstract class Endpoint {
public constructor(private readonly httpClient: AxiosInstance) {}

protected async getPlain<T>(path: string): Promise<T> {
const reponse = await this.httpClient.get<T>(path, { validateStatus: (status) => status === 200 });
protected async getPlain<T>(path: string, validateStatus?: (status: number) => boolean): Promise<T> {
const reponse = await this.httpClient.get<T>(path, { validateStatus: validateStatus ?? ((status) => status === 200) });
return reponse.data;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/endpoints/MonitoringEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Endpoint } from "./Endpoint";

export class MonitoringEndpoint extends Endpoint {
public async getHealth(): Promise<ConnectorHealth> {
return await this.getPlain("/health");
return await this.getPlain("/health", (status) => status === 200 || status === 500);
}

public async getVersion(): Promise<ConnectorVersionInfo> {
Expand Down
3 changes: 2 additions & 1 deletion src/infrastructure/httpServer/HttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ export class HttpServer extends ConnectorInfrastructure<HttpServerConfiguration>
private useHealthEndpoint() {
this.app.get("/health", async (_req: any, res: any) => {
const health = await this.runtime.getHealth();
res.status(200).json(health);
const httpStatus = health.isHealthy ? 200 : 500;
res.status(httpStatus).json(health);
});
}

Expand Down

0 comments on commit 71c93eb

Please sign in to comment.