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

View File

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

View File

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