From c6d4867cddf88ed4d15c16eeb7177add78d95618 Mon Sep 17 00:00:00 2001 From: awstools Date: Mon, 12 Feb 2024 19:14:16 +0000 Subject: [PATCH] feat(client-cloudwatch): This release enables PutMetricData API request payload compression by default. --- clients/client-cloudwatch/package.json | 1 + clients/client-cloudwatch/src/CloudWatchClient.ts | 14 +++++++++++--- .../src/commands/PutMetricDataCommand.ts | 2 ++ .../client-cloudwatch/src/runtimeConfig.browser.ts | 7 +++++++ clients/client-cloudwatch/src/runtimeConfig.ts | 8 ++++++++ codegen/sdk-codegen/aws-models/cloudwatch.json | 5 ++++- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/clients/client-cloudwatch/package.json b/clients/client-cloudwatch/package.json index f5b83ae340cc..6abef7628009 100644 --- a/clients/client-cloudwatch/package.json +++ b/clients/client-cloudwatch/package.json @@ -38,6 +38,7 @@ "@smithy/fetch-http-handler": "^2.4.1", "@smithy/hash-node": "^2.1.1", "@smithy/invalid-dependency": "^2.1.1", + "@smithy/middleware-compression": "^2.1.1", "@smithy/middleware-content-length": "^2.1.1", "@smithy/middleware-endpoint": "^2.4.1", "@smithy/middleware-retry": "^2.1.1", diff --git a/clients/client-cloudwatch/src/CloudWatchClient.ts b/clients/client-cloudwatch/src/CloudWatchClient.ts index dc6bb4b9dfd1..8c90571f4f1b 100644 --- a/clients/client-cloudwatch/src/CloudWatchClient.ts +++ b/clients/client-cloudwatch/src/CloudWatchClient.ts @@ -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"; @@ -364,6 +369,7 @@ export type CloudWatchClientConfigType = Partial<__SmithyConfiguration<__HttpHan HostHeaderInputConfig & AwsAuthInputConfig & UserAgentInputConfig & + CompressionInputConfig & ClientInputEndpointParameters; /** * @public @@ -384,6 +390,7 @@ export type CloudWatchClientResolvedConfigType = __SmithyResolvedConfiguration<_ HostHeaderResolvedConfig & AwsAuthResolvedConfig & UserAgentResolvedConfig & + CompressionResolvedConfig & ClientResolvedEndpointParameters; /** * @public @@ -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)); diff --git a/clients/client-cloudwatch/src/commands/PutMetricDataCommand.ts b/clients/client-cloudwatch/src/commands/PutMetricDataCommand.ts index ea8ba061d115..aacf9da30496 100644 --- a/clients/client-cloudwatch/src/commands/PutMetricDataCommand.ts +++ b/clients/client-cloudwatch/src/commands/PutMetricDataCommand.ts @@ -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"; @@ -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", {}) diff --git a/clients/client-cloudwatch/src/runtimeConfig.browser.ts b/clients/client-cloudwatch/src/runtimeConfig.browser.ts index 902151a74e91..37ace1c17b48 100644 --- a/clients/client-cloudwatch/src/runtimeConfig.browser.ts +++ b/clients/client-cloudwatch/src/runtimeConfig.browser.ts @@ -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"; @@ -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, diff --git a/clients/client-cloudwatch/src/runtimeConfig.ts b/clients/client-cloudwatch/src/runtimeConfig.ts index b2525aaf3a58..35d3e4db6091 100644 --- a/clients/client-cloudwatch/src/runtimeConfig.ts +++ b/clients/client-cloudwatch/src/runtimeConfig.ts @@ -12,6 +12,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"; @@ -42,9 +46,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({ diff --git a/codegen/sdk-codegen/aws-models/cloudwatch.json b/codegen/sdk-codegen/aws-models/cloudwatch.json index d4737c31ce45..9263ed653d12 100644 --- a/codegen/sdk-codegen/aws-models/cloudwatch.json +++ b/codegen/sdk-codegen/aws-models/cloudwatch.json @@ -5955,7 +5955,10 @@ } ], "traits": { - "smithy.api#documentation": "

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

\n

You can publish either individual data points in the Value field, or \n\t\tarrays of values and the number of times each value occurred during the period by using the \n\t\tValues and Counts fields in the MetricDatum structure. Using\n\t\tthe Values and Counts method enables you to publish up to 150 values per metric\n\t\t\twith one PutMetricData request, and\n\t\tsupports retrieving percentile statistics on this data.

\n

Each PutMetricData 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.

\n

Although the Value parameter accepts numbers of type\n\t\t\tDouble, 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.

\n

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 Publishing Metrics in the\n\t\t\tAmazon CloudWatch User Guide.

\n

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.

\n

Data points with time stamps from 24 hours ago or longer can take at least 48\n\t\t\thours to become available for GetMetricData or \n\t\t\tGetMetricStatistics 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 GetMetricData or \n\t\t\tGetMetricStatistics.

\n

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:

\n " + "smithy.api#documentation": "

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

\n

You can publish either individual data points in the Value field, or \n\t\tarrays of values and the number of times each value occurred during the period by using the \n\t\tValues and Counts fields in the MetricDatum structure. Using\n\t\tthe Values and Counts method enables you to publish up to 150 values per metric\n\t\t\twith one PutMetricData request, and\n\t\tsupports retrieving percentile statistics on this data.

\n

Each PutMetricData 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.

\n

Although the Value parameter accepts numbers of type\n\t\t\tDouble, 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.

\n

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 Publishing Metrics in the\n\t\t\tAmazon CloudWatch User Guide.

\n

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.

\n

Data points with time stamps from 24 hours ago or longer can take at least 48\n\t\t\thours to become available for GetMetricData or \n\t\t\tGetMetricStatistics 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 GetMetricData or \n\t\t\tGetMetricStatistics.

\n

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:

\n ", + "smithy.api#requestCompression": { + "encodings": ["gzip"] + } } }, "com.amazonaws.cloudwatch#PutMetricDataInput": {