feat(mixins-preview): add recordFields and outputFormat to Vended Logs Mixin#37042
feat(mixins-preview): add recordFields and outputFormat to Vended Logs Mixin#37042ShadowCat567 wants to merge 3 commits intomainfrom
recordFields and outputFormat to Vended Logs Mixin#37042Conversation
|
|
||||||||||||||
|
|
||||||||||||||
recordFields and outputFormat to Vended Logs MixinrecordFields and outputFormat to Vended Logs Mixin
aws-cdk-automation
left a comment
There was a problem hiding this comment.
The pull request linter fails with the following errors:
❌ Features must contain a change to a README file.
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.
| @@ -24,7 +24,10 @@ const logGroup = new logs.LogGroup(stack, 'DeliveryLogGroup', { | |||
| }); | |||
|
|
|||
| // Setup delivery | |||
| eventBus.with(CfnEventBusLogsMixin.ERROR_LOGS.toLogGroup(logGroup)); | |||
| eventBus.with(CfnEventBusLogsMixin.ERROR_LOGS.toLogGroup(logGroup, { | |||
| outputFormat: CfnEventBusErrorLogsLogGroupOutputFormat.JSON, | |||
There was a problem hiding this comment.
Allegedly you can pass strings into a string enum (like this), however typescript does not like it - gives me an error
| } | ||
|
|
||
| /** | ||
| * Props for S3LogsDelivery | ||
| */ | ||
| export interface S3LogsDeliveryProps { | ||
| export interface IS3LogsDeliveryProps extends IDeliveryProps { |
There was a problem hiding this comment.
Props shouldn't be a behavioural interface.
There was a problem hiding this comment.
I don't think I understand, how should this be restructured? Since S3 has some unique things (mostly encryptionKey) that I think should be a part of props
| export interface IRecordFieldDeliveryProps { | ||
| /** | ||
| * V1 | ||
| * Optional RecordFields that are not required for log delivery | ||
| * These may or may not be passed in by the user | ||
| * | ||
| * @defualt - no optional fields | ||
| */ | ||
| V1 = 'V1', | ||
| readonly optionalFields?: string[]; | ||
| /** | ||
| * V2 | ||
| * Required RecordFields are mandatory to be included in a log delivery | ||
| * | ||
| * @default - no mandatory fields | ||
| */ | ||
| V2 = 'V2', | ||
| readonly mandatoryFields?: string[]; | ||
| } |
There was a problem hiding this comment.
The distinction here between optionalFields and mandatoryFields seems unnecessary.
There was a problem hiding this comment.
we do need both in here, I think these were just the wrong names. optionalFields is now providedFields, it represents the fields the user provided us. mandatoryFields remains pretty much the same, it's an array of a delivery's mandatory fields.
| optionalFields: props?.additionalFields, | ||
| mandatoryFields: ["resource-id","body"] |
There was a problem hiding this comment.
we can combine these in the code gen
There was a problem hiding this comment.
I think this is a little confusing, since optionalFields/additionalFields is public facing, while mandatoryFields is not. Yes, we can add the mandatoryFields to the additionalFields enum type, but I think we should still have the mandatoryFields passed into the LogDelivery class for the logic surrounding what we set recordFields to in there.
| readonly additionalFields?: Array<CfnThingApplicationLogsAdditionalFields>; | ||
| } | ||
|
|
||
| export enum CfnThingApplicationLogsLogGroupOutputFormat { |
There was a problem hiding this comment.
okay i see how this is getting ridiculous. maybe we do a single output format for everything and do docs and runtime validation?
There was a problem hiding this comment.
what do you mean? Not all destinations share the same outputFormats?
| @@ -157,5 +201,149 @@ export class CfnThingLogsMixin extends core.Mixin implements core.IMixin { | |||
| const sourceArn = service.CfnThing.arnForThing(resource); | |||
| this.logDelivery.bind(resource, this.logType, sourceArn); | |||
| } | |||
| } | |||
|
|
|||
| export enum CfnThingApplicationLogsAdditionalFields { | |||
There was a problem hiding this comment.
Hmm. I wonder if the enum should have all fields. We can do the adding of mandatory fields and deduplication in code.
Reason for this change
We want to support passing in
outputFormatandrecordFieldsto theVendedLogsMixin.Description of changes
Added support for
outputFormatandrecordFieldsin theVendedLogsMixin. There are some important design decisions that happened here:toDestination()andtoXRay()do not supportoutputFormat. This is becauseoutputFormatis something that is set in the destination andtoDestination()does not actually have direct access to the destination resource that was passed into it. If the user wants to set anoutputFormatin their destination resource, we assume they already did so.toXRaydoes not supportoutputFormatbecause the XRay destination does not support setting anoutputFormat.recordFieldsvs when we rely on default implementation. The default implementation ofrecordFields(RecordFields: undefinedin the delivery) includes all possiblerecordFieldsfor a delivery. I did not want to mess with this default implementation and have something that may be unexpected happen if a delivery has both optional and mandatory fields and the user does not pass in any optional fields. So when a delivery only has mandatory fields or it has mandatory fields but can take optional ones, in the case no optional fields are passed in, we use the default implementation. When optional fields are present we setRecordFieldsto the optional fields or if a delivery has mandatory fields we setRecordFieldsto the optional fields we got + the delivery's mandatory fields.When we don't get an
outputFormatfor S3, Firehose, and Cloudwatch destinations, we also fall back to whatever the default is by providingundefined.I have done my own manual testing to verify that providing
undefinedtoOutputFormatandRecordFieldsworks as I have described here.Describe any new or updated permissions being added
N/A
Description of how you validated changes
Update integration and unit test coverage
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license