This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 31b03eaf7769 CAMEL-28029: camel-aws2-cw - enforce the PutMetricData
batch limit and convert the dimensions header (#31261)
31b03eaf7769 is described below
commit 31b03eaf7769ffb1293379d01cacae95274c5c27
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Dec 3 14:26:37 2026 +0100
CAMEL-28029: camel-aws2-cw - enforce the PutMetricData batch limit and
convert the dimensions header (#31261)
* CAMEL-28029: camel-aws2-cw - enforce the PutMetricData batch limit and
convert the dimensions header
putMetricData passed a collection or array body straight through, so a
body with more than the 1000 MetricDatum
Amazon CloudWatch accepts failed the whole exchange with an opaque
service error after a full round trip. Fail
locally instead, with a message that gives the size, in the style of
CAMEL-27307.
The CamelAwsCwMetricDimensions header was read as a raw Map and its
entries cast to String, so a map carrying
numbers or booleans (easy to build with a Simple expression) threw a bare
ClassCastException from inside the
producer. Convert the keys and values through the type converter in the
three places that read the header, and
fail with a message naming the header when an entry cannot be converted.
Document the four operations, the batch limit and the dimensions
conversion.
* CAMEL-28029: camel-aws2-cw - listMetrics keeps a null dimension value,
the supplied-client test detects a close, upgrade note
Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Andrea Cosentino <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
---
.../camel/catalog/docs/aws2-cw-component.adoc | 32 ++++++++++++
.../src/main/docs/aws2-cw-component.adoc | 32 ++++++++++++
.../camel/component/aws2/cw/Cw2Producer.java | 61 ++++++++++++++++++----
.../component/aws2/cw/CloudWatchClientMock.java | 12 +++++
.../camel/component/aws2/cw/CwComponentTest.java | 22 +++++++-
.../cw/CwEndpointRestartSuppliedClientTest.java | 50 ++++++++++++++++++
.../component/aws2/cw/CwEndpointRestartTest.java | 49 +++++++++++++++++
.../component/aws2/cw/CwPutMetricDataTest.java | 38 ++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_25.adoc | 6 +++
9 files changed, 290 insertions(+), 12 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-cw-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-cw-component.adoc
index 7915bf553988..01c4690e619a 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-cw-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws2-cw-component.adoc
@@ -189,3 +189,35 @@ option.
The unit is the name of a `StandardUnit` of the AWS SDK, such as `Count`,
`Bytes` or `Kilobytes/Second`, in any case;
an unknown unit fails the exchange. The timestamp header is an `Instant` or a
`java.util.Date`.
+
+Amazon CloudWatch accepts at most 1000 `MetricDatum` in one `PutMetricData`
call. A larger body fails the exchange
+locally, with a message that gives the size, instead of being rejected by the
service after a full round trip; split
+the body first, for example with the split EIP.
+
+=== Operations
+
+[cols="1,3"]
+|===
+| Operation | Description
+
+| `putMetricData`
+| Puts the metric data of the body, or of the headers and options. See
<<_the_metric_data_of_putmetricdata>>.
+
+| `listMetrics`
+| Lists the metrics, filtered by the `CamelAwsCwMetricNamespace` and
`CamelAwsCwMetricName` headers (or the `namespace`
+and `name` options) and by the `CamelAwsCwMetricDimensions` header. The body
is the `ListMetricsResponse`. The producer
+sets `CamelAwsCwNextToken` and `CamelAwsCwIsTruncated`; send the next token
back in `CamelAwsCwNextToken` for the next
+page.
+
+| `describeAlarms`
+| Describes the alarms. The body is the `DescribeAlarmsResponse`.
+
+| `describeAlarmsForMetric`
+| Describes the alarms of one metric. The namespace and the metric name are
required, from the headers or the options,
+and the `CamelAwsCwMetricDimensions` header narrows the metric further. The
body is the
+`DescribeAlarmsForMetricResponse`.
+|===
+
+The `CamelAwsCwMetricDimensions` header is a `Map`. Its keys and values are
converted to `String`, so a map built with
+a Simple expression, which often carries numbers or booleans, works; an entry
that cannot be converted fails the
+exchange with a message that names the header.
diff --git
a/components/camel-aws/camel-aws2-cw/src/main/docs/aws2-cw-component.adoc
b/components/camel-aws/camel-aws2-cw/src/main/docs/aws2-cw-component.adoc
index 7915bf553988..01c4690e619a 100644
--- a/components/camel-aws/camel-aws2-cw/src/main/docs/aws2-cw-component.adoc
+++ b/components/camel-aws/camel-aws2-cw/src/main/docs/aws2-cw-component.adoc
@@ -189,3 +189,35 @@ option.
The unit is the name of a `StandardUnit` of the AWS SDK, such as `Count`,
`Bytes` or `Kilobytes/Second`, in any case;
an unknown unit fails the exchange. The timestamp header is an `Instant` or a
`java.util.Date`.
+
+Amazon CloudWatch accepts at most 1000 `MetricDatum` in one `PutMetricData`
call. A larger body fails the exchange
+locally, with a message that gives the size, instead of being rejected by the
service after a full round trip; split
+the body first, for example with the split EIP.
+
+=== Operations
+
+[cols="1,3"]
+|===
+| Operation | Description
+
+| `putMetricData`
+| Puts the metric data of the body, or of the headers and options. See
<<_the_metric_data_of_putmetricdata>>.
+
+| `listMetrics`
+| Lists the metrics, filtered by the `CamelAwsCwMetricNamespace` and
`CamelAwsCwMetricName` headers (or the `namespace`
+and `name` options) and by the `CamelAwsCwMetricDimensions` header. The body
is the `ListMetricsResponse`. The producer
+sets `CamelAwsCwNextToken` and `CamelAwsCwIsTruncated`; send the next token
back in `CamelAwsCwNextToken` for the next
+page.
+
+| `describeAlarms`
+| Describes the alarms. The body is the `DescribeAlarmsResponse`.
+
+| `describeAlarmsForMetric`
+| Describes the alarms of one metric. The namespace and the metric name are
required, from the headers or the options,
+and the `CamelAwsCwMetricDimensions` header narrows the metric further. The
body is the
+`DescribeAlarmsForMetricResponse`.
+|===
+
+The `CamelAwsCwMetricDimensions` header is a `Map`. Its keys and values are
converted to `String`, so a map built with
+a Simple expression, which often carries numbers or booleans, works; an entry
that cannot be converted fails the
+exchange with a message that names the header.
diff --git
a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Producer.java
b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Producer.java
index b9ccd0ac7da6..cccb7c10184e 100644
---
a/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Producer.java
+++
b/components/camel-aws/camel-aws2-cw/src/main/java/org/apache/camel/component/aws2/cw/Cw2Producer.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
@@ -57,6 +58,9 @@ public class Cw2Producer extends DefaultProducer {
private static final Logger LOG =
LoggerFactory.getLogger(Cw2Producer.class);
+ /** The maximum number of MetricDatum that Amazon CloudWatch accepts in
one PutMetricData request. */
+ private static final int MAX_METRIC_DATA_PER_REQUEST = 1000;
+
private HealthCheck producerHealthCheck;
private WritableHealthCheckRepository healthCheckRepository;
private transient String cwProducerToString;
@@ -98,6 +102,13 @@ public class Cw2Producer extends DefaultProducer {
private void putMetricData(CloudWatchClient client, Exchange exchange) {
List<MetricDatum> metricData = getMetricData(exchange);
+ if (metricData.size() > MAX_METRIC_DATA_PER_REQUEST) {
+ // fail here, as Amazon CloudWatch rejects the whole request after
a full round trip
+ throw new IllegalArgumentException(
+ "The body has " + metricData.size() + " MetricDatum, but
Amazon CloudWatch accepts at most "
+ + MAX_METRIC_DATA_PER_REQUEST
+ + " in one putMetricData: split
the body, for example with the split EIP.");
+ }
PutMetricDataRequest.Builder builder = PutMetricDataRequest.builder();
builder.metricData(metricData).namespace(determineNameSpace(exchange));
@@ -127,10 +138,9 @@ public class Cw2Producer extends DefaultProducer {
builder.nextToken(nextToken);
}
- // Handle dimensions filter
- @SuppressWarnings("unchecked")
- Map<String, String> dimensions =
exchange.getIn().getHeader(Cw2Constants.METRIC_DIMENSIONS, Map.class);
- if (ObjectHelper.isNotEmpty(dimensions)) {
+ // Handle dimensions filter: a null value matches any value of the
dimension
+ Map<String, String> dimensions = determineDimensions(exchange, true);
+ if (!dimensions.isEmpty()) {
List<DimensionFilter> dimensionFilters = new ArrayList<>();
for (Map.Entry<String, String> entry : dimensions.entrySet()) {
dimensionFilters.add(DimensionFilter.builder()
@@ -192,9 +202,8 @@ public class Cw2Producer extends DefaultProducer {
builder.metricName(metricName);
// Handle dimensions
- @SuppressWarnings("unchecked")
- Map<String, String> dimensions =
exchange.getIn().getHeader(Cw2Constants.METRIC_DIMENSIONS, Map.class);
- if (ObjectHelper.isNotEmpty(dimensions)) {
+ Map<String, String> dimensions = determineDimensions(exchange, false);
+ if (!dimensions.isEmpty()) {
List<Dimension> dimensionList = new ArrayList<>();
for (Map.Entry<String, String> entry : dimensions.entrySet()) {
dimensionList.add(Dimension.builder()
@@ -256,9 +265,8 @@ public class Cw2Producer extends DefaultProducer {
if (ObjectHelper.isNotEmpty(name) && ObjectHelper.isNotEmpty(value)) {
metricDatum.dimensions(Dimension.builder().name(name).value(value).build());
} else {
- @SuppressWarnings("unchecked")
- Map<String, String> dimensions =
exchange.getIn().getHeader(Cw2Constants.METRIC_DIMENSIONS, Map.class);
- if (ObjectHelper.isNotEmpty(dimensions)) {
+ Map<String, String> dimensions = determineDimensions(exchange,
false);
+ if (!dimensions.isEmpty()) {
Collection<Dimension> dimensionCollection = new ArrayList<>();
for (Map.Entry<String, String> dimensionEntry :
dimensions.entrySet()) {
Dimension dimension
@@ -270,6 +278,39 @@ public class Cw2Producer extends DefaultProducer {
}
}
+ /**
+ * Reads the dimensions header as a map of strings. The entries are
converted, so that a map built with a Simple
+ * expression, which often holds numbers, does not fail with a
ClassCastException inside the producer. A null value
+ * is kept when {@code nullValueMatchesAny} is set: listMetrics sends a
DimensionFilter without a value, which
+ * matches any value of the dimension; the other operations build a
Dimension, which needs both parts, so a null
+ * value fails them.
+ */
+ private Map<String, String> determineDimensions(Exchange exchange, boolean
nullValueMatchesAny) {
+ Map<?, ?> dimensions =
exchange.getIn().getHeader(Cw2Constants.METRIC_DIMENSIONS, Map.class);
+ if (ObjectHelper.isEmpty(dimensions)) {
+ return Map.of();
+ }
+ Map<String, String> converted = new LinkedHashMap<>();
+ for (Map.Entry<?, ?> entry : dimensions.entrySet()) {
+ String name = convertDimensionPart(exchange, entry.getKey(),
"name");
+ String value = entry.getValue() == null && nullValueMatchesAny
+ ? null : convertDimensionPart(exchange, entry.getValue(),
"value");
+ converted.put(name, value);
+ }
+ return converted;
+ }
+
+ private String convertDimensionPart(Exchange exchange, Object part, String
kind) {
+ String converted =
exchange.getContext().getTypeConverter().tryConvertTo(String.class, exchange,
part);
+ if (converted == null) {
+ throw new IllegalArgumentException(
+ "The " + Cw2Constants.METRIC_DIMENSIONS + " header has an
entry whose " + kind
+ + " cannot be converted to a
String: "
+ + (part == null ? "null" :
part.getClass().getName()));
+ }
+ return converted;
+ }
+
private Instant determineTimestamp(Exchange exchange) {
if (exchange.getIn().getHeader(Cw2Constants.METRIC_TIMESTAMP)
instanceof Date date) {
return date.toInstant();
diff --git
a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CloudWatchClientMock.java
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CloudWatchClientMock.java
index ce8361925d90..5c19cc3e9e35 100644
---
a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CloudWatchClientMock.java
+++
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CloudWatchClientMock.java
@@ -35,11 +35,21 @@ import
software.amazon.awssdk.services.cloudwatch.model.PutMetricDataResponse;
public class CloudWatchClientMock implements CloudWatchClient {
private PutMetricDataRequest lastPutMetricDataRequest;
+ private ListMetricsRequest lastListMetricsRequest;
+ private boolean closed;
public PutMetricDataRequest getLastPutMetricDataRequest() {
return lastPutMetricDataRequest;
}
+ public ListMetricsRequest getLastListMetricsRequest() {
+ return lastListMetricsRequest;
+ }
+
+ public boolean isClosed() {
+ return closed;
+ }
+
@Override
public String serviceName() {
return null;
@@ -47,6 +57,7 @@ public class CloudWatchClientMock implements CloudWatchClient
{
@Override
public void close() {
+ closed = true;
}
@Override
@@ -58,6 +69,7 @@ public class CloudWatchClientMock implements CloudWatchClient
{
@Override
public ListMetricsResponse listMetrics(ListMetricsRequest request) {
+ lastListMetricsRequest = request;
List<Metric> metrics = new ArrayList<>();
metrics.add(Metric.builder()
.namespace("TestNamespace")
diff --git
a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentTest.java
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentTest.java
index 5425c8115588..c56a812ae24b 100644
---
a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentTest.java
+++
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwComponentTest.java
@@ -17,6 +17,8 @@
package org.apache.camel.component.aws2.cw;
import java.time.Instant;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.camel.BindToRegistry;
import org.apache.camel.EndpointInject;
@@ -27,15 +29,16 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Test;
-import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
import
software.amazon.awssdk.services.cloudwatch.model.DescribeAlarmsForMetricResponse;
import software.amazon.awssdk.services.cloudwatch.model.DescribeAlarmsResponse;
+import software.amazon.awssdk.services.cloudwatch.model.DimensionFilter;
import software.amazon.awssdk.services.cloudwatch.model.ListMetricsResponse;
import software.amazon.awssdk.services.cloudwatch.model.StandardUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class CwComponentTest extends CamelTestSupport {
@@ -45,7 +48,7 @@ public class CwComponentTest extends CamelTestSupport {
public static final Instant LATER = Instant.ofEpochMilli(NOW.getNano() +
1);
@BindToRegistry("amazonCwClient")
- private CloudWatchClient cloudWatchClient = new CloudWatchClientMock();
+ private CloudWatchClientMock cloudWatchClient = new CloudWatchClientMock();
@EndpointInject("mock:result")
private MockEndpoint mock;
@@ -81,6 +84,21 @@ public class CwComponentTest extends CamelTestSupport {
assertFalse(exchange.getMessage().getHeader(Cw2Constants.IS_TRUNCATED,
Boolean.class));
}
+ @Test
+ public void listMetricsKeepsANullDimensionValueToMatchAnyValue() {
+ Map<String, String> dimensions = new HashMap<>();
+ dimensions.put("InstanceId", null);
+ Exchange exchange = template.send("direct:listMetrics",
ExchangePattern.InOut, e -> {
+ e.getIn().setHeader(Cw2Constants.METRIC_NAMESPACE,
"TestNamespace");
+ e.getIn().setHeader(Cw2Constants.METRIC_DIMENSIONS, dimensions);
+ });
+
+ assertNull(exchange.getException(), "a null value is a filter on the
name only, not an error");
+ DimensionFilter filter =
cloudWatchClient.getLastListMetricsRequest().dimensions().get(0);
+ assertEquals("InstanceId", filter.name());
+ assertNull(filter.value(), "no value is sent, so the filter matches
any value of the dimension");
+ }
+
@Test
public void describeAlarms() throws Exception {
Exchange exchange = template.send("direct:describeAlarms",
ExchangePattern.InOut, new Processor() {
diff --git
a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwEndpointRestartSuppliedClientTest.java
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwEndpointRestartSuppliedClientTest.java
new file mode 100644
index 000000000000..863844b689ee
--- /dev/null
+++
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwEndpointRestartSuppliedClientTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws2.cw;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+/**
+ * A client the user supplies is not owned by the endpoint: doStop must not
close it, and a restart must keep using it.
+ */
+public class CwEndpointRestartSuppliedClientTest extends CamelTestSupport {
+
+ @BindToRegistry("amazonCwClient")
+ private final CloudWatchClientMock suppliedClient = new
CloudWatchClientMock();
+
+ @Test
+ public void aClientTheUserSuppliedSurvivesARestart() throws Exception {
+ Cw2Endpoint endpoint = context.getEndpoint(
+ "aws2-cw://namespace?amazonCwClient=#amazonCwClient",
Cw2Endpoint.class);
+
+ endpoint.start();
+ assertSame(suppliedClient, endpoint.getCloudWatchClient());
+ endpoint.stop();
+ assertFalse(suppliedClient.isClosed(), "doStop must not close a client
the user supplied");
+
+ endpoint.start();
+ assertSame(suppliedClient, endpoint.getCloudWatchClient(),
+ "a client the user supplied is never closed, and stays in use
after a restart");
+ endpoint.stop();
+ assertFalse(suppliedClient.isClosed(), "doStop must not close a client
the user supplied");
+ }
+}
diff --git
a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwEndpointRestartTest.java
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwEndpointRestartTest.java
new file mode 100644
index 000000000000..5a0c43c05f1c
--- /dev/null
+++
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwEndpointRestartTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws2.cw;
+
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
+
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+
+/**
+ * doStop closes the client the endpoint created, so a restart must leave the
endpoint with a usable client. It does,
+ * because BaseService.init runs doInit again once the service is STOPPED.
This test guards that pairing: moving the
+ * creation out of doInit, or making it run only once, would leave a restarted
endpoint holding a closed client.
+ *
+ * No client is bound in the registry here on purpose: an autowired one would
be treated as user supplied, and the
+ * endpoint would neither create nor close it.
+ */
+public class CwEndpointRestartTest extends CamelTestSupport {
+
+ @Test
+ public void aClientTheEndpointOwnsIsRecreatedOnRestart() throws Exception {
+ Cw2Endpoint endpoint = context.getEndpoint(
+
"aws2-cw://namespace?accessKey=key&secretKey=secret®ion=eu-west-1",
Cw2Endpoint.class);
+
+ endpoint.start();
+ CloudWatchClient beforeRestart = endpoint.getCloudWatchClient();
+ endpoint.stop();
+
+ endpoint.start();
+ assertNotSame(beforeRestart, endpoint.getCloudWatchClient(),
+ "doStop closed the first client, so the restart must leave a
new one behind");
+ endpoint.stop();
+ }
+}
diff --git
a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwPutMetricDataTest.java
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwPutMetricDataTest.java
index 7f38fa42dd4e..e7a98acadf50 100644
---
a/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwPutMetricDataTest.java
+++
b/components/camel-aws/camel-aws2-cw/src/test/java/org/apache/camel/component/aws2/cw/CwPutMetricDataTest.java
@@ -18,15 +18,19 @@ package org.apache.camel.component.aws2.cw;
import java.time.Instant;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.stream.IntStream;
import org.apache.camel.BindToRegistry;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.cloudwatch.model.Dimension;
import software.amazon.awssdk.services.cloudwatch.model.MetricDatum;
import software.amazon.awssdk.services.cloudwatch.model.StandardUnit;
@@ -168,6 +172,40 @@ public class CwPutMetricDataTest extends CamelTestSupport {
assertTrue(cause.getMessage().contains("Unknown unit Bananas"),
cause.getMessage());
}
+ @Test
+ public void atMostOneThousandMetricDatumAreSent() {
+ List<MetricDatum> body = IntStream.range(0, 1000).mapToObj(i ->
datum("metric" + i)).toList();
+ template.sendBody("direct:start", body);
+
+ assertEquals(1000, sentMetricData().size());
+ }
+
+ @Test
+ public void moreThanOneThousandMetricDatumFailsLocally() {
+ List<MetricDatum> body = IntStream.range(0, 1001).mapToObj(i ->
datum("metric" + i)).toList();
+
+ CamelExecutionException e
+ = assertThrows(CamelExecutionException.class, () ->
template.sendBody("direct:start", body));
+ IllegalArgumentException cause =
assertInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertTrue(cause.getMessage().contains("1001 MetricDatum"),
cause.getMessage());
+ assertTrue(cause.getMessage().contains("at most 1000"),
cause.getMessage());
+ }
+
+ @Test
+ public void dimensionsHeaderValuesAreConverted() {
+ Map<String, Object> dimensions = new LinkedHashMap<>();
+ dimensions.put("instance", 42);
+ dimensions.put("enabled", true);
+ template.sendBodyAndHeader("direct:start", null,
Cw2Constants.METRIC_DIMENSIONS, dimensions);
+
+ List<Dimension> sent = sentMetricData().get(0).dimensions();
+ assertEquals(2, sent.size());
+ assertEquals("instance", sent.get(0).name());
+ assertEquals("42", sent.get(0).value());
+ assertEquals("enabled", sent.get(1).name());
+ assertEquals("true", sent.get(1).value());
+ }
+
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
index df41cd8ff74c..1ebdb6789f69 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_25.adoc
@@ -331,6 +331,12 @@ these now require `citrus-validation-text` to be on the
classpath to avoid falli
Note: the `gzip` message type (without base64 encoding) has been removed from
the documented types.
Use `gzip_base64` instead (requires `citrus-validation-text`).
+=== camel-aws2-cw - putMetricData rejects more than 1000 metric data items
before the call
+
+A `putMetricData` body with more than 1000 `MetricDatum` items now fails the
exchange with an `IllegalArgumentException`
+before any request is sent. Before, the request was sent and CloudWatch
rejected it with a `CloudWatchException`. A
+route that handled that exception type for this case must now handle the
`IllegalArgumentException` instead.
+
=== camel-aws2-translate - a String CamelAwsTranslateTerminologyNames header
is used, and other types fail
The `CamelAwsTranslateTerminologyNames` header can now be a `String` with one
terminology name or names separated by