Skip to content

Commit c6d4867

Browse files
author
awstools
committed
feat(client-cloudwatch): This release enables PutMetricData API request payload compression by default.
1 parent 06af293 commit c6d4867

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

clients/client-cloudwatch/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@smithy/fetch-http-handler": "^2.4.1",
3939
"@smithy/hash-node": "^2.1.1",
4040
"@smithy/invalid-dependency": "^2.1.1",
41+
"@smithy/middleware-compression": "^2.1.1",
4142
"@smithy/middleware-content-length": "^2.1.1",
4243
"@smithy/middleware-endpoint": "^2.4.1",
4344
"@smithy/middleware-retry": "^2.1.1",

clients/client-cloudwatch/src/CloudWatchClient.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import {
2121
} from "@aws-sdk/middleware-user-agent";
2222
import { Credentials as __Credentials } from "@aws-sdk/types";
2323
import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver";
24+
import {
25+
CompressionInputConfig,
26+
CompressionResolvedConfig,
27+
resolveCompressionConfig,
28+
} from "@smithy/middleware-compression";
2429
import { getContentLengthPlugin } from "@smithy/middleware-content-length";
2530
import { EndpointInputConfig, EndpointResolvedConfig, resolveEndpointConfig } from "@smithy/middleware-endpoint";
2631
import { getRetryPlugin, resolveRetryConfig, RetryInputConfig, RetryResolvedConfig } from "@smithy/middleware-retry";
@@ -364,6 +369,7 @@ export type CloudWatchClientConfigType = Partial<__SmithyConfiguration<__HttpHan
364369
HostHeaderInputConfig &
365370
AwsAuthInputConfig &
366371
UserAgentInputConfig &
372+
CompressionInputConfig &
367373
ClientInputEndpointParameters;
368374
/**
369375
* @public
@@ -384,6 +390,7 @@ export type CloudWatchClientResolvedConfigType = __SmithyResolvedConfiguration<_
384390
HostHeaderResolvedConfig &
385391
AwsAuthResolvedConfig &
386392
UserAgentResolvedConfig &
393+
CompressionResolvedConfig &
387394
ClientResolvedEndpointParameters;
388395
/**
389396
* @public
@@ -428,9 +435,10 @@ export class CloudWatchClient extends __Client<
428435
const _config_5 = resolveHostHeaderConfig(_config_4);
429436
const _config_6 = resolveAwsAuthConfig(_config_5);
430437
const _config_7 = resolveUserAgentConfig(_config_6);
431-
const _config_8 = resolveRuntimeExtensions(_config_7, configuration?.extensions || []);
432-
super(_config_8);
433-
this.config = _config_8;
438+
const _config_8 = resolveCompressionConfig(_config_7);
439+
const _config_9 = resolveRuntimeExtensions(_config_8, configuration?.extensions || []);
440+
super(_config_9);
441+
this.config = _config_9;
434442
this.middlewareStack.use(getRetryPlugin(this.config));
435443
this.middlewareStack.use(getContentLengthPlugin(this.config));
436444
this.middlewareStack.use(getHostHeaderPlugin(this.config));

clients/client-cloudwatch/src/commands/PutMetricDataCommand.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// smithy-typescript generated code
2+
import { getCompressionPlugin } from "@smithy/middleware-compression";
23
import { getEndpointPlugin } from "@smithy/middleware-endpoint";
34
import { getSerdePlugin } from "@smithy/middleware-serde";
45
import { Command as $Command } from "@smithy/smithy-client";
@@ -150,6 +151,7 @@ export class PutMetricDataCommand extends $Command
150151
return [
151152
getSerdePlugin(config, this.serialize, this.deserialize),
152153
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
154+
getCompressionPlugin(config, { encodings: ["gzip"] }),
153155
];
154156
})
155157
.s("GraniteServiceVersion20100801", "PutMetricData", {})

clients/client-cloudwatch/src/runtimeConfig.browser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
77
import { DEFAULT_USE_DUALSTACK_ENDPOINT, DEFAULT_USE_FIPS_ENDPOINT } from "@smithy/config-resolver";
88
import { FetchHttpHandler as RequestHandler, streamCollector } from "@smithy/fetch-http-handler";
99
import { invalidProvider } from "@smithy/invalid-dependency";
10+
import {
11+
DEFAULT_DISABLE_REQUEST_COMPRESSION,
12+
DEFAULT_NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES,
13+
} from "@smithy/middleware-compression";
1014
import { calculateBodyLength } from "@smithy/util-body-length-browser";
1115
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@smithy/util-retry";
1216
import { CloudWatchClientConfig } from "./CloudWatchClient";
@@ -32,9 +36,12 @@ export const getRuntimeConfig = (config: CloudWatchClientConfig) => {
3236
defaultUserAgentProvider:
3337
config?.defaultUserAgentProvider ??
3438
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
39+
disableRequestCompression: config?.disableRequestCompression ?? DEFAULT_DISABLE_REQUEST_COMPRESSION,
3540
maxAttempts: config?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
3641
region: config?.region ?? invalidProvider("Region is missing"),
3742
requestHandler: config?.requestHandler ?? new RequestHandler(defaultConfigProvider),
43+
requestMinCompressionSizeBytes:
44+
config?.requestMinCompressionSizeBytes ?? DEFAULT_NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES,
3845
retryMode: config?.retryMode ?? (async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE),
3946
sha256: config?.sha256 ?? Sha256,
4047
streamCollector: config?.streamCollector ?? streamCollector,

clients/client-cloudwatch/src/runtimeConfig.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import {
1212
NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS,
1313
} from "@smithy/config-resolver";
1414
import { Hash } from "@smithy/hash-node";
15+
import {
16+
NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS,
17+
NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_CONFIG_OPTIONS,
18+
} from "@smithy/middleware-compression";
1519
import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@smithy/middleware-retry";
1620
import { loadConfig as loadNodeConfig } from "@smithy/node-config-provider";
1721
import { NodeHttpHandler as RequestHandler, streamCollector } from "@smithy/node-http-handler";
@@ -42,9 +46,13 @@ export const getRuntimeConfig = (config: CloudWatchClientConfig) => {
4246
defaultUserAgentProvider:
4347
config?.defaultUserAgentProvider ??
4448
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
49+
disableRequestCompression:
50+
config?.disableRequestCompression ?? loadNodeConfig(NODE_DISABLE_REQUEST_COMPRESSION_CONFIG_OPTIONS),
4551
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
4652
region: config?.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
4753
requestHandler: config?.requestHandler ?? new RequestHandler(defaultConfigProvider),
54+
requestMinCompressionSizeBytes:
55+
config?.requestMinCompressionSizeBytes ?? loadNodeConfig(NODE_REQUEST_MIN_COMPRESSION_SIZE_BYTES_CONFIG_OPTIONS),
4856
retryMode:
4957
config?.retryMode ??
5058
loadNodeConfig({

codegen/sdk-codegen/aws-models/cloudwatch.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5955,7 +5955,10 @@
59555955
}
59565956
],
59575957
"traits": {
5958-
"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>"
5958+
"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>",
5959+
"smithy.api#requestCompression": {
5960+
"encodings": ["gzip"]
5961+
}
59595962
}
59605963
},
59615964
"com.amazonaws.cloudwatch#PutMetricDataInput": {

0 commit comments

Comments
 (0)