mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 10:38:00 -05:00
feat(cloudwatch): create, read, update and delete resource metrics configurations (#10164)
Add CreateResourceMetricsConfiguration, GetResourceMetricsConfiguration,
UpdateResourceMetricsConfiguration and DeleteResourceMetricsConfiguration
over Query, JSON 1.0 and CBOR: at most one detailed monitoring
configuration per resource ARN, kept per account and Region. Floci stores
the configuration; collecting the selected metrics comes next.
The model is checked first, every violation in AWS's form, the metric
selection list quoted as AWS writes it. Then the ARN must name a resource
type ("ARN is missing resource type") and one with detailed monitoring
("Unsupported resource type"): the guides document only ElastiCache
replication groups. These refusals are ValidationError, the JSON body
naming com.amazon.coral.validate#ValidationException, as recorded from
AWS. A second create is ConflictException (409) and a missing
configuration ResourceNotFoundException (404), each with its exception's
model documentation, as AWS quotes no message. An update replaces the
selections, and one without them collects every metric.
DeleteReplicationGroup fires a ReplicationGroupDeleted event, and the
configuration of the deleted group is deleted with it, as the ElastiCache
user guide says. SmithyValidationErrors.Violations gains sizeOutOfRange, the quoted
twin of the list-size violation.
Part of #7030.
This commit is contained in:
1 parent
1f5c7abaaf
commit
bece631041
28 files changed
+1044
-33
No files matched your search
+82
@@ -0,0 +1,82 @@
|
||||
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.ConflictException;
|
||||
import software.amazon.awssdk.services.cloudwatch.model.ResourceMetricSelection;
|
||||
import software.amazon.awssdk.services.cloudwatch.model.ResourceMetricsConfiguration;
|
||||
import software.amazon.awssdk.services.cloudwatch.model.ResourceNotFoundException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
@DisplayName("CloudWatch resource metrics configuration")
|
||||
class CloudWatchResourceMetricsConfigurationTest {
|
||||
|
||||
// An account of its own, so no other test class touches the same configurations.
|
||||
private static final String ACCOUNT_ID = "797979797979";
|
||||
private static final StaticCredentialsProvider ACCOUNT =
|
||||
StaticCredentialsProvider.create(AwsBasicCredentials.create(ACCOUNT_ID, "test"));
|
||||
|
||||
@Test
|
||||
@DisplayName("creates, reads, replaces and deletes the configuration of a replication group")
|
||||
void configurationLifecycle() {
|
||||
try (CloudWatchClient cloudWatch = client()) {
|
||||
String arn = "arn:aws:elasticache:" + TestFixtures.region() + ":" + ACCOUNT_ID
|
||||
+ ":replicationgroup:compat-lifecycle";
|
||||
ResourceMetricSelection memory = ResourceMetricSelection.builder()
|
||||
.includeMetrics("valkey.memory.used").build();
|
||||
|
||||
ResourceMetricsConfiguration created = cloudWatch.createResourceMetricsConfiguration(request -> request
|
||||
.resourceArn(arn).metricSelections(memory)).resourceMetricsConfiguration();
|
||||
try {
|
||||
assertThat(created.resourceArn()).isEqualTo(arn);
|
||||
assertThat(created.metricSelections()).singleElement()
|
||||
.satisfies(selection -> assertThat(selection.includeMetrics())
|
||||
.containsExactly("valkey.memory.used"));
|
||||
assertThat(created.createdAt()).isNotNull();
|
||||
assertThatThrownBy(() -> cloudWatch.createResourceMetricsConfiguration(request -> request
|
||||
.resourceArn(arn))).isInstanceOf(ConflictException.class);
|
||||
|
||||
ResourceMetricsConfiguration replaced = cloudWatch.updateResourceMetricsConfiguration(request ->
|
||||
request.resourceArn(arn)).resourceMetricsConfiguration();
|
||||
assertThat(replaced.hasMetricSelections()).isFalse();
|
||||
assertThat(replaced.createdAt()).isEqualTo(created.createdAt());
|
||||
assertThat(cloudWatch.getResourceMetricsConfiguration(request -> request.resourceArn(arn))
|
||||
.resourceMetricsConfiguration().hasMetricSelections()).isFalse();
|
||||
} finally {
|
||||
cloudWatch.deleteResourceMetricsConfiguration(request -> request.resourceArn(arn));
|
||||
}
|
||||
|
||||
assertThatThrownBy(() -> cloudWatch.getResourceMetricsConfiguration(request -> request.resourceArn(arn)))
|
||||
.isInstanceOf(ResourceNotFoundException.class)
|
||||
.hasMessageContaining("The named resource does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("refuses a resource type without detailed monitoring as a ValidationError")
|
||||
void unsupportedResourceType() {
|
||||
try (CloudWatchClient cloudWatch = client()) {
|
||||
String table = "arn:aws:dynamodb:" + TestFixtures.region() + ":" + ACCOUNT_ID + ":table/compat";
|
||||
|
||||
assertThatThrownBy(() -> cloudWatch.getResourceMetricsConfiguration(request -> request.resourceArn(table)))
|
||||
.isInstanceOf(CloudWatchException.class)
|
||||
.hasMessageContaining("Unsupported resource type")
|
||||
.satisfies(e -> {
|
||||
CloudWatchException refused = (CloudWatchException) e;
|
||||
assertThat(refused.statusCode()).isEqualTo(400);
|
||||
assertThat(refused.awsErrorDetails().errorCode()).isEqualTo("ValidationError");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static CloudWatchClient client() {
|
||||
return CloudWatchClient.builder().endpointOverride(TestFixtures.endpoint())
|
||||
.region(TestFixtures.region()).credentialsProvider(ACCOUNT).build();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user