Browse Source

Feature/refactor health check endpoints (#5005)

* Refactor health check endpoints

* Update changelog
pull/4999/head^2
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
be3a9b8e83
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      CHANGELOG.md
  2. 40
      apps/api/src/app/health/health.controller.ts
  3. 4
      libs/common/src/lib/interfaces/index.ts
  4. 3
      libs/common/src/lib/interfaces/responses/data-enhancer-health-response.interface.ts
  5. 3
      libs/common/src/lib/interfaces/responses/data-provider-health-response.interface.ts

2
CHANGELOG.md

@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Migrated the `@ghostfolio/ui/value` component to control flow - Migrated the `@ghostfolio/ui/value` component to control flow
- Refactored the health check endpoint for data enhancers
- Refactored the health check endpoint for data providers
## 2.173.0 - 2025-06-21 ## 2.173.0 - 2025-06-21

40
apps/api/src/app/health/health.controller.ts

@ -1,4 +1,8 @@
import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.interceptor'; import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.interceptor';
import {
DataEnhancerHealthResponse,
DataProviderHealthResponse
} from '@ghostfolio/common/interfaces';
import { import {
Controller, Controller,
@ -37,23 +41,30 @@ export class HealthController {
} }
@Get('data-enhancer/:name') @Get('data-enhancer/:name')
public async getHealthOfDataEnhancer(@Param('name') name: string) { public async getHealthOfDataEnhancer(
@Param('name') name: string,
@Res() response: Response
): Promise<Response<DataEnhancerHealthResponse>> {
const hasResponse = const hasResponse =
await this.healthService.hasResponseFromDataEnhancer(name); await this.healthService.hasResponseFromDataEnhancer(name);
if (hasResponse !== true) { if (hasResponse) {
throw new HttpException( return response.status(HttpStatus.OK).json({
getReasonPhrase(StatusCodes.SERVICE_UNAVAILABLE), status: getReasonPhrase(StatusCodes.OK)
StatusCodes.SERVICE_UNAVAILABLE });
); } else {
return response
.status(HttpStatus.SERVICE_UNAVAILABLE)
.json({ status: getReasonPhrase(StatusCodes.SERVICE_UNAVAILABLE) });
} }
} }
@Get('data-provider/:dataSource') @Get('data-provider/:dataSource')
@UseInterceptors(TransformDataSourceInRequestInterceptor) @UseInterceptors(TransformDataSourceInRequestInterceptor)
public async getHealthOfDataProvider( public async getHealthOfDataProvider(
@Param('dataSource') dataSource: DataSource @Param('dataSource') dataSource: DataSource,
) { @Res() response: Response
): Promise<Response<DataProviderHealthResponse>> {
if (!DataSource[dataSource]) { if (!DataSource[dataSource]) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.NOT_FOUND), getReasonPhrase(StatusCodes.NOT_FOUND),
@ -64,11 +75,14 @@ export class HealthController {
const hasResponse = const hasResponse =
await this.healthService.hasResponseFromDataProvider(dataSource); await this.healthService.hasResponseFromDataProvider(dataSource);
if (hasResponse !== true) { if (hasResponse) {
throw new HttpException( return response
getReasonPhrase(StatusCodes.SERVICE_UNAVAILABLE), .status(HttpStatus.OK)
StatusCodes.SERVICE_UNAVAILABLE .json({ status: getReasonPhrase(StatusCodes.OK) });
); } else {
return response
.status(HttpStatus.SERVICE_UNAVAILABLE)
.json({ status: getReasonPhrase(StatusCodes.SERVICE_UNAVAILABLE) });
} }
} }
} }

4
libs/common/src/lib/interfaces/index.ts

@ -41,8 +41,10 @@ import type { AccountsResponse } from './responses/accounts-response.interface';
import type { AiPromptResponse } from './responses/ai-prompt-response.interface'; import type { AiPromptResponse } from './responses/ai-prompt-response.interface';
import type { ApiKeyResponse } from './responses/api-key-response.interface'; import type { ApiKeyResponse } from './responses/api-key-response.interface';
import type { BenchmarkResponse } from './responses/benchmark-response.interface'; import type { BenchmarkResponse } from './responses/benchmark-response.interface';
import type { DataEnhancerHealthResponse } from './responses/data-enhancer-health-response.interface';
import type { DataProviderGhostfolioAssetProfileResponse } from './responses/data-provider-ghostfolio-asset-profile-response.interface'; import type { DataProviderGhostfolioAssetProfileResponse } from './responses/data-provider-ghostfolio-asset-profile-response.interface';
import type { DataProviderGhostfolioStatusResponse } from './responses/data-provider-ghostfolio-status-response.interface'; import type { DataProviderGhostfolioStatusResponse } from './responses/data-provider-ghostfolio-status-response.interface';
import type { DataProviderHealthResponse } from './responses/data-provider-health-response.interface';
import type { DividendsResponse } from './responses/dividends-response.interface'; import type { DividendsResponse } from './responses/dividends-response.interface';
import type { ResponseError } from './responses/errors.interface'; import type { ResponseError } from './responses/errors.interface';
import type { HistoricalResponse } from './responses/historical-response.interface'; import type { HistoricalResponse } from './responses/historical-response.interface';
@ -88,8 +90,10 @@ export {
BenchmarkProperty, BenchmarkProperty,
BenchmarkResponse, BenchmarkResponse,
Coupon, Coupon,
DataEnhancerHealthResponse,
DataProviderGhostfolioAssetProfileResponse, DataProviderGhostfolioAssetProfileResponse,
DataProviderGhostfolioStatusResponse, DataProviderGhostfolioStatusResponse,
DataProviderHealthResponse,
DataProviderInfo, DataProviderInfo,
DividendsResponse, DividendsResponse,
EnhancedSymbolProfile, EnhancedSymbolProfile,

3
libs/common/src/lib/interfaces/responses/data-enhancer-health-response.interface.ts

@ -0,0 +1,3 @@
export interface DataEnhancerHealthResponse {
status: string;
}

3
libs/common/src/lib/interfaces/responses/data-provider-health-response.interface.ts

@ -0,0 +1,3 @@
export interface DataProviderHealthResponse {
status: string;
}
Loading…
Cancel
Save