Skip to content

Commit bee6b9a

Browse files
authored
fix(amazonq): add jitter for validation call of profiles (#7534)
… ## Problem - to reduce # of service calls within short time duration and result in throttling error thrown - ## Solution --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent fd936e4 commit bee6b9a

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

packages/core/src/codewhisperer/region/regionProfileManager.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -285,34 +285,40 @@ export class RegionProfileManager {
285285
if (!previousSelected) {
286286
return
287287
}
288+
289+
await this.switchRegionProfile(previousSelected, 'reload')
290+
288291
// cross-validation
289-
this.getProfiles()
290-
.then(async (profiles) => {
291-
const r = profiles.find((it) => it.arn === previousSelected.arn)
292-
if (!r) {
292+
// jitter of 0 ~ 5 second
293+
const jitterInSec = Math.floor(Math.random() * 6)
294+
const jitterInMs = jitterInSec * 1000
295+
setTimeout(async () => {
296+
this.getProfiles()
297+
.then(async (profiles) => {
298+
const r = profiles.find((it) => it.arn === previousSelected.arn)
299+
if (!r) {
300+
telemetry.amazonq_profileState.emit({
301+
source: 'reload',
302+
amazonQProfileRegion: 'not-set',
303+
reason: 'profile could not be selected',
304+
result: 'Failed',
305+
})
306+
307+
await this.invalidateProfile(previousSelected.arn)
308+
RegionProfileManager.logger.warn(
309+
`invlaidating ${previousSelected.name} profile, arn=${previousSelected.arn}`
310+
)
311+
}
312+
})
313+
.catch((e) => {
293314
telemetry.amazonq_profileState.emit({
294315
source: 'reload',
295316
amazonQProfileRegion: 'not-set',
296-
reason: 'profile could not be selected',
317+
reason: (e as Error).message,
297318
result: 'Failed',
298319
})
299-
300-
await this.invalidateProfile(previousSelected.arn)
301-
RegionProfileManager.logger.warn(
302-
`invlaidating ${previousSelected.name} profile, arn=${previousSelected.arn}`
303-
)
304-
}
305-
})
306-
.catch((e) => {
307-
telemetry.amazonq_profileState.emit({
308-
source: 'reload',
309-
amazonQProfileRegion: 'not-set',
310-
reason: (e as Error).message,
311-
result: 'Failed',
312320
})
313-
})
314-
315-
await this.switchRegionProfile(previousSelected, 'reload')
321+
}, jitterInMs)
316322
}
317323

318324
private loadPersistedRegionProfle(): { [label: string]: RegionProfile } {

0 commit comments

Comments
 (0)