-
Notifications
You must be signed in to change notification settings - Fork 86
Functions logging #2245
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
Functions logging #2245
Conversation
🦋 Changeset detectedLatest commit: 23a7409 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The reason is that we're using some of these parameters for our internal implementation purposes. Therefore, exposing them in uncontrolled way will impact some of our functionalities like secret resolution or bundling. For "just give me all CDK knobs" we're evaluating different approach described here #1543 and prototyped here #1602 . |
Thank you for the additional context. If someone really wants all the CDK knobs the can use CDK. Some trade offs are expected with a managed solution such as Amplify. thank you to you and the other contributors for your work on Amplify! |
retention: RetentionDays.INFINITE, | ||
retention: this.props.logging?.retention, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the default still INFINITE
? Should we include it regardless to avoid CDK breaking it in future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the default still INFINITE?
yes, but we can be explicit about this.
assert.ok( | ||
Object.keys(lambdas).some((key) => key.startsWith('LogRetention')) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no way to assert the actual retention period?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found something. added below.
* Converts LogRetention to CDK types. | ||
*/ | ||
export class LogRetentionConverter { | ||
toRetentionDays = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The converted type is specific to CDK
, we should mention it as such.
toRetentionDays = ( | |
toCDKLogsRetentionDays = ( |
* Converts LogLevel to CDK types. | ||
*/ | ||
export class LogLevelConverter { | ||
toApplicationLogLevel = (logLevel: LogLevel | undefined) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toApplicationLogLevel = (logLevel: LogLevel | undefined) => { | |
toCDKLambdaApplicationLogLevel = (logLevel: LogLevel | undefined) => { |
// Enabling log retention adds extra lambda. | ||
template.resourceCountIs('AWS::Lambda::Function', 2); | ||
const lambdas = template.findResources('AWS::Lambda::Function'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to avoid creating this extra lambda by creating the logGroup ourselves https://repost.aws/questions/QUzCgY0gSIQNGHZc6frGcI7g/log-retention-lambda#ANwKiEC22QQ-uV0r5yi0JdBQ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been tried and adopted in conversation handler.
However, it was easier there because it was a new thing.
Here the problem space is constrained in such a way that:
- In order to use custom log group (us or customer) we have to pass reference to function. So log group must be created before calling NodejsFunction ctor.
- In order to retain log group naming we need function name first. This is not available until NodejsFunction ctor is called, making it circlular dependency problem.
- When working on conversation handler I tried to compute function name before creating log group and nodejsfunction but I was not successful at producing function name that would match implicit cdk algorithm. That computation is internalized and I didn't find a way to implement it using available apis from cdk.
- Changing function name and/or log group name algorithm at this point would mean destructive changes.
I wanted to avoid destructive changes, so I pursued a solution based on this extra lambda.
I think the proper solution to expose log group knobs would be to add another alternative to LoggingOptions
in the future where we {..existing...} | { logGroupKnobs }
.
wdyt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, at least it's only one extra function for all customer defined lambda functions.
packages/platform-core/API.md
Outdated
@@ -136,13 +136,13 @@ export type LocalConfigurationFileName = 'usage_data_preferences.json'; | |||
// @public | |||
class LogLevelConverter { | |||
// (undocumented) | |||
toApplicationLogLevel: (logLevel: LogLevel | undefined) => ApplicationLogLevel | undefined; | |||
toCDKApplicationLogLevel: (logLevel: LogLevel | undefined) => ApplicationLogLevel | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still suggest to include lambda
in there, as other AWS services may have different log level names or types.
toCDKApplicationLogLevel: (logLevel: LogLevel | undefined) => ApplicationLogLevel | undefined; | |
toCDKLambdaApplicationLogLevel: (logLevel: LogLevel | undefined) => CDKLambdaApplicationLogLevel | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change the toCDKApplicationLogLevel
.
But return type is already import { ApplicationLogLevel } from 'aws-cdk-lib/aws-lambda';
Even if we alias this for our purposes, customer still needs to import from cdk lib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw. I didn't notice Lambda
in first comment, sorry.
Problem
Implements feature request #2058 .
Changes
DX
Validation
Added tests
Checklist
run-e2e
label set.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.