Skip to content

Commit

Permalink
fix(cli): cdk watch constantly prints 'messages suppressed' (#18486)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
corymhall authored Jan 19, 2022
1 parent 4e4f7d2 commit 9b266f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/aws-cdk/lib/api/logs/logs-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ export class CloudWatchLogEventMonitor {
limit: 100,
startTime: startTime,
}).promise();
const filteredEvents = response.events ?? [];

for (const event of response.events ?? []) {
for (const event of filteredEvents) {
if (event.message) {
events.push({
message: event.message,
Expand All @@ -200,9 +201,9 @@ export class CloudWatchLogEventMonitor {
// if we have > 100 events let the user know some
// messages have been supressed. We are essentially
// showing them a sampling (10000 events printed out is not very useful)
if (response.nextToken) {
if (filteredEvents.length > 0 && response.nextToken) {
events.push({
message: '(...messages supressed...)',
message: '>>> `watch` shows only the first 100 log messages - the rest have been truncated...',
logGroupName,
timestamp: new Date(endTime),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk/test/api/logs/logs-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test('continue to the next page if it exists', async () => {
`[${blue('loggroup')}] ${yellow(HUMAN_TIME)} message`,
);
expect(stderrMock.mock.calls[1][0]).toContain(
`[${blue('loggroup')}] ${yellow(new Date(T100).toLocaleTimeString())} (...messages supressed...)`,
`[${blue('loggroup')}] ${yellow(new Date(T100).toLocaleTimeString())} >>> \`watch\` shows only the first 100 log messages - the rest have been truncated...`,
);
});

Expand Down

0 comments on commit 9b266f4

Please sign in to comment.