From ac11af8c05fab4f6d11d01cead39cebd01c69931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Mon, 25 Aug 2025 07:26:36 -0700 Subject: [PATCH] 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. --- .../client-feature-toggle.controller.ts | 28 +++++++++++++------ .../configuration-revision-service.ts | 18 ++++++++++-- src/lib/types/experimental.ts | 3 +- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/lib/features/client-feature-toggles/client-feature-toggle.controller.ts b/src/lib/features/client-feature-toggles/client-feature-toggle.controller.ts index bbf8343587..7e532603cb 100644 --- a/src/lib/features/client-feature-toggles/client-feature-toggle.controller.ts +++ b/src/lib/features/client-feature-toggles/client-feature-toggle.controller.ts @@ -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,9 +327,11 @@ 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( @@ -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}"`; diff --git a/src/lib/features/feature-toggle/configuration-revision-service.ts b/src/lib/features/feature-toggle/configuration-revision-service.ts index d46e7544e7..8ffd85a576 100644 --- a/src/lib/features/feature-toggle/configuration-revision-service.ts +++ b/src/lib/features/feature-toggle/configuration-revision-service.ts @@ -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) { - this.logger.debug( - `Updating feature configuration with new revision Id ${revisionId} and all envs: ${Object.keys(this.maxRevisionId).join(', ')}`, - ); + 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), diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts index 7257b00f85..c106de9df8 100644 --- a/src/lib/types/experimental.ts +++ b/src/lib/types/experimental.ts @@ -61,7 +61,8 @@ export type IFlagKey = | 'addConfiguration' | 'filterFlagsToArchive' | 'fetchMode' - | 'etagByEnv'; + | 'etagByEnv' + | 'debugEtag'; export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;