Skip to content

Commit 9b266f4

Browse files
authored
fix(cli): cdk watch constantly prints 'messages suppressed' (#18486)
Currently if `filterLogEvents` returns a nextToken then we print `(...messages suppressed...)`. According to the docs "This operation can return empty results while there are more log events available through the token.". This fix adds a condition to only print out the suppression message if `filterLogEvents` returns non-empty results. Also updates the message to be more descriptive. fixes #18451 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 4e4f7d2 commit 9b266f4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

packages/aws-cdk/lib/api/logs/logs-monitor.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ export class CloudWatchLogEventMonitor {
182182
limit: 100,
183183
startTime: startTime,
184184
}).promise();
185+
const filteredEvents = response.events ?? [];
185186

186-
for (const event of response.events ?? []) {
187+
for (const event of filteredEvents) {
187188
if (event.message) {
188189
events.push({
189190
message: event.message,
@@ -200,9 +201,9 @@ export class CloudWatchLogEventMonitor {
200201
// if we have > 100 events let the user know some
201202
// messages have been supressed. We are essentially
202203
// showing them a sampling (10000 events printed out is not very useful)
203-
if (response.nextToken) {
204+
if (filteredEvents.length > 0 && response.nextToken) {
204205
events.push({
205-
message: '(...messages supressed...)',
206+
message: '>>> `watch` shows only the first 100 log messages - the rest have been truncated...',
206207
logGroupName,
207208
timestamp: new Date(endTime),
208209
});

packages/aws-cdk/test/api/logs/logs-monitor.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test('continue to the next page if it exists', async () => {
5555
`[${blue('loggroup')}] ${yellow(HUMAN_TIME)} message`,
5656
);
5757
expect(stderrMock.mock.calls[1][0]).toContain(
58-
`[${blue('loggroup')}] ${yellow(new Date(T100).toLocaleTimeString())} (...messages supressed...)`,
58+
`[${blue('loggroup')}] ${yellow(new Date(T100).toLocaleTimeString())} >>> \`watch\` shows only the first 100 log messages - the rest have been truncated...`,
5959
);
6060
});
6161

0 commit comments

Comments
 (0)