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

feat(ec2): change log format in Vpc flow logs #22430

Merged
merged 17 commits into from
Nov 11, 2022

Conversation

watany-dev
Copy link
Contributor

@watany-dev watany-dev commented Oct 9, 2022

refer to #16279 and #16279 (comment). The difference is below

fixes #19316


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

@gitpod-io
Copy link

gitpod-io bot commented Oct 9, 2022

@github-actions github-actions bot added the valued-contributor [Pilot] contributed between 6-12 PRs to the CDK label Oct 9, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team October 9, 2022 07:44
@github-actions github-actions bot added p2 effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. labels Oct 9, 2022
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.

@watany-dev watany-dev force-pushed the add-flowlog-logformat branch from 4d2aa5e to 0fb256a Compare October 15, 2022 05:50
@aws-cdk-automation aws-cdk-automation dismissed their stale review October 15, 2022 15:12

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

@watany-dev watany-dev changed the title feat(ec2): Add Option LogFormatField in flowlogs feat(ec2): support for custom logformat in vpc flow logs Oct 15, 2022
@watany-dev watany-dev marked this pull request as ready for review October 16, 2022 03:37
@corymhall corymhall self-assigned this Oct 21, 2022
Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

Just a couple of comments. Thanks for picking this up!

/**
* The following table describes all of the available fields for a flow log record.
*/
export enum LogFormatField {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need custom for LogFormatField. "custom" in the document below does not mean that the user can specify any Key. It means that you can specify any Key of "Available fields" with a space-separated string.
docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html#flow-logs-fields

The reason we want to have the custom option is to allow the user to specify new fields that we
have not added support for yet. We don't want to block users from using new values as soon as they
are released. If you don't like the custom methed we can do without that and the
user can just do something like:

customLogFormatFields: [
  LogFormatField.SRC_PORT,
  new LogFormatField('${new-field}'),
]

Copy link
Contributor Author

@watany-dev watany-dev Oct 22, 2022

Choose a reason for hiding this comment

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

Fixed. Added Usage to Readme.md.

Comment on lines 408 to 410
/**
* The VPC Flow Logs version.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* The VPC Flow Logs version.
*/
/**
* The VPC Flow Logs version.
*/

nit - can you fix all the formatting of these docstrings so they are consistent.

packages/@aws-cdk/aws-ec2/lib/vpc-flow-logs.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed corymhall’s stale review October 22, 2022 04:52

Pull request has been modified.

@watany-dev watany-dev force-pushed the add-flowlog-logformat branch 3 times, most recently from 3b819e2 to a535340 Compare October 22, 2022 08:33
@watany-dev watany-dev force-pushed the add-flowlog-logformat branch from a535340 to 8d24152 Compare October 22, 2022 09:06
@watany-dev watany-dev requested a review from corymhall October 23, 2022 05:07
@corymhall corymhall removed their assignment Nov 2, 2022
/**
* The default format.
*/
public static readonly ALL_DEFAULT_FIELDS = new LogFormatField('${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status} ${vpc-id} ${subnet-id} ${instance-id} ${tcp-flags} ${type} ${pkt-srcaddr} ${pkt-dstaddr} ${region} ${az-id} ${sublocation-type} ${sublocation-id} ${pkt-src-aws-service} ${pkt-dst-aws-service} ${flow-direction} ${traffic-path}');
Copy link
Contributor

Choose a reason for hiding this comment

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

Edge case question here. Since this will be a manual update in the future, what happens if a customer uses this and then also adds a custom one because it's not in here yet, and then we update this to include it (so now it's a duplicate). Will that cause an error? Will it de-duplicate it? Or will it just have the field twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this implementation, the expanded string of each parameter is defined as a space-separated string. Thus there will be two fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

According to https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html#flow-log-records, the default fields are all those with version '2' in that table, i.e.:

  • version
  • account-id
  • interface-id
  • srcaddr
  • dstaddr
  • srcport
  • dstport
  • protocol
  • packets
  • bytes
  • start
  • end
  • action
  • log-status

(Hence, not the rest)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@watany-dev watany-dev requested review from TheRealAmazonKendra and removed request for corymhall November 8, 2022 14:16
rix0rrr
rix0rrr previously requested changes Nov 9, 2022
/**
* The default format.
*/
public static readonly ALL_DEFAULT_FIELDS = new LogFormatField('${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status} ${vpc-id} ${subnet-id} ${instance-id} ${tcp-flags} ${type} ${pkt-srcaddr} ${pkt-dstaddr} ${region} ${az-id} ${sublocation-type} ${sublocation-id} ${pkt-src-aws-service} ${pkt-dst-aws-service} ${flow-direction} ${traffic-path}');
Copy link
Contributor

Choose a reason for hiding this comment

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

According to https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html#flow-log-records, the default fields are all those with version '2' in that table, i.e.:

  • version
  • account-id
  • interface-id
  • srcaddr
  • dstaddr
  • srcport
  • dstport
  • protocol
  • packets
  • bytes
  • start
  • end
  • action
  • log-status

(Hence, not the rest)

return new LogFormatField(`\${${field}}`);
}

constructor(public readonly value: string) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Make this constructor at least protected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am actually using public value to pass strings like this to CfnFlowlog. Is there a good way to improve this?

      customLogFormat = props.logFormat.map(elm => {
        return elm.value;
      }).join(' ');

Copy link
Contributor

Choose a reason for hiding this comment

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

That is fine. The constructor itself should be protected is what I mean.

Suggested change
constructor(public readonly value: string) {}
protected constructor(public readonly value: string) {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My mistake, my bad.

/**
* The custom format. For users to specify unsupported fields.
*/
public static custom(field: string): LogFormatField {
Copy link
Contributor

Choose a reason for hiding this comment

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

A factory called custom() probably shouldn't add any unrequested decoration. Probably call this factory field(), and add one called custom() that just uses the user string verbatim.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is certainly more natural that way. Corrected.

packages/@aws-cdk/aws-ec2/lib/vpc-flow-logs.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ec2/lib/vpc-flow-logs.ts Outdated Show resolved Hide resolved
@@ -1321,6 +1321,36 @@ vpc.addFlowLog('FlowLogCloudWatch', {
});
```

You can also custom format flow logs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a section heading as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@mergify mergify bot dismissed rix0rrr’s stale review November 9, 2022 16:10

Pull request has been modified.

@rix0rrr rix0rrr changed the title feat(ec2): support for custom logformat in vpc flow logs feat(ec2): control of log format in Vpc flow logs Nov 10, 2022
rix0rrr
rix0rrr previously approved these changes Nov 10, 2022
@mergify mergify bot dismissed rix0rrr’s stale review November 10, 2022 09:22

Pull request has been modified.

@rix0rrr rix0rrr changed the title feat(ec2): control of log format in Vpc flow logs feat(ec2): change log format in Vpc flow logs Nov 10, 2022
rix0rrr
rix0rrr previously approved these changes Nov 10, 2022
@mergify mergify bot dismissed rix0rrr’s stale review November 10, 2022 13:04

Pull request has been modified.

@rix0rrr rix0rrr self-assigned this Nov 10, 2022
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 10, 2022

@aws-cdk/aws-ec2:   UNCHANGED  integ.instance-multipart-userdata 1.383s
@aws-cdk/aws-ec2:   UNCHANGED  integ.share-vpcs.lit 1.255s
@aws-cdk/aws-ec2:   NEW        integ.vpc-flow-logs-customformat 0.529s
@aws-cdk/aws-ec2:   UNCHANGED  integ.ports 1.637s
@aws-cdk/aws-ec2:   UNCHANGED  integ.vpc-flow-logs-interval 1.316s
@aws-cdk/aws-ec2:   UNCHANGED  integ.client-vpn-endpoint 2.519s
@aws-cdk/aws-ec2:   UNCHANGED  integ.vpc-ipam 1.34s

wat

@watany-dev watany-dev force-pushed the add-flowlog-logformat branch from 84d4f9c to c0ca1ea Compare November 11, 2022 05:08
@watany-dev
Copy link
Contributor Author

tested integ.vpc-flow-logs-customformat

@mergify
Copy link
Contributor

mergify bot commented Nov 11, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 26779f8 into aws:main Nov 11, 2022
@mergify
Copy link
Contributor

mergify bot commented Nov 11, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@watany-dev watany-dev deleted the add-flowlog-logformat branch November 11, 2022 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 valued-contributor [Pilot] contributed between 6-12 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FlowLog: add support for log_format parameter
5 participants