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(apigateway): minCompressionSize on SpecRestApi #24067

Merged
merged 12 commits into from
Mar 1, 2023

Conversation

pattasai
Copy link
Contributor

@pattasai pattasai commented Feb 8, 2023

This PR adds minCompressionSize to SpecRestApi, which allows compression on api's payload. Within SpecRestApi minComppresssionSize: Size is the additional prop added to SpecRestApiProps to support minCompressionSize which takes class Size, the value of how much the payload needs to be compressed.

This PR also adds minCompressionSize to RestApi which supports Size class e.g minComppresssionSize: Size and deprecates minimumCompressionSize which has number as a type.

For example,

const api = new apigw.RestApi(stack, 'RestApi', {
      minCompressionSize: Size.bytes(1024),
    });

compression for the payload would be 1024 bytes which is equivalent to 1 kibibyte.

Closes #22926.


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 Feb 8, 2023

@github-actions github-actions bot added the p2 label Feb 8, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team February 8, 2023 13:57
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Feb 8, 2023
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.

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

PR Linter changes needed. Once updated, it will also ask for integ tests and a readme update.

*
* @default - Compression is disabled.
*/
readonly minimumCompressionSize?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered using the Size type here?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on using the Size type.

Also, just out of curiosity, if a user inputs a number higher than the maximum here, what is the user experience? If the failure message sent back from CloudFormation or the service isn't clear, we may want to add our own validation for the maximum value with a clear error message.

@pattasai pattasai changed the title Setting MinimumCompressionSize prop Supporting Setting MinimumCompressionSize on SpecRestApi Feb 9, 2023
@pattasai pattasai changed the title Supporting Setting MinimumCompressionSize on SpecRestApi feat(aws-apigateway): Support Setting MinimumCompressionSize on SpecRestApi Feb 10, 2023
@pattasai pattasai changed the title feat(aws-apigateway): Support Setting MinimumCompressionSize on SpecRestApi feat(apigateway): support setting minimumCompressionSize Feb 10, 2023
@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. labels Feb 11, 2023
@pattasai pattasai force-pushed the pattasai-MinimumCompressionSize-SpecRestApi branch from 0c7097e to 2ea8ec7 Compare February 15, 2023 15:21
@rix0rrr rix0rrr added the pr-linter/exempt-readme The PR linter will not require README changes label Feb 16, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review February 17, 2023 15:06

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

Comment on lines 229 to 237
readonly minimumCompressionSize?: number;
readonly minCompressionSize?: Size;
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is morally ~the same, but I would have expected you to leave the old property in place and @deprecate it, and then add a new block of text with the new property.

In any case I think you'd like to adjust the doc comment for the new property. For example, it's no longer an "integer".

@@ -216,6 +216,14 @@ export interface RestApiProps extends RestApiOptions {
*/
readonly binaryMediaTypes?: string[];

/**
* Deprecated
Copy link
Contributor

Choose a reason for hiding this comment

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

Both properties need to be documented, even if they are deprecated.

@@ -261,6 +269,18 @@ export interface SpecRestApiProps extends RestApiBaseProps {
* @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-import-api.html
*/
readonly apiDefinition: ApiDefinition;

/**
* A nullable integer that is used to enable compression (with non-negative
Copy link
Contributor

Choose a reason for hiding this comment

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

Not an integer.

const imported = apigw.RestApi.fromRestApiId(stack, 'imported-api', 'api-rxt4498f');
const stack = new Stack(app);
const api = new apigw.RestApi(stack, 'RestApi', {
minCompressionSize: Size.bytes(1024),
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 test to make sure that minimumCompressionSize also still works.

You might need to use testDeprecated().

Copy link
Contributor

Choose a reason for hiding this comment

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

Also users shouldn't be able to set both properties.

Copy link
Contributor

Choose a reason for hiding this comment

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

@pattasai I don't see where the second part of this was addressed. I would expect to see an error thrown if the user specifies minCompressionSize and minimumCompressionSize, and a test to assert that that behavior happens.

Copy link
Contributor

Choose a reason for hiding this comment

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

☝️ What Kaizen said. Now users are able to go:

new RestApi(..., {
  minimumCompressionSize: 666,
  minCompressionSize: Size.bytes(1024),
});

What do you think should happen in that case?

@@ -225,9 +225,22 @@ export interface RestApiProps extends RestApiOptions {
* payload size.
*
* @default - Compression is disabled.
* @deprecated - superseded by `minCompressionSize`
Copy link
Contributor

Choose a reason for hiding this comment

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

👨‍🍳👌

@@ -763,7 +789,7 @@ export class RestApi extends RestApiBase {
description: props.description,
policy: props.policy,
failOnWarnings: props.failOnWarnings,
minimumCompressionSize: props.minimumCompressionSize,
minimumCompressionSize: props.minCompressionSize?.toBytes() || props.minimumCompressionSize,
Copy link
Contributor

Choose a reason for hiding this comment

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

For reasons (gestures wildly), this will not what you expect it to do when you pass in Size.bytes(0).

  • Try it first in a new unit test
  • Then read about it
  • Then replace it with:
Suggested change
minimumCompressionSize: props.minCompressionSize?.toBytes() || props.minimumCompressionSize,
minimumCompressionSize: props.minCompressionSize?.toBytes() ?? props.minimumCompressionSize,

test('fromRestApiAttributes() with restApiName', () => {
// GIVEN
const stack = new Stack();
testDeprecated('RestApi minimumCompressionSize', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 thank you!

Comment on lines -961 to +958
// WHEN
const api = new apigw.SpecRestApi(stack, 'api', {
apiDefinition: apigw.ApiDefinition.fromInline({ foo: 'bar' }),
endpointTypes: [apigw.EndpointType.EDGE, apigw.EndpointType.PRIVATE],
});
test('fromRestApiAttributes() with restApiName', () => {
// GIVEN
const stack = new Stack();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does so much of this other code show up as changed?

Template.fromStack(stack).resourceCountIs('AWS::ApiGateway::Account', 0);
});

test('SpecRestApi minimumCompressionSize', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

const imported = apigw.RestApi.fromRestApiId(stack, 'imported-api', 'api-rxt4498f');
const stack = new Stack(app);
const api = new apigw.RestApi(stack, 'RestApi', {
minCompressionSize: Size.bytes(1024),
Copy link
Contributor

Choose a reason for hiding this comment

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

☝️ What Kaizen said. Now users are able to go:

new RestApi(..., {
  minimumCompressionSize: 666,
  minCompressionSize: Size.bytes(1024),
});

What do you think should happen in that case?

@rix0rrr rix0rrr changed the title feat(apigateway): support setting minimumCompressionSize feat(apigateway): minCompressionSize on SpecRestApi Feb 23, 2023
@@ -758,12 +784,16 @@ export class RestApi extends RestApiBase {
constructor(scope: Construct, id: string, props: RestApiProps = { }) {
super(scope, id, props);

if (props.minCompressionSize?.toBytes()! >= 0 && props.minimumCompressionSize! >= 0) {
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
if (props.minCompressionSize?.toBytes()! >= 0 && props.minimumCompressionSize! >= 0) {
if (props.minCompressionSize !== undefined && props.minimumCompressionSize !== undefined) {

@mergify
Copy link
Contributor

mergify bot commented Mar 1, 2023

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: 9b9ea6c
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 2a81f0f into main Mar 1, 2023
@mergify mergify bot deleted the pattasai-MinimumCompressionSize-SpecRestApi branch March 1, 2023 16:09
@mergify
Copy link
Contributor

mergify bot commented Mar 1, 2023

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).

homakk pushed a commit to homakk/aws-cdk that referenced this pull request Mar 28, 2023
This PR adds minCompressionSize to SpecRestApi, which allows compression on api's payload. Within SpecRestApi ``` minComppresssionSize: Size``` is the additional prop added to SpecRestApiProps to support minCompressionSize  which takes class Size, the value of how much the payload needs to be compressed. 

This PR  also adds minCompressionSize to RestApi which supports  Size class e.g ``` minComppresssionSize: Size``` and deprecates minimumCompressionSize which has number as a type.

For example,
```ts
const api = new apigw.RestApi(stack, 'RestApi', {
      minCompressionSize: Size.bytes(1024),
    });
```
compression for the payload would be 1024 bytes which is equivalent to 1 kibibyte.

Closes aws#22926.

----

*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
contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 pr-linter/exempt-readme The PR linter will not require README changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(apigateway): support for minimumCompressionSize
5 participants