Skip to content

Commit 1a8ebbc

Browse files
authored
fix(cloudwatch): "Search Log Group" shows multiple progress popups #3788
Problem: When entering filter pattern for the "Search Log Group" action, the validation action does its own mini-search, before the actual search is done. The user sees multiple popups, which feels clunky. Solution: Ignore query parameters when calculating the message "id".
1 parent adf3dfe commit 1a8ebbc

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "CloudWatch Logs: \"Search Log Group\" shows multiple progress popups"
4+
}

src/cloudWatchLogs/cloudWatchLogsUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ export function uriToKey(uri: vscode.Uri): string {
4545
return uri.path
4646
}
4747

48+
/**
49+
* Creates a message key from region + loggroup + logstream.
50+
*
51+
* Intentionally _ignores_ query parameters, so that the validation step can use the same progress
52+
* message as the actual log group search. That results in a more fluid UX.
53+
*/
54+
export function msgKey(logGroupInfo: CloudWatchLogsGroupInfo): string {
55+
const uri = createURIFromArgs(logGroupInfo, {})
56+
return uri.toString()
57+
}
58+
4859
/**
4960
* Destructures an awsCloudWatchLogs URI into its component pieces.
5061
* @param uri URI for a Cloudwatch Logs file

src/cloudWatchLogs/commands/searchLogGroup.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from '../registry/logDataRegistry'
1717
import { DataQuickPickItem } from '../../shared/ui/pickerPrompter'
1818
import { isValidResponse, isWizardControl, Wizard, WIZARD_RETRY } from '../../shared/wizards/wizard'
19-
import { createURIFromArgs, parseCloudWatchLogsUri, recordTelemetryFilter } from '../cloudWatchLogsUtils'
19+
import { createURIFromArgs, msgKey, parseCloudWatchLogsUri, recordTelemetryFilter } from '../cloudWatchLogsUtils'
2020
import { DefaultCloudWatchLogsClient } from '../../shared/clients/cloudWatchLogsClient'
2121
import { CancellationError } from '../../shared/utilities/timeoutUtils'
2222
import { getLogger } from '../../shared/logger'
@@ -28,6 +28,7 @@ import { truncate } from '../../shared/utilities/textUtilities'
2828
import { createBackButton, createExitButton, createHelpButton } from '../../shared/ui/buttons'
2929
import { PromptResult } from '../../shared/ui/prompter'
3030
import { ToolkitError } from '../../shared/errors'
31+
import { Messages } from '../../shared/utilities/messages'
3132

3233
const localize = nls.loadMessageBundle()
3334

@@ -192,9 +193,13 @@ export class SearchPatternPrompter extends InputBoxPrompter {
192193
limit: 1,
193194
},
194195
undefined,
195-
true
196+
false
196197
)
197198
} catch (e) {
199+
// Validation error. Get the progress message from the global map and cancel it.
200+
const msgTimeout = await Messages.putMessage(msgKey(this.logGroup), '')
201+
msgTimeout.cancel()
202+
198203
return (e as Error).message
199204
}
200205
return undefined

src/cloudWatchLogs/registry/logDataRegistry.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from 'vscode'
77
import { CloudWatchLogs } from 'aws-sdk'
8-
import { CloudWatchLogsSettings, parseCloudWatchLogsUri, uriToKey, createURIFromArgs } from '../cloudWatchLogsUtils'
8+
import { CloudWatchLogsSettings, parseCloudWatchLogsUri, uriToKey, msgKey } from '../cloudWatchLogsUtils'
99
import { DefaultCloudWatchLogsClient } from '../../shared/clients/cloudWatchLogsClient'
1010
import { waitTimeout } from '../../shared/utilities/timeoutUtils'
1111
import { Messages } from '../../shared/utilities/messages'
@@ -78,9 +78,13 @@ export class LogDataRegistry {
7878
// We are at the earliest data and trying to go back in time, there is nothing to see.
7979
// If we don't return now, redundant data will be retrieved.
8080
if (isHead && logData.previous?.token === undefined) {
81-
const msgId = uriToKey(uri)
8281
// show something so the user doesn't think nothing happened.
83-
await Messages.putMessage(msgId, `Loading from: '${logData.logGroupInfo.groupName}'`, undefined, 500)
82+
await Messages.putMessage(
83+
msgKey(logData.logGroupInfo),
84+
`Loading from: '${logData.logGroupInfo.groupName}'`,
85+
undefined,
86+
500
87+
)
8488
return []
8589
}
8690

@@ -108,8 +112,10 @@ export class LogDataRegistry {
108112
return last
109113
}
110114

111-
const msgId = uriToKey(uri)
112-
const msgTimeout = await Messages.putMessage(msgId, `Loading from: '${logData.logGroupInfo.groupName}'`)
115+
const msgTimeout = await Messages.putMessage(
116+
msgKey(logData.logGroupInfo),
117+
`Loading from: '${logData.logGroupInfo.groupName}'`
118+
)
113119
const responseData = await firstOrLast(stream, resp => resp.events.length > 0).finally(() => {
114120
msgTimeout.dispose()
115121
})
@@ -232,8 +238,7 @@ export async function filterLogEventsFromUri(
232238
delete cwlParameters.logStreamNames
233239
}
234240

235-
const msgId = uriToKey(createURIFromArgs(logGroupInfo, parameters))
236-
const msgTimeout = await Messages.putMessage(msgId, `Loading from: '${logGroupInfo.groupName}'`, {
241+
const msgTimeout = await Messages.putMessage(msgKey(logGroupInfo), `Loading from: '${logGroupInfo.groupName}'`, {
237242
message: logGroupInfo.streamName ?? '',
238243
})
239244

0 commit comments

Comments
 (0)