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

chore(codegen): support request compression #5625

Closed
wants to merge 6 commits into from

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Dec 29, 2023

Issue

Internal JS-4242

Description

The codegen change to support request compression when trait is available.

Testing

Test code:

import { strictEqual } from "assert";
import {
  CloudWatch,
  StandardUnit,
} from "../aws-sdk-js-v3/clients/client-cloudwatch/dist-cjs/index.js";

const client = new CloudWatch({});

for (const relation of ["before", "after"]) {
  client.middlewareStack.addRelativeTo(
    (next) => async (args) => {
      const { body } = args.request;
      console.log(`length ${relation} compressionMiddleware`, body.length);
      return next(args);
    },
    {
      relation,
      toMiddleware: "compressionMiddleware",
    }
  );
}

const startTime = Date.now();

const separator = "_";
const Namespace = ["test", startTime].join(separator);
const MetricName = [Namespace, "metric"].join(separator);
const length = 500;

await client.putMetricData({
  Namespace,
  MetricData: Array.from({ length }, (_, i) => ({
    MetricName,
    Unit: StandardUnit.Bytes,
    Value: 1,
  })),
});
const endTime = startTime + length * 1000;

const response = await new CloudWatch().getMetricData({
  StartTime: new Date(startTime),
  EndTime: new Date(endTime),
  MetricDataQueries: Array.from({ length }, (_, i) => ({
    Id: [MetricName, i].join(separator),
    MetricStat: {
      Metric: { Namespace, MetricName },
      Period: 1,
      Stat: "Sum",
      Unit: StandardUnit.Bytes,
    },
  })),
});

strictEqual(response.MetricDataResults?.length, length);
for (const result of response.MetricDataResults) {
  strictEqual(result.Label, MetricName);
}

By default, the request.body is compressed:

$ grep -wns 'CloudWatch({' test.v3.mjs
7:const client = new CloudWatch({});

$ node test.v3.mjs
length before compressionMiddleware 60744
length after compressionMiddleware 4180

The compression is skipped, if explicitly required in client configuration:

$ grep -wns 'CloudWatch({' test.v3.mjs
7:const client = new CloudWatch({ disableRequestCompression: true });

$ node test.v3.mjs
length before compressionMiddleware 60744
length after compressionMiddleware 60744

The compression is skipped if requestMinCompressionSizeBytes does not allow

$ grep -wns 'CloudWatch({' test.v3.mjs
7:const client = new CloudWatch({ requestMinCompressionSizeBytes: 60745 })

$ node test.v3.mjs
length before compressionMiddleware 60744
length after compressionMiddleware 60744

The compression goes through if requestMinCompressionSizeBytes allows

$ grep -wns 'CloudWatch({' test.v3.mjs
7:const client = new CloudWatch({ requestMinCompressionSizeBytes: 60743 });

$ node test.v3.mjs
length before compressionMiddleware 60744
length after compressionMiddleware 4180

Checklist

  • If you wrote E2E tests, are they resilient to concurrent I/O?
  • If adding new public functions, did you add the @public tag and enable doc generation on the package?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr trivikr force-pushed the codegen-request-compression branch 2 times, most recently from 44885ea to 470a0cc Compare January 3, 2024 08:01
@trivikr
Copy link
Member Author

trivikr commented Jan 3, 2024

This PR was just created for testing.

The requestCompression will be added in clients with a daily update.

@trivikr trivikr closed this Jan 3, 2024
@trivikr trivikr deleted the codegen-request-compression branch January 3, 2024 22:48
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant