feat(cloudwatch): start, read, update and stop OTel enrichment (#10130)

Add StartOTelEnrichment, GetOTelEnrichment, UpdateOTelEnrichment and
StopOTelEnrichment over Query, JSON 1.0 and CBOR, with one configuration
per account and Region as the user guide scopes it. Floci stores the
configuration; enriching vended metrics comes next.

Resource tag enrichment, the default, needs ObservabilityAdmin's resource
tags for telemetry running in the Region: a start without it is the
modeled ValidationError with the API reference's sentence, as AWS quotes
no message. EnableTagEnrichment false needs nothing. A start while
running changes nothing, an update replaces both filter lists as a pair
and keeps the stored tag setting it omits, and an update while stopped is
AWS's ResourceNotFoundException "OTel enrichment is not enabled for this
account". A stopped enrichment reads as its status alone.

Filters are validated as the model gives them, every violation listed in
AWS's form, then against the 100 selectors allowed across both lists. A
selector naming metrics without a namespace is refused as a null namespace
over Query too, for metric streams as well, rather than read as no selector.
Over JSON, a filter list sent as something else is refused with the
deserializer's SerializationException, and EnableTagEnrichment sent as a
string is read as the boolean it names or refused, so a malformed update
changes nothing.
Over Query, a filter name XML cannot carry is written as U+FFFD, for
metric streams too.

Part of #7030.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-12-03 22:58:23 -04:00
1 parent 570c8357a2
commit 00230a3612
20 files changed
+977 -31

No files matched your search

@@ -0,0 +1,63 @@
package com.floci.test;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
import software.amazon.awssdk.services.cloudwatch.model.CloudWatchException;
import software.amazon.awssdk.services.cloudwatch.model.GetOTelEnrichmentResponse;
import software.amazon.awssdk.services.cloudwatch.model.OTelEnrichmentMetricSelector;
import software.amazon.awssdk.services.cloudwatch.model.OTelEnrichmentStatus;
import software.amazon.awssdk.services.cloudwatch.model.ResourceNotFoundException;
import software.amazon.awssdk.services.observabilityadmin.ObservabilityAdminClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@DisplayName("CloudWatch OTel enrichment")
class CloudWatchOTelEnrichmentTest {
// An account of its own: test classes run concurrently, and another one toggles resource tags for telemetry in
// the default account.
private static final StaticCredentialsProvider ACCOUNT =
StaticCredentialsProvider.create(AwsBasicCredentials.create("747474747474", "test"));
@Test
@DisplayName("starts tag enrichment once resource tags for telemetry run, updates and stops it")
void enrichmentLifecycle() {
try (CloudWatchClient cloudWatch = CloudWatchClient.builder().endpointOverride(TestFixtures.endpoint())
.region(TestFixtures.region()).credentialsProvider(ACCOUNT).build();
ObservabilityAdminClient admin = ObservabilityAdminClient.builder()
.endpointOverride(TestFixtures.endpoint())
.region(TestFixtures.region()).credentialsProvider(ACCOUNT).build()) {
assertThat(cloudWatch.getOTelEnrichment(request -> { }).status()).isEqualTo(OTelEnrichmentStatus.STOPPED);
assertThatThrownBy(() -> cloudWatch.startOTelEnrichment(request -> { }))
.isInstanceOf(CloudWatchException.class)
.satisfies(e -> assertThat(((CloudWatchException) e).statusCode()).isEqualTo(400));
admin.startTelemetryEnrichment(request -> { });
try {
cloudWatch.startOTelEnrichment(request -> request.includeFilters(OTelEnrichmentMetricSelector.builder()
.namespace("AWS/EC2").metricNames("CPUUtilization").build()));
GetOTelEnrichmentResponse running = cloudWatch.getOTelEnrichment(request -> { });
assertThat(running.status()).isEqualTo(OTelEnrichmentStatus.RUNNING);
assertThat(running.includeFilters()).singleElement()
.satisfies(filter -> assertThat(filter.namespace()).isEqualTo("AWS/EC2"));
cloudWatch.updateOTelEnrichment(request -> request.includeFilters(OTelEnrichmentMetricSelector.builder()
.namespace("AWS/Lambda").build()));
assertThat(cloudWatch.getOTelEnrichment(request -> { }).includeFilters()).singleElement()
.satisfies(filter -> assertThat(filter.namespace()).isEqualTo("AWS/Lambda"));
} finally {
cloudWatch.stopOTelEnrichment(request -> { });
admin.stopTelemetryEnrichment(request -> { });
}
assertThat(cloudWatch.getOTelEnrichment(request -> { }).status()).isEqualTo(OTelEnrichmentStatus.STOPPED);
assertThatThrownBy(() -> cloudWatch.updateOTelEnrichment(request -> { }))
.isInstanceOf(ResourceNotFoundException.class)
.hasMessageContaining("OTel enrichment is not enabled for this account");
}
}
}