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

fix(lambda): update the type of LogFormat option #28127

Closed
wants to merge 10 commits into from

Conversation

tomoish
Copy link

@tomoish tomoish commented Nov 24, 2023

The logFormat option in the FunctionOptions interface should accept one of the LogFormat enum options.

This PR updates the type of the LogFormat option to LogFormat instead of string.

Closes #28114.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. p2 labels Nov 24, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team November 24, 2023 09:55
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@@ -466,7 +466,7 @@ export interface FunctionOptions extends EventInvokeConfigOptions {
* Sets the logFormat for the function.
* @default Text format
*/
readonly logFormat?: string;
readonly logFormat?: LogFormat;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be a breaking change since it's currently possible (arguably encouraged by the type) to set the property to the strings "JSON" or "Text".

I suggest adding | keyof LogFormat which would let the user use either the enum or type-safe strings

Suggested change
readonly logFormat?: LogFormat;
readonly logFormat?: LogFormat | keyof typeof LogFormat;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment.
I will modify logFormat type to accept both the enum and type-safe strings

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion.
Your comment realised me that my first change would be a breaking change.
Both of my first change and your suggestion can't accept both of the enum or type-safe strings.
Therefore, I changed the type of logFormat as readonly logFormat?: LogFormat | `${LogFormat}`; due to accept both of lambda.LogFormat.TEXT and string 'Text'.

@aws-cdk-automation aws-cdk-automation dismissed their stale review November 29, 2023 07:38

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 29, 2023
Copy link
Contributor

@scanlonp scanlonp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we add validation that the text passed in is either 'Text' or 'JSON'? This will prevent random strings from being passed in. We could add it in the getLoggingConfig function on 1089-1103 of function.ts. While this would technically be breaking for anyone who passed in a bad value, I would assume any LogFormat value other than those two would cause a deployment failure. This would corral the problem fully.

@scanlonp scanlonp self-assigned this Dec 5, 2023
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 5, 2023
@tomoish
Copy link
Author

tomoish commented Dec 11, 2023

I believe we add validation that the text passed in is either 'Text' or 'JSON'? This will prevent random strings from being passed in. We could add it in the getLoggingConfig function on 1089-1103 of function.ts. While this would technically be breaking for anyone who passed in a bad value, I would assume any LogFormat value other than those two would cause a deployment failure. This would corral the problem fully.

Thank you for your comment.
I will add a validation.

@mergify mergify bot dismissed scanlonp’s stale review December 11, 2023 06:30

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 8bfd2d6
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 11, 2023
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a problem with this as is, since the values in which this would be a breaking change would never have worked. That being said, we must sanity check this in our JSII-target languages to make sure that this doesn't somehow break those users. We cannot merge this in without doing that

Unless @tomoish you are willing to do this I'm mostly adding in this note to myself to test this later.

@tomoish
Copy link
Author

tomoish commented Dec 14, 2023

I don't have a problem with this as is, since the values in which this would be a breaking change would never have worked. That being said, we must sanity check this in our JSII-target languages to make sure that this doesn't somehow break those users. We cannot merge this in without doing that

Unless @tomoish you are willing to do this I'm mostly adding in this note to myself to test this later.

Hello, @kaizencc.

Thank you for your comment.

I might not be able to perform the sanity check for the JSII-target languages.
Would you be willing to take on this task?

Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like in python, the readonly logFormat?: LogFormat |${LogFormat}; gets converted to:

log_format: typing.Optional[typing.Union[builtins.str, "LogFormat"]] = None,

which is not a breaking change. however, it also negates the impact of this PR since it still permits all strings (and the point of this PR is to restrict these strings to 'TEXT' and 'JSON'.

We want to do a better job of catering to all our languages, not just typescript. So I don't think I want to go down this path. Instead, we should deprecate logFormat and create a new variable, loggingFormat, which has the correct type. (If you hate the loggingFormat name for some reason, I'll also allow logFormatV2 or feel free to come up with alternatives).

The deprecation will nag users to move to the new prop, where we will successfully restrict typing for all languages, and problem (not-so-elegantly) solved.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 21, 2023
@kaizencc
Copy link
Contributor

@tomoish ^

@tomoish
Copy link
Author

tomoish commented Dec 23, 2023

Thank you for your consideration, @kaizencc.

I wasn't familiar with jsii, so I was researching how changing the type of logFormat fromreadonly logFormat?: LogFormat | \`${LogFormat}`; to readonly logFormat?: LogFormat | "Text" | "JSON";, thereby explicitly restricting logFormat string to only 'Text' and 'JSON', would be translated in other languages.

If you have any information on this, I would like to know. Also, if this approach does not resolve the issue, I would accept your proposal.

In this new loggingFormat, are we considering a type like readonly logFormat?: LogFormat; that does not allow string?

@kaizencc
Copy link
Contributor

kaizencc commented Dec 29, 2023

@tomoish

In this new loggingFormat, are we considering a type like readonly logFormat?: LogFormat; that does not allow string?

Correct

If you have any information on this, I would like to know. Also, if this approach does not resolve the issue, I would accept your proposal.

I'm not too familiar with jsii myself unfortunately, but I believe what happens is that any type in typescript like "TEXT" becomes a string type in python and maybe other languages as well.

@tomoish
Copy link
Author

tomoish commented Dec 29, 2023

Thank you for your response, @kaizencc.
I understand the new arguments and how they are converted to other languages.
I will try to implement loggingFormat.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Jan 19, 2024
mergify bot pushed a commit that referenced this pull request Jan 31, 2024
> # Issue
> > The issue is that LogFormat is a String so it doesn't allow the enum LogFormat. 
> # Solution
> > Created a new enum for the LoggingFormat and added testing. 
So the solution sets these values as potential environment variables.
The main difference is LoggingFormat is assigned to an enum instead of a string.
> # Important Design Decisions
> > This is so that an enum could be used for LoggingFormat without breaking JSII target languages. Some background information is in this pr #28127. Was a recommended solution here. #28127
>
> Remember to follow the [CONTRIBUTING GUIDE] and [DESIGN GUIDELINES] for any
> code you submit.
>
> [CONTRIBUTING GUIDE]: https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md
> [DESIGN GUIDELINES]: https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md

Closes #28114.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
SankyRed pushed a commit that referenced this pull request Feb 8, 2024
> # Issue
> > The issue is that LogFormat is a String so it doesn't allow the enum LogFormat. 
> # Solution
> > Created a new enum for the LoggingFormat and added testing. 
So the solution sets these values as potential environment variables.
The main difference is LoggingFormat is assigned to an enum instead of a string.
> # Important Design Decisions
> > This is so that an enum could be used for LoggingFormat without breaking JSII target languages. Some background information is in this pr #28127. Was a recommended solution here. #28127
>
> Remember to follow the [CONTRIBUTING GUIDE] and [DESIGN GUIDELINES] for any
> code you submit.
>
> [CONTRIBUTING GUIDE]: https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md
> [DESIGN GUIDELINES]: https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md

Closes #28114.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TheRealAmazonKendra pushed a commit that referenced this pull request Feb 9, 2024
> # Issue
> > The issue is that LogFormat is a String so it doesn't allow the enum LogFormat. 
> # Solution
> > Created a new enum for the LoggingFormat and added testing. 
So the solution sets these values as potential environment variables.
The main difference is LoggingFormat is assigned to an enum instead of a string.
> # Important Design Decisions
> > This is so that an enum could be used for LoggingFormat without breaking JSII target languages. Some background information is in this pr #28127. Was a recommended solution here. #28127
>
> Remember to follow the [CONTRIBUTING GUIDE] and [DESIGN GUIDELINES] for any
> code you submit.
>
> [CONTRIBUTING GUIDE]: https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md
> [DESIGN GUIDELINES]: https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md

Closes #28114.

----

*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
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-lambda: Log format option is not typed
5 participants