1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-19 17:52:45 +02:00

chore: add some debug statements controlled by a flag (#10532)

## About the changes
Add some **info** logs prefixed with `[etag]` so que can control them
and with this investigate the increase in traffic after the new etag
implementation.
This commit is contained in:
Gastón Fournier 2025-08-25 07:26:36 -07:00 committed by GitHub
parent 0cd64780fa
commit ac11af8c05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 12 deletions

View File

@ -147,15 +147,13 @@ export default class FeatureController extends Controller {
if (clientFeatureCaching.enabled) {
this.featuresAndSegments = memoizee(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(query: IFeatureToggleQuery, etag: string) =>
(query: IFeatureToggleQuery, _etag: string) =>
this.resolveFeaturesAndSegments(query),
{
promise: true,
maxAge: clientFeatureCaching.maxAge,
normalizer(args) {
// args is arguments object as accessible in memoized function
return args[1];
normalizer([_query, etag]) {
return etag;
},
},
);
@ -167,6 +165,11 @@ export default class FeatureController extends Controller {
private async resolveFeaturesAndSegments(
query?: IFeatureToggleQuery,
): Promise<[FeatureConfigurationClient[], IClientSegment[]]> {
if (this.flagResolver.isEnabled('debugEtag')) {
this.logger.info(
`[etag] Flags and segments cache miss for ${JSON.stringify(query)}`,
);
}
if (this.flagResolver.isEnabled('deltaApi')) {
const features =
await this.clientFeatureToggleService.getClientFeatures(query);
@ -324,10 +327,12 @@ export default class FeatureController extends Controller {
res.end();
return;
} else {
this.logger.debug(
`Provided revision: ${userVersion}, calculated revision: ${etag}`,
if (this.flagResolver.isEnabled('debugEtag')) {
this.logger.info(
`[etag] Provided revision: ${userVersion}, calculated revision: ${etag}`,
);
}
}
const [features, segments] = await this.featuresAndSegments(
query,
@ -364,6 +369,13 @@ export default class FeatureController extends Controller {
);
const queryHash = hashSum(query);
if (this.flagResolver.isEnabled('debugEtag')) {
this.logger.info(
`[etag] for query ${JSON.stringify(
query,
)} is "${queryHash}:${revisionId}" (revision id query with env ${etagByEnvEnabled ? query.environment : undefined})`,
);
}
const etagVariant = this.flagResolver.getVariant('etagVariant');
if (etagVariant.feature_enabled && etagVariant.enabled) {
const etag = `"${queryHash}:${revisionId}:${etagVariant.name}"`;

View File

@ -80,6 +80,12 @@ export default class ConfigurationRevisionService extends EventEmitter {
this.maxRevisionId[environment] = envRevisionId;
}
if (this.flagResolver.isEnabled('debugEtag')) {
this.logger.info(
`[etag] Computed ETag for environment ${environment}: ${envRevisionId} stored as "${this.maxRevisionId[environment]}"`,
);
}
return this.maxRevisionId[environment];
}
@ -92,9 +98,15 @@ export default class ConfigurationRevisionService extends EventEmitter {
this.revisionId,
);
if (this.revisionId !== revisionId) {
if (this.flagResolver.isEnabled('debugEtag')) {
this.logger.info(
`[etag] Updating feature configuration with new revision Id ${revisionId} and all envs: ${Object.keys(this.maxRevisionId).join(', ')}`,
);
} else {
this.logger.debug(
`Updating feature configuration with new revision Id ${revisionId} and all envs: ${Object.keys(this.maxRevisionId).join(', ')}`,
);
}
await Promise.allSettled(
Object.keys(this.maxRevisionId).map((environment) =>
this.updateMaxEnvironmentRevisionId(environment),

View File

@ -61,7 +61,8 @@ export type IFlagKey =
| 'addConfiguration'
| 'filterFlagsToArchive'
| 'fetchMode'
| 'etagByEnv';
| 'etagByEnv'
| 'debugEtag';
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;