Skip to content

chore(codegen): support request compression #5625

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clients/client-cloudwatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@smithy/fetch-http-handler": "^2.3.2",
"@smithy/hash-node": "^2.0.18",
"@smithy/invalid-dependency": "^2.0.16",
"@smithy/middleware-compression": "^2.0.0",
"@smithy/middleware-content-length": "^2.0.18",
"@smithy/middleware-endpoint": "^2.3.0",
"@smithy/middleware-retry": "^2.0.26",
Expand Down
14 changes: 11 additions & 3 deletions clients/client-cloudwatch/src/CloudWatchClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import {
} from "@aws-sdk/middleware-user-agent";
import { Credentials as __Credentials } from "@aws-sdk/types";
import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver";
import {
CompressionInputConfig,
CompressionResolvedConfig,
resolveCompressionConfig,
} from "@smithy/middleware-compression";
import { getContentLengthPlugin } from "@smithy/middleware-content-length";
import { EndpointInputConfig, EndpointResolvedConfig, resolveEndpointConfig } from "@smithy/middleware-endpoint";
import { getRetryPlugin, resolveRetryConfig, RetryInputConfig, RetryResolvedConfig } from "@smithy/middleware-retry";
Expand Down Expand Up @@ -364,6 +369,7 @@ export type CloudWatchClientConfigType = Partial<__SmithyConfiguration<__HttpHan
HostHeaderInputConfig &
AwsAuthInputConfig &
UserAgentInputConfig &
CompressionInputConfig &
ClientInputEndpointParameters;
/**
* @public
Expand All @@ -384,6 +390,7 @@ export type CloudWatchClientResolvedConfigType = __SmithyResolvedConfiguration<_
HostHeaderResolvedConfig &
AwsAuthResolvedConfig &
UserAgentResolvedConfig &
CompressionResolvedConfig &
ClientResolvedEndpointParameters;
/**
* @public
Expand Down Expand Up @@ -428,9 +435,10 @@ export class CloudWatchClient extends __Client<
const _config_5 = resolveHostHeaderConfig(_config_4);
const _config_6 = resolveAwsAuthConfig(_config_5);
const _config_7 = resolveUserAgentConfig(_config_6);
const _config_8 = resolveRuntimeExtensions(_config_7, configuration?.extensions || []);
super(_config_8);
this.config = _config_8;
const _config_8 = resolveCompressionConfig(_config_7);
const _config_9 = resolveRuntimeExtensions(_config_8, configuration?.extensions || []);
super(_config_9);
this.config = _config_9;
this.middlewareStack.use(getRetryPlugin(this.config));
this.middlewareStack.use(getContentLengthPlugin(this.config));
this.middlewareStack.use(getHostHeaderPlugin(this.config));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// smithy-typescript generated code
import { getCompressionPlugin } from "@smithy/middleware-compression";
import { getEndpointPlugin } from "@smithy/middleware-endpoint";
import { getSerdePlugin } from "@smithy/middleware-serde";
import { Command as $Command } from "@smithy/smithy-client";
Expand Down Expand Up @@ -150,6 +151,7 @@ export class PutMetricDataCommand extends $Command
return [
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getCompressionPlugin(config, { encodings: ["gzip"] }),
];
})
.s("GraniteServiceVersion20100801", "PutMetricData", {})
Expand Down
7 changes: 7 additions & 0 deletions clients/client-cloudwatch/src/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
import { DEFAULT_USE_DUALSTACK_ENDPOINT, DEFAULT_USE_FIPS_ENDPOINT } from "@smithy/config-resolver";
import { FetchHttpHandler as RequestHandler, streamCollector } from "@smithy/fetch-http-handler";
import { invalidProvider } from "@smithy/invalid-dependency";
import {
DEFAULT_DISABLE_REQUEST_COMPRESSION,
DEFAULT_NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES,
} from "@smithy/middleware-compression";
import { calculateBodyLength } from "@smithy/util-body-length-browser";
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@smithy/util-retry";
import { CloudWatchClientConfig } from "./CloudWatchClient";
Expand All @@ -32,9 +36,12 @@ export const getRuntimeConfig = (config: CloudWatchClientConfig) => {
defaultUserAgentProvider:
config?.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
disableRequestCompression: config?.disableRequestCompression ?? DEFAULT_DISABLE_REQUEST_COMPRESSION,
maxAttempts: config?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
region: config?.region ?? invalidProvider("Region is missing"),
requestHandler: config?.requestHandler ?? new RequestHandler(defaultConfigProvider),
requestMinCompressionSizeBytes:
config?.requestMinCompressionSizeBytes ?? DEFAULT_NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES,
retryMode: config?.retryMode ?? (async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE),
sha256: config?.sha256 ?? Sha256,
streamCollector: config?.streamCollector ?? streamCollector,
Expand Down
8 changes: 8 additions & 0 deletions clients/client-cloudwatch/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS,
} from "@smithy/config-resolver";
import { Hash } from "@smithy/hash-node";
import {
NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS,
NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_CONFIG_OPTIONS,
} from "@smithy/middleware-compression";
import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@smithy/middleware-retry";
import { loadConfig as loadNodeConfig } from "@smithy/node-config-provider";
import { NodeHttpHandler as RequestHandler, streamCollector } from "@smithy/node-http-handler";
Expand Down Expand Up @@ -44,9 +48,13 @@ export const getRuntimeConfig = (config: CloudWatchClientConfig) => {
defaultUserAgentProvider:
config?.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
disableRequestCompression:
config?.disableRequestCompression ?? loadNodeConfig(NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS),
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
region: config?.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
requestHandler: config?.requestHandler ?? new RequestHandler(defaultConfigProvider),
requestMinCompressionSizeBytes:
config?.requestMinCompressionSizeBytes ?? loadNodeConfig(NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_CONFIG_OPTIONS),
retryMode:
config?.retryMode ??
loadNodeConfig({
Expand Down
3 changes: 3 additions & 0 deletions codegen/sdk-codegen/aws-models/cloudwatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5955,6 +5955,9 @@
}
],
"traits": {
"smithy.api#requestCompression": {
"encodings": ["gzip"]
},
"smithy.api#documentation": "<p>Publishes metric data points to Amazon CloudWatch. CloudWatch associates\n\t\t\tthe data points with the specified metric. If the specified metric does not exist,\n\t\t\tCloudWatch creates the metric. When CloudWatch creates a metric, it can\n\t\t\ttake up to fifteen minutes for the metric to appear in calls to <a href=\"https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_ListMetrics.html\">ListMetrics</a>.</p>\n <p>You can publish either individual data points in the <code>Value</code> field, or \n\t\tarrays of values and the number of times each value occurred during the period by using the \n\t\t<code>Values</code> and <code>Counts</code> fields in the <code>MetricDatum</code> structure. Using\n\t\tthe <code>Values</code> and <code>Counts</code> method enables you to publish up to 150 values per metric\n\t\t\twith one <code>PutMetricData</code> request, and\n\t\tsupports retrieving percentile statistics on this data.</p>\n <p>Each <code>PutMetricData</code> request is limited to 1 MB in size for HTTP POST requests. You can \n\t\t\tsend a payload compressed by gzip. Each request\n\t\tis also limited to no more than 1000 different metrics.</p>\n <p>Although the <code>Value</code> parameter accepts numbers of type\n\t\t\t<code>Double</code>, CloudWatch rejects values that are either too small\n\t\t\tor too large. Values must be in the range of -2^360 to 2^360. In addition, special values (for example, NaN, +Infinity,\n\t\t\t-Infinity) are not supported.</p>\n <p>You can use up to 30 dimensions per metric to further clarify what data the metric collects. Each dimension\n\t\t\tconsists of a Name and Value pair. For more information about specifying dimensions, see <a href=\"https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html\">Publishing Metrics</a> in the\n\t\t\t<i>Amazon CloudWatch User Guide</i>.</p>\n <p>You specify the time stamp to be associated with each data point. You can specify\n\t\ttime stamps that are as much as two weeks before the current date, and as much as 2 hours after \n\t\tthe current day and time.</p>\n <p>Data points with time stamps from 24 hours ago or longer can take at least 48\n\t\t\thours to become available for <a href=\"https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html\">GetMetricData</a> or \n\t\t\t<a href=\"https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html\">GetMetricStatistics</a> from the time they \n\t\t\tare submitted. Data points with time stamps between 3 and 24 hours ago can take as much as 2 hours to become available\n\t\t\tfor for <a href=\"https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html\">GetMetricData</a> or \n\t\t\t<a href=\"https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html\">GetMetricStatistics</a>.</p>\n <p>CloudWatch needs raw data points to calculate percentile statistics. If you publish \n\t\t\tdata using a statistic set instead, you can only retrieve \n\t\t\tpercentile statistics for this data if one of the following conditions is true:</p>\n <ul>\n <li>\n <p>The <code>SampleCount</code> value of the statistic set is 1 and <code>Min</code>,\n\t\t\t\t\t<code>Max</code>, and <code>Sum</code> are all equal.</p>\n </li>\n <li>\n <p>The <code>Min</code> and\n\t\t\t\t\t<code>Max</code> are equal, and <code>Sum</code> is equal to <code>Min</code> \n\t\t\t\t\tmultiplied by <code>SampleCount</code>.</p>\n </li>\n </ul>"
}
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-clients/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Update this commit when taking up new changes from smithy-typescript.
module.exports = {
// Use full commit hash as we explicitly fetch it.
SMITHY_TS_COMMIT: "e3b13dda0891091282c27cd65cc72b87826753b6",
SMITHY_TS_COMMIT: "codegen-request-compression",
};
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2982,6 +2982,17 @@
"@smithy/types" "^2.8.0"
tslib "^2.5.0"

"@smithy/middleware-compression@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@smithy/middleware-compression/-/middleware-compression-2.0.0.tgz#27f61af9ed0ef42820d7ad53c1a51610b3db60e1"
integrity sha512-o/1gfgkg+x1o5XAAklFYfGeZzM+sGZviFrFJ4QiVVn73f9bBQNbQJAho+yYPOaSs8yKiL89yN41Z9t6o2jQ4LA==
dependencies:
"@smithy/node-config-provider" "^2.1.9"
"@smithy/types" "^2.8.0"
"@smithy/util-config-provider" "^2.1.0"
fflate "0.8.1"
tslib "^2.5.0"

"@smithy/middleware-content-length@^2.0.18":
version "2.0.18"
resolved "https://registry.yarnpkg.com/@smithy/middleware-content-length/-/middleware-content-length-2.0.18.tgz#a3b13beb300290f5d0d48ace0f818e44261356fa"
Expand Down