Skip to content

Commit

Permalink
feat(feature config): add logging and availability check to feature f…
Browse files Browse the repository at this point in the history
…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
noctua84 committed Jan 13, 2024
1 parent 7e0c0f6 commit fbcebc2
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/config/featureconfig/featureconfig.service.ts
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;
}
}

0 comments on commit fbcebc2

Please sign in to comment.