Skip to content

Commit d56a8ac

Browse files
authored
fix(cwl): set LogEventFilter when constructing LiveTailSession #6008
## Problem LogEventFilter is an optional configuration parameter when building a LiveTailSession. Currently, the Constructor is not actually setting this property so it is always undefined. This means that if a user sets a Filter pattern, it will not be applied. ## Solution Set the property in LiveTailSession Constructor. Add missing unit tests to validate that LiveTailSession config values are set properly. Testing via `buildStartLiveTailCommand` because this is what actually gets sent to the CWL backend to start a LiveTailSession.
1 parent 8f6ca43 commit d56a8ac

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

packages/core/src/awsService/cloudWatchLogs/registry/liveTailSession.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import {
1111
} from '@aws-sdk/client-cloudwatch-logs'
1212
import { LogStreamFilterResponse } from '../wizard/liveTailLogStreamSubmenu'
1313
import { CloudWatchLogsSettings, uriToKey } from '../cloudWatchLogsUtils'
14-
import { convertToTimeString, getLogger, globals, Settings, ToolkitError } from '../../../shared'
14+
import { getLogger, globals, Settings, ToolkitError } from '../../../shared'
1515
import { createLiveTailURIFromArgs } from './liveTailSessionRegistry'
1616
import { getUserAgent } from '../../../shared/telemetry/util'
17+
import { convertToTimeString } from '../../../shared/datetime'
1718

1819
export type LiveTailSessionConfiguration = {
1920
logGroupArn: string
@@ -49,6 +50,7 @@ export class LiveTailSession {
4950
public constructor(configuration: LiveTailSessionConfiguration) {
5051
this._logGroupArn = configuration.logGroupArn
5152
this.logStreamFilter = configuration.logStreamFilter
53+
this.logEventFilterPattern = configuration.logEventFilterPattern
5254
this.liveTailClient = {
5355
cwlClient: new CloudWatchLogsClient({
5456
credentials: configuration.awsCredentials,
@@ -120,7 +122,7 @@ export class LiveTailSession {
120122
return this.endTime - this.startTime
121123
}
122124

123-
private buildStartLiveTailCommand(): StartLiveTailCommand {
125+
public buildStartLiveTailCommand(): StartLiveTailCommand {
124126
let logStreamNamePrefix = undefined
125127
let logStreamName = undefined
126128
if (this.logStreamFilter) {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import assert from 'assert'
6+
import { LiveTailSession } from '../../../../awsService/cloudWatchLogs/registry/liveTailSession'
7+
import { StartLiveTailCommand } from '@aws-sdk/client-cloudwatch-logs'
8+
import { LogStreamFilterResponse } from '../../../../awsService/cloudWatchLogs/wizard/liveTailLogStreamSubmenu'
9+
10+
describe('LiveTailSession', async function () {
11+
const testLogGroupArn = 'arn:aws:test-log-group'
12+
const testRegion = 'test-region'
13+
const testFilter = 'test-filter'
14+
const testAwsCredentials = {} as any as AWS.Credentials
15+
16+
it('builds StartLiveTailCommand: no stream Filter, no event filter.', function () {
17+
const session = buildLiveTailSession({ type: 'all' }, undefined)
18+
assert.deepStrictEqual(
19+
session.buildStartLiveTailCommand().input,
20+
new StartLiveTailCommand({
21+
logGroupIdentifiers: [testLogGroupArn],
22+
logEventFilterPattern: undefined,
23+
logStreamNamePrefixes: undefined,
24+
logStreamNames: undefined,
25+
}).input
26+
)
27+
})
28+
29+
it('builds StartLiveTailCommand: with prefix stream Filter', function () {
30+
const session = buildLiveTailSession({ type: 'prefix', filter: testFilter }, undefined)
31+
assert.deepStrictEqual(
32+
session.buildStartLiveTailCommand().input,
33+
new StartLiveTailCommand({
34+
logGroupIdentifiers: [testLogGroupArn],
35+
logEventFilterPattern: undefined,
36+
logStreamNamePrefixes: [testFilter],
37+
logStreamNames: undefined,
38+
}).input
39+
)
40+
})
41+
42+
it('builds StartLiveTailCommand: with specific stream Filter', function () {
43+
const session = buildLiveTailSession({ type: 'specific', filter: testFilter }, undefined)
44+
assert.deepStrictEqual(
45+
session.buildStartLiveTailCommand().input,
46+
new StartLiveTailCommand({
47+
logGroupIdentifiers: [testLogGroupArn],
48+
logEventFilterPattern: undefined,
49+
logStreamNamePrefixes: undefined,
50+
logStreamNames: [testFilter],
51+
}).input
52+
)
53+
})
54+
55+
it('builds StartLiveTailCommand: with log event Filter', function () {
56+
const session = buildLiveTailSession({ type: 'all' }, testFilter)
57+
assert.deepStrictEqual(
58+
session.buildStartLiveTailCommand().input,
59+
new StartLiveTailCommand({
60+
logGroupIdentifiers: [testLogGroupArn],
61+
logEventFilterPattern: testFilter,
62+
logStreamNamePrefixes: undefined,
63+
logStreamNames: undefined,
64+
}).input
65+
)
66+
})
67+
68+
function buildLiveTailSession(
69+
logStreamFilter: LogStreamFilterResponse,
70+
logEventFilterPattern: string | undefined
71+
): LiveTailSession {
72+
return new LiveTailSession({
73+
logGroupArn: testLogGroupArn,
74+
logStreamFilter: logStreamFilter,
75+
logEventFilterPattern: logEventFilterPattern,
76+
region: testRegion,
77+
awsCredentials: testAwsCredentials,
78+
})
79+
}
80+
})

0 commit comments

Comments
 (0)