Skip to content

Commit

Permalink
use UriToKey
Browse files Browse the repository at this point in the history
  • Loading branch information
Keegan Irby committed Nov 8, 2024
1 parent 432ecf1 commit 9b2c3a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
StartLiveTailResponseStream,
} from '@aws-sdk/client-cloudwatch-logs'
import { getLogger, ToolkitError } from '../../../shared'
import { uriToKey } from '../cloudWatchLogsUtils'

export async function tailLogGroup(
registry: LiveTailSessionRegistry,
Expand All @@ -32,11 +33,11 @@ export async function tailLogGroup(
region: wizardResponse.regionLogGroupSubmenuResponse.region,
}
const session = new LiveTailSession(liveTailSessionConfig)
if (registry.has(session.uri.toString())) {
if (registry.has(uriToKey(session.uri))) {
await prepareDocument(session)
return
}
registry.set(session.uri.toString(), session)
registry.set(uriToKey(session.uri), session)

const document = await prepareDocument(session)

Expand All @@ -49,12 +50,12 @@ export async function tailLogGroup(
}

export function closeSession(sessionUri: vscode.Uri, registry: LiveTailSessionRegistry) {
const session = registry.get(sessionUri.toString())
const session = registry.get(uriToKey(sessionUri))
if (session === undefined) {
throw new ToolkitError(`No LiveTail session found for URI: ${sessionUri.toString()}`)
}
session.stopLiveTailSession()
registry.delete(sessionUri.toString())
registry.delete(uriToKey(sessionUri))
}

export async function clearDocument(textDocument: vscode.TextDocument) {
Expand Down Expand Up @@ -102,7 +103,7 @@ async function handleSessionStream(
//AbortSignal interrupts the LiveTail stream, causing error to be thrown here.
//Can assume that stopLiveTailSession() has already been called - AbortSignal is only
//exposed through that method.
getLogger().info(`Session stopped: ${session.uri.toString()}`)
getLogger().info(`Session stopped: ${uriToKey(session.uri)}`)
} else {
//Unexpected exception.
session.stopLiveTailSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TailLogGroupWizardResponse,
} from '../../../../awsService/cloudWatchLogs/wizard/tailLogGroupWizard'
import { getTestWindow } from '../../../shared/vscode/window'
import { CloudWatchLogsSettings } from '../../../../awsService/cloudWatchLogs/cloudWatchLogsUtils'
import { CloudWatchLogsSettings, uriToKey } from '../../../../awsService/cloudWatchLogs/cloudWatchLogsUtils'
import { installFakeClock } from '../../../testUtil'

describe('TailLogGroup', function () {
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('TailLogGroup', function () {
logGroupName: testLogGroup,
region: testRegion,
})
registry.set(session.uri.toString(), session)
registry.set(uriToKey(session.uri), session)

closeSession(session.uri, registry)
assert.strictEqual(0, registry.size)
Expand Down

0 comments on commit 9b2c3a7

Please sign in to comment.