-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feature config): add logging and availability check to feature f…
…lags the feature service got updated to check if feature flags exist in the config and therefore in the .env file setting defaults in case the values do not exist. The settings default to false.
- Loading branch information
Showing
1 changed file
with
26 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,41 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
@Injectable() | ||
export class FeatureConfigService { | ||
constructor(private configService: ConfigService) {} | ||
private readonly logger: Logger = new Logger(FeatureConfigService.name); | ||
private readonly featureFlags = { | ||
metrics: 'monitoring.metrics.enabled', | ||
healthCheck: 'monitoring.health.enabled', | ||
}; | ||
private readonly metricsEnabled: boolean | string; | ||
private readonly healthCheckEnabled: boolean | string; | ||
|
||
constructor(private configService: ConfigService) { | ||
const metrics = this.configService.get(this.featureFlags.metrics); | ||
const healthCheck = this.configService.get( | ||
this.featureFlags.healthCheck, | ||
); | ||
|
||
if (!metrics || !healthCheck) { | ||
this.logger.warn( | ||
'Metrics or health check feature flag not set. Defaulting to false.', | ||
); | ||
} | ||
|
||
this.metricsEnabled = metrics || false; | ||
this.healthCheckEnabled = healthCheck || false; | ||
} | ||
|
||
/** | ||
* This class is meant to contain all the feature flags. | ||
* There are currently no feature flags, so this class is empty. | ||
* */ | ||
isMetricsEnabled(): boolean | string { | ||
return this.configService.get('monitoring.metrics.enabled'); | ||
return this.metricsEnabled; | ||
} | ||
|
||
isHealthCheckEnabled(): boolean | string { | ||
return this.configService.get('monitoring.health.enabled'); | ||
return this.healthCheckEnabled; | ||
} | ||
} |