Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CLI): watch logs always end with the 'truncated' message #18805

Closed
skinny85 opened this issue Feb 3, 2022 · 2 comments · Fixed by #19241
Closed

(CLI): watch logs always end with the 'truncated' message #18805

skinny85 opened this issue Feb 3, 2022 · 2 comments · Fixed by #19241
Assignees
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p1 package/tools Related to AWS CDK Tools or CLI

Comments

@skinny85
Copy link
Contributor

skinny85 commented Feb 3, 2022

What is the problem?

When using cdk watch, the logs always end with:

[/aws/lambda/HackathonExampleStack-NodeJsFunction6DD2A8DD-adO4KmEjQSuq] 5:10:46 PM >>> `watch` shows only the first 100 log messages - the rest have been truncated...

Before that, the logs show only 5 messages, so the limit of 100 was definitely not hit.

Reproduction Steps

My CDK app is super basic:

import * as cdk from '@aws-cdk/core';
import * as lambda from '@aws-cdk/aws-lambda';
import * as apig from '@aws-cdk/aws-apigateway';

export class HackathonExampleStack extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        const func = new lambda.Function(this, 'NodeJsFunction', {
            // functionName: 'hackathon-function',
            code: lambda.Code.fromAsset(`${__dirname}/lambda-code`),
            runtime: lambda.Runtime.NODEJS_14_X,
            handler: 'index.handler',
        });
        new apig.LambdaRestApi(this, 'RestAPi', {
            handler: func,
        });
        new lambda.Function(this, 'SecondLambdaFunction', {
            code: lambda.Code.fromInline(`
                function handler(_event, _context, callback) {
                    callback(null, 'Success!');
                }

                exports.h = handler;
            `),
            runtime: lambda.Runtime.NODEJS_12_X,
            handler: 'index.h',
        });
    }
}

What did you expect to happen?

Logs would be shown nicely.

What actually happened?

The logs always end with:

[/aws/lambda/HackathonExampleStack-NodeJsFunction6DD2A8DD-adO4KmEjQSuq] 5:10:46 PM >>> `watch` shows only the first 100 log messages - the rest have been truncated...

CDK CLI Version

v1.143.0

Framework Version

v1.143.0

Node.js Version

v16.13.1

OS

MacOS

Language

Typescript

Language Version

3.9.7

Other information

No response

@skinny85 skinny85 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 3, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Feb 3, 2022
@skinny85 skinny85 assigned corymhall and unassigned rix0rrr Feb 3, 2022
@corymhall
Copy link
Contributor

It looks like as long as there are any events in the log group it will always return a nextToken. I think the solution is to only return that message if we actually get 100 events.

@corymhall corymhall added effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 3, 2022
@skinny85 skinny85 added the p1 label Feb 3, 2022
@skinny85 skinny85 changed the title (CLI): watch logs always end wit the truncated message (CLI): watch logs always end with the truncated message Feb 3, 2022
@skinny85 skinny85 changed the title (CLI): watch logs always end with the truncated message (CLI): watch logs always end with the 'truncated' message Feb 3, 2022
@mergify mergify bot closed this as completed in #19241 Mar 4, 2022
mergify bot pushed a commit that referenced this issue Mar 4, 2022
CloudWatchLogs.filterLogEvents will always return a `nextToken` as long
as there are _any_ additional logs. This is regardless of any filter
used (i.e. `startTime`).

This PR updates the logic to only display the truncated message if
`CloudWatchLogs.filterLogEvents` returns 100 events (the `limit`) _and_ the
`nextToken`. If the limit is hit and there is a `nextToken` then we can
assume that the _current_ request for log events was truncated.

fixes #18805


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Mar 4, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TheRealAmazonKendra pushed a commit to TheRealAmazonKendra/aws-cdk that referenced this issue Mar 11, 2022
…9241)

CloudWatchLogs.filterLogEvents will always return a `nextToken` as long
as there are _any_ additional logs. This is regardless of any filter
used (i.e. `startTime`).

This PR updates the logic to only display the truncated message if
`CloudWatchLogs.filterLogEvents` returns 100 events (the `limit`) _and_ the
`nextToken`. If the limit is hit and there is a `nextToken` then we can
assume that the _current_ request for log events was truncated.

fixes aws#18805


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants