Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"generateNonCodeFiles": "npm run generateNonCodeFiles -w packages/ --if-present"
},
"devDependencies": {
"@aws-toolkits/telemetry": "^1.0.282",
"@aws-toolkits/telemetry": "^1.0.284",
"@playwright/browser-chromium": "^1.43.1",
"@types/he": "^1.2.3",
"@types/vscode": "^1.68.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/awsService/cloudWatchLogs/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ export async function activate(context: vscode.ExtensionContext, configuration:
node instanceof LogGroupNode
? { regionName: node.regionCode, groupName: node.logGroup.logGroupName! }
: undefined
await tailLogGroup(liveTailRegistry, logGroupInfo)
const source = node ? (logGroupInfo ? 'ExplorerLogGroupNode' : 'ExplorerServiceNode') : 'Command'
await tailLogGroup(liveTailRegistry, source, logGroupInfo)
}),

Commands.register('aws.cwl.stopTailingLogGroup', async (document: vscode.TextDocument) => {
closeSession(document.uri, liveTailRegistry)
Commands.register('aws.cwl.stopTailingLogGroup', async (document: vscode.TextDocument, source: string) => {
closeSession(document.uri, liveTailRegistry, source)
}),

Commands.register('aws.cwl.clearDocument', async (document: vscode.TextDocument) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import * as vscode from 'vscode'
import { telemetry } from '../../../shared/telemetry/telemetry'
import { TailLogGroupWizard } from '../wizard/tailLogGroupWizard'
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
import { LiveTailSession, LiveTailSessionConfiguration } from '../registry/liveTailSession'
Expand All @@ -18,48 +19,70 @@ import { uriToKey } from '../cloudWatchLogsUtils'

export async function tailLogGroup(
registry: LiveTailSessionRegistry,
source: string,
logData?: { regionName: string; groupName: string }
): Promise<void> {
const wizard = new TailLogGroupWizard(logData)
const wizardResponse = await wizard.run()
if (!wizardResponse) {
throw new CancellationError('user')
}
const awsCredentials = await globals.awsContext.getCredentials()
if (awsCredentials === undefined) {
throw new ToolkitError('Failed to start LiveTail session: credentials are undefined.')
}
const liveTailSessionConfig: LiveTailSessionConfiguration = {
logGroupArn: wizardResponse.regionLogGroupSubmenuResponse.data,
logStreamFilter: wizardResponse.logStreamFilter,
logEventFilterPattern: wizardResponse.filterPattern,
region: wizardResponse.regionLogGroupSubmenuResponse.region,
awsCredentials: awsCredentials,
}
const session = new LiveTailSession(liveTailSessionConfig)
if (registry.has(uriToKey(session.uri))) {
await prepareDocument(session)
return
}
registry.set(uriToKey(session.uri), session)
await telemetry.cwlLiveTail_Start.run(async (span) => {
const wizard = new TailLogGroupWizard(logData)
const wizardResponse = await wizard.run()
if (!wizardResponse) {
throw new CancellationError('user')
}
const awsCredentials = await globals.awsContext.getCredentials()
if (awsCredentials === undefined) {
throw new ToolkitError('Failed to start LiveTail session: credentials are undefined.')
}
const liveTailSessionConfig: LiveTailSessionConfiguration = {
logGroupArn: wizardResponse.regionLogGroupSubmenuResponse.data,
logStreamFilter: wizardResponse.logStreamFilter,
logEventFilterPattern: wizardResponse.filterPattern,
region: wizardResponse.regionLogGroupSubmenuResponse.region,
awsCredentials: awsCredentials,
}
const session = new LiveTailSession(liveTailSessionConfig)
if (registry.has(uriToKey(session.uri))) {
await prepareDocument(session)
span.record({
result: 'Succeeded',
sessionAlreadyStarted: true,
source: source,
})
return
}

const document = await prepareDocument(session)
registry.set(uriToKey(session.uri), session)

hideShowStatusBarItemsOnActiveEditor(session, document)
registerTabChangeCallback(session, registry, document)
const document = await prepareDocument(session)

const stream = await session.startLiveTailSession()
hideShowStatusBarItemsOnActiveEditor(session, document)
registerTabChangeCallback(session, registry, document)

await handleSessionStream(stream, document, session)
const stream = await session.startLiveTailSession()
span.record({
source: source,
result: 'Succeeded',
sessionAlreadyStarted: false,
hasLogEventFilterPattern: Boolean(wizardResponse.filterPattern),
logStreamFilterType: wizardResponse.logStreamFilter.type,
})
await handleSessionStream(stream, document, session)
})
}

export function closeSession(sessionUri: vscode.Uri, registry: LiveTailSessionRegistry) {
const session = registry.get(uriToKey(sessionUri))
if (session === undefined) {
throw new ToolkitError(`No LiveTail session found for URI: ${sessionUri.toString()}`)
}
session.stopLiveTailSession()
registry.delete(uriToKey(sessionUri))
export function closeSession(sessionUri: vscode.Uri, registry: LiveTailSessionRegistry, source: string) {
telemetry.cwlLiveTail_Stop.run((span) => {
const session = registry.get(uriToKey(sessionUri))
if (session === undefined) {
throw new ToolkitError(`No LiveTail session found for URI: ${sessionUri.toString()}`)
}
session.stopLiveTailSession()
registry.delete(uriToKey(sessionUri))
span.record({
result: 'Succeeded',
source: source,
duration: session.getLiveTailSessionDuration(),
})
})
}

export async function clearDocument(textDocument: vscode.TextDocument) {
Expand Down Expand Up @@ -215,7 +238,7 @@ function registerTabChangeCallback(
vscode.window.tabGroups.onDidChangeTabs((tabEvent) => {
const isOpen = isLiveTailSessionOpenInAnyTab(session)
if (!isOpen) {
closeSession(session.uri, registry)
closeSession(session.uri, registry, 'ClosedEditors')
void clearDocument(document)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class LiveTailCodeLensProvider implements vscode.CodeLensProvider {
const command: vscode.Command = {
title: 'Stop tailing',
command: 'aws.cwl.stopTailingLogGroup',
arguments: [document],
arguments: [document, 'codeLens'],
}
return new vscode.CodeLens(range, command)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('TailLogGroup', function () {
const testRegion = 'test-region'
const testMessage = 'test-message'
const testAwsAccountId = '1234'
const testSource = 'test-source'
const testAwsCredentials = {} as any as AWS.Credentials

let sandbox: sinon.SinonSandbox
Expand Down Expand Up @@ -93,7 +94,7 @@ describe('TailLogGroup', function () {
cloudwatchSettingsSpy = sandbox.stub(CloudWatchLogsSettings.prototype, 'get').callsFake(() => {
return 1
})
await tailLogGroup(registry, {
await tailLogGroup(registry, testSource, {
groupName: testLogGroup,
regionName: testRegion,
})
Expand Down Expand Up @@ -131,7 +132,7 @@ describe('TailLogGroup', function () {
return getTestWizardResponse()
})
await assert.rejects(async () => {
await tailLogGroup(registry, {
await tailLogGroup(registry, testSource, {
groupName: testLogGroup,
regionName: testRegion,
})
Expand All @@ -152,7 +153,7 @@ describe('TailLogGroup', function () {
})
registry.set(uriToKey(session.uri), session)

closeSession(session.uri, registry)
closeSession(session.uri, registry, testSource)
assert.strictEqual(0, registry.size)
assert.strictEqual(true, stopLiveTailSessionSpy.calledOnce)
assert.strictEqual(0, clock.countTimers())
Expand Down
Loading