From f20470cfa2b289293805d9ab08384b7f058ffd84 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Fri, 20 Jun 2025 13:07:39 -0700 Subject: [PATCH 1/3] fix(amazonq): remove validation call of profiles to reduce # of service calls --- .../region/regionProfileManager.ts | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/packages/core/src/codewhisperer/region/regionProfileManager.ts b/packages/core/src/codewhisperer/region/regionProfileManager.ts index a85a2133d89..227bcd75601 100644 --- a/packages/core/src/codewhisperer/region/regionProfileManager.ts +++ b/packages/core/src/codewhisperer/region/regionProfileManager.ts @@ -285,32 +285,33 @@ export class RegionProfileManager { if (!previousSelected) { return } + // Comment these out until we have a better way to deal with throttling issue, currently service can only take 1 tps // cross-validation - this.getProfiles() - .then(async (profiles) => { - const r = profiles.find((it) => it.arn === previousSelected.arn) - if (!r) { - telemetry.amazonq_profileState.emit({ - source: 'reload', - amazonQProfileRegion: 'not-set', - reason: 'profile could not be selected', - result: 'Failed', - }) - - await this.invalidateProfile(previousSelected.arn) - RegionProfileManager.logger.warn( - `invlaidating ${previousSelected.name} profile, arn=${previousSelected.arn}` - ) - } - }) - .catch((e) => { - telemetry.amazonq_profileState.emit({ - source: 'reload', - amazonQProfileRegion: 'not-set', - reason: (e as Error).message, - result: 'Failed', - }) - }) + // this.getProfiles() + // .then(async (profiles) => { + // const r = profiles.find((it) => it.arn === previousSelected.arn) + // if (!r) { + // telemetry.amazonq_profileState.emit({ + // source: 'reload', + // amazonQProfileRegion: 'not-set', + // reason: 'profile could not be selected', + // result: 'Failed', + // }) + + // await this.invalidateProfile(previousSelected.arn) + // RegionProfileManager.logger.warn( + // `invlaidating ${previousSelected.name} profile, arn=${previousSelected.arn}` + // ) + // } + // }) + // .catch((e) => { + // telemetry.amazonq_profileState.emit({ + // source: 'reload', + // amazonQProfileRegion: 'not-set', + // reason: (e as Error).message, + // result: 'Failed', + // }) + // }) await this.switchRegionProfile(previousSelected, 'reload') } From d002f66d5580831f2f37b9865fef3110e5c7bdf1 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Fri, 20 Jun 2025 13:16:14 -0700 Subject: [PATCH 2/3] patch --- .../region/regionProfileManager.ts | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/packages/core/src/codewhisperer/region/regionProfileManager.ts b/packages/core/src/codewhisperer/region/regionProfileManager.ts index 227bcd75601..b6b8d23c887 100644 --- a/packages/core/src/codewhisperer/region/regionProfileManager.ts +++ b/packages/core/src/codewhisperer/region/regionProfileManager.ts @@ -285,35 +285,39 @@ export class RegionProfileManager { if (!previousSelected) { return } - // Comment these out until we have a better way to deal with throttling issue, currently service can only take 1 tps + // cross-validation - // this.getProfiles() - // .then(async (profiles) => { - // const r = profiles.find((it) => it.arn === previousSelected.arn) - // if (!r) { - // telemetry.amazonq_profileState.emit({ - // source: 'reload', - // amazonQProfileRegion: 'not-set', - // reason: 'profile could not be selected', - // result: 'Failed', - // }) - - // await this.invalidateProfile(previousSelected.arn) - // RegionProfileManager.logger.warn( - // `invlaidating ${previousSelected.name} profile, arn=${previousSelected.arn}` - // ) - // } - // }) - // .catch((e) => { - // telemetry.amazonq_profileState.emit({ - // source: 'reload', - // amazonQProfileRegion: 'not-set', - // reason: (e as Error).message, - // result: 'Failed', - // }) - // }) - - await this.switchRegionProfile(previousSelected, 'reload') + const jitterInSec = Math.floor(Math.random() * 6) + const jitterInMs = jitterInSec * 1000 + setTimeout(async () => { + this.getProfiles() + .then(async (profiles) => { + const r = profiles.find((it) => it.arn === previousSelected.arn) + if (!r) { + telemetry.amazonq_profileState.emit({ + source: 'reload', + amazonQProfileRegion: 'not-set', + reason: 'profile could not be selected', + result: 'Failed', + }) + + await this.invalidateProfile(previousSelected.arn) + RegionProfileManager.logger.warn( + `invlaidating ${previousSelected.name} profile, arn=${previousSelected.arn}` + ) + } + }) + .catch((e) => { + telemetry.amazonq_profileState.emit({ + source: 'reload', + amazonQProfileRegion: 'not-set', + reason: (e as Error).message, + result: 'Failed', + }) + }) + + await this.switchRegionProfile(previousSelected, 'reload') + }, jitterInMs) } private loadPersistedRegionProfle(): { [label: string]: RegionProfile } { From 153c02c8becddaba29a0011daf3541aff13ace01 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Fri, 20 Jun 2025 13:19:59 -0700 Subject: [PATCH 3/3] patch --- .../core/src/codewhisperer/region/regionProfileManager.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/src/codewhisperer/region/regionProfileManager.ts b/packages/core/src/codewhisperer/region/regionProfileManager.ts index b6b8d23c887..ce33bfd925d 100644 --- a/packages/core/src/codewhisperer/region/regionProfileManager.ts +++ b/packages/core/src/codewhisperer/region/regionProfileManager.ts @@ -286,7 +286,10 @@ export class RegionProfileManager { return } + await this.switchRegionProfile(previousSelected, 'reload') + // cross-validation + // jitter of 0 ~ 5 second const jitterInSec = Math.floor(Math.random() * 6) const jitterInMs = jitterInSec * 1000 setTimeout(async () => { @@ -315,8 +318,6 @@ export class RegionProfileManager { result: 'Failed', }) }) - - await this.switchRegionProfile(previousSelected, 'reload') }, jitterInMs) }