mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(elasticache): keep a replication group's log delivery configurations (#8846)
* fix(elasticache): keep a replication group's log delivery configurations * fix(elasticache): refuse a log delivery configuration with an unknown or missing value * fix(elasticache): settle log delivery to a missing log group as an error
This commit is contained in:
1 parent
9e65c12f8c
commit
66a9d647fb
9 files changed
+287
-13
No files matched your search
@@ -92,7 +92,7 @@ without authentication relays these commands to the engine as sent.
|
||||
| Action | Description |
|
||||
| --- | --- |
|
||||
| `ValidateIamAuthToken` | Validate an IAM auth token (data-plane auth) |
|
||||
| `CreateReplicationGroup` | Start a new Redis/Valkey cluster; `AtRestEncryptionEnabled`, `KmsKeyId` (resolved to the key ARN), `SnapshotRetentionLimit`, `SnapshotWindow`, `Tags` and `UserGroupIds` are kept and returned, with the group `ARN`. `UserGroupIds` needs `TransitEncryptionEnabled` or an `AuthToken` |
|
||||
| `CreateReplicationGroup` | Start a new Redis/Valkey cluster; `AtRestEncryptionEnabled`, `KmsKeyId` (resolved to the key ARN), `SnapshotRetentionLimit`, `SnapshotWindow`, `Tags`, `UserGroupIds` and `LogDeliveryConfigurations` are kept and returned, with the group `ARN`. Each enabled log delivery configuration reads back as `active`, or as `error` with a `Message` when it names a CloudWatch Logs group that does not exist (the group is not created); Floci delivers no logs. `UserGroupIds` needs `TransitEncryptionEnabled` or an `AuthToken` |
|
||||
| `DescribeReplicationGroups` | List clusters and their connection info |
|
||||
| `ModifyReplicationGroup` | Modify `SnapshotRetentionLimit` and `SnapshotWindow`, and the associated user groups (`UserGroupIdsToAdd`, `UserGroupIdsToRemove`, `RemoveUserGroups`). A cache with user groups no longer takes its AUTH token, `AuthTokenUpdateStrategy=DELETE` removes the token when adding a user group, and removing the last user group leaves the cache without access control. Changing the AUTH token (`ROTATE`, `SET`) is not supported |
|
||||
| `IncreaseReplicaCount` | Raise a cluster-mode-disabled group's replicas to `NewReplicaCount` (up to 5), with `ApplyImmediately=true`. See [Replicas and failover](#replicas-and-failover) |
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.floci.aws.services.elasticache;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.AwsNamespaces;
|
||||
import io.floci.aws.core.common.AwsQueryLists;
|
||||
import io.floci.aws.core.common.AwsQueryResponse;
|
||||
import io.floci.aws.core.common.AwsRegions;
|
||||
import io.floci.aws.core.common.BackupWindows;
|
||||
@@ -18,6 +19,7 @@ import io.floci.aws.services.elasticache.model.ElastiCacheSnapshot;
|
||||
import io.floci.aws.services.elasticache.model.ElastiCacheUser;
|
||||
import io.floci.aws.services.elasticache.model.ElastiCacheUserGroup;
|
||||
import io.floci.aws.services.elasticache.model.Endpoint;
|
||||
import io.floci.aws.services.elasticache.model.LogDeliveryConfiguration;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroup;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroupSettings;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroupStatus;
|
||||
@@ -153,7 +155,8 @@ public class ElastiCacheQueryHandler {
|
||||
replicationGroupSettings(params),
|
||||
parseTags(params),
|
||||
extractMemberList(params, "UserGroupIds.member."),
|
||||
parseSecurityGroupIds(params));
|
||||
parseSecurityGroupIds(params),
|
||||
parseLogDeliveryConfigurations(params));
|
||||
ReplicationGroup group = snapshotName != null && !snapshotName.isBlank()
|
||||
? service.createReplicationGroupFromSnapshot(request, snapshotName)
|
||||
: service.createReplicationGroup(request);
|
||||
@@ -176,6 +179,40 @@ public class ElastiCacheQueryHandler {
|
||||
boolParam(params, "TransitEncryptionEnabled"));
|
||||
}
|
||||
|
||||
private static final List<String> LOG_TYPES = List.of("slow-log", "engine-log");
|
||||
private static final List<String> LOG_DESTINATION_TYPES = List.of("cloudwatch-logs", "kinesis-firehose");
|
||||
private static final List<String> LOG_FORMATS = List.of("text", "json");
|
||||
|
||||
private static List<LogDeliveryConfiguration> parseLogDeliveryConfigurations(
|
||||
MultivaluedMap<String, String> params) {
|
||||
List<LogDeliveryConfiguration> configurations = new ArrayList<>();
|
||||
for (AwsQueryLists.IndexedMember entry
|
||||
: AwsQueryLists.members(params, "LogDeliveryConfigurations", "LogDeliveryConfigurationRequest")) {
|
||||
String member = entry.prefix() + ".";
|
||||
if ("false".equalsIgnoreCase(params.getFirst(member + "Enabled"))) {
|
||||
continue;
|
||||
}
|
||||
configurations.add(new LogDeliveryConfiguration(
|
||||
oneOf(params, member + "LogType", "LogType", LOG_TYPES),
|
||||
oneOf(params, member + "DestinationType", "DestinationType", LOG_DESTINATION_TYPES),
|
||||
params.getFirst(member + "DestinationDetails.CloudWatchLogsDetails.LogGroup"),
|
||||
params.getFirst(member + "DestinationDetails.KinesisFirehoseDetails.DeliveryStream"),
|
||||
oneOf(params, member + "LogFormat", "LogFormat", LOG_FORMATS),
|
||||
"active", null));
|
||||
}
|
||||
return configurations;
|
||||
}
|
||||
|
||||
private static String oneOf(MultivaluedMap<String, String> params, String param, String field,
|
||||
List<String> allowed) {
|
||||
String value = params.getFirst(param);
|
||||
if (value == null || !allowed.contains(value)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid " + field + " " + value + ". Valid values are " + String.join(", ", allowed) + ".", 400);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Integer optionalInt(String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
@@ -1272,6 +1309,29 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
return g.getAuthMode() == AuthMode.PASSWORD && g.getUserGroupIds().isEmpty();
|
||||
}
|
||||
|
||||
private static String logDeliveryConfigurationsXml(List<LogDeliveryConfiguration> configurations) {
|
||||
XmlBuilder xml = new XmlBuilder().start("LogDeliveryConfigurations");
|
||||
for (LogDeliveryConfiguration c : configurations) {
|
||||
xml.start("LogDeliveryConfiguration")
|
||||
.elem("LogType", c.logType())
|
||||
.elem("DestinationType", c.destinationType())
|
||||
.start("DestinationDetails");
|
||||
if (c.logGroup() != null) {
|
||||
xml.start("CloudWatchLogsDetails").elem("LogGroup", c.logGroup()).end("CloudWatchLogsDetails");
|
||||
}
|
||||
if (c.deliveryStream() != null) {
|
||||
xml.start("KinesisFirehoseDetails").elem("DeliveryStream", c.deliveryStream())
|
||||
.end("KinesisFirehoseDetails");
|
||||
}
|
||||
xml.end("DestinationDetails")
|
||||
.elem("LogFormat", c.logFormat())
|
||||
.elem("Status", c.status())
|
||||
.elem("Message", c.message())
|
||||
.end("LogDeliveryConfiguration");
|
||||
}
|
||||
return xml.end("LogDeliveryConfigurations").build();
|
||||
}
|
||||
|
||||
private String replicationGroupXml(ReplicationGroup g) {
|
||||
Endpoint ep = g.getConfigurationEndpoint();
|
||||
boolean authTokenEnabled = authTokenEnabled(g);
|
||||
@@ -1306,6 +1366,9 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
if (g.getArn() != null) {
|
||||
xml.elem("ARN", g.getArn());
|
||||
}
|
||||
if (!g.getLogDeliveryConfigurations().isEmpty()) {
|
||||
xml.raw(logDeliveryConfigurationsXml(g.getLogDeliveryConfigurations()));
|
||||
}
|
||||
if (!g.getUserGroupIds().isEmpty()) {
|
||||
xml.raw(memberListXml("UserGroupIds", g.getUserGroupIds()));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import io.floci.aws.core.storage.AccountAwareStorageBackend.AccountEntry;
|
||||
import io.floci.aws.core.storage.StorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.core.storage.StorageJson;
|
||||
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsService;
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.services.ec2.model.SecurityGroup;
|
||||
import io.floci.aws.services.ec2.model.Subnet;
|
||||
@@ -34,6 +35,7 @@ import io.floci.aws.services.elasticache.model.ElastiCacheSnapshot;
|
||||
import io.floci.aws.services.elasticache.model.ElastiCacheUser;
|
||||
import io.floci.aws.services.elasticache.model.ElastiCacheUserGroup;
|
||||
import io.floci.aws.services.elasticache.model.Endpoint;
|
||||
import io.floci.aws.services.elasticache.model.LogDeliveryConfiguration;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroup;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroupSettings;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroupStatus;
|
||||
@@ -105,6 +107,7 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
private final EmulatorConfig config;
|
||||
private final KmsService kmsService;
|
||||
private final Ec2Service ec2Service;
|
||||
private final CloudWatchLogsService logsService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final Set<Integer> usedPorts = ConcurrentHashMap.newKeySet();
|
||||
/**
|
||||
@@ -170,8 +173,10 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
Ec2Service ec2Service,
|
||||
RegionResolver regionResolver,
|
||||
KmsService kmsService,
|
||||
CloudWatchLogsService logsService,
|
||||
ElastiCacheProvisioningIds provisioningIds) {
|
||||
this.kmsService = kmsService;
|
||||
this.logsService = logsService;
|
||||
this.provisioningIds = provisioningIds;
|
||||
this.containerManager = containerManager;
|
||||
this.proxyManager = proxyManager;
|
||||
@@ -224,7 +229,22 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
ReplicationGroupSettings settings,
|
||||
Map<String, String> tags,
|
||||
List<String> userGroupIds,
|
||||
List<String> securityGroupIds) {
|
||||
List<String> securityGroupIds,
|
||||
List<LogDeliveryConfiguration> logDeliveryConfigurations) {
|
||||
|
||||
public CreateReplicationGroupRequest(String replicationGroupId, String description, AuthMode authMode,
|
||||
String authToken, String region, String engine, String engineVersion,
|
||||
String cacheNodeType, String cacheParameterGroupName,
|
||||
String cacheSubnetGroupName, String clusterMode, Integer numNodeGroups,
|
||||
Integer replicasPerNodeGroup, Integer numCacheClusters,
|
||||
Boolean automaticFailoverEnabled, Boolean multiAzEnabled, Integer port,
|
||||
ReplicationGroupSettings settings, Map<String, String> tags,
|
||||
List<String> userGroupIds, List<String> securityGroupIds) {
|
||||
this(replicationGroupId, description, authMode, authToken, region, engine, engineVersion, cacheNodeType,
|
||||
cacheParameterGroupName, cacheSubnetGroupName, clusterMode, numNodeGroups, replicasPerNodeGroup,
|
||||
numCacheClusters, automaticFailoverEnabled, multiAzEnabled, port, settings, tags, userGroupIds,
|
||||
securityGroupIds, List.of());
|
||||
}
|
||||
}
|
||||
|
||||
public ReplicationGroup createReplicationGroup(String groupId, String description,
|
||||
@@ -602,6 +622,15 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/** AWS settles a configuration naming a CloudWatch Logs group that does not exist to an error. */
|
||||
private LogDeliveryConfiguration settleLogDelivery(LogDeliveryConfiguration configuration, String region) {
|
||||
if ("cloudwatch-logs".equals(configuration.destinationType())
|
||||
&& !logsService.logGroupExists(configuration.logGroup(), region)) {
|
||||
return configuration.failed("Destination log group " + configuration.logGroup() + " does not exist.");
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private void applyCommonAttributes(ReplicationGroup group, CreateReplicationGroupRequest request,
|
||||
ReplicationGroupSettings resolvedSettings) {
|
||||
group.setEngine(engineFor(request));
|
||||
@@ -617,6 +646,8 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
group.setCacheParameterGroupName(request.cacheParameterGroupName());
|
||||
group.setCacheSubnetGroupName(request.cacheSubnetGroupName());
|
||||
group.setSecurityGroupIds(request.securityGroupIds());
|
||||
group.setLogDeliveryConfigurations(request.logDeliveryConfigurations().stream()
|
||||
.map(c -> settleLogDelivery(c, request.region())).toList());
|
||||
group.setAutomaticFailoverEnabled(Boolean.TRUE.equals(request.automaticFailoverEnabled()));
|
||||
group.setMultiAzEnabled(Boolean.TRUE.equals(request.multiAzEnabled()));
|
||||
group.setSnapshotWindow(ReplicationGroupSettings.DEFAULT_SNAPSHOT_WINDOW);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.floci.aws.services.elasticache.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/**
|
||||
* Where a replication group delivers one type of log: a CloudWatch Logs group or a Firehose delivery
|
||||
* stream, depending on {@code destinationType}. Floci delivers nothing, so a configuration is active
|
||||
* unless its destination is missing, when it is an error saying so in {@code message}.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public record LogDeliveryConfiguration(String logType,
|
||||
String destinationType,
|
||||
String logGroup,
|
||||
String deliveryStream,
|
||||
String logFormat,
|
||||
String status,
|
||||
String message) {
|
||||
|
||||
/** This configuration settled to an error, as AWS reports a destination it cannot deliver to. */
|
||||
public LogDeliveryConfiguration failed(String reason) {
|
||||
return new LogDeliveryConfiguration(logType, destinationType, logGroup, deliveryStream, logFormat,
|
||||
"error", reason);
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ public class ReplicationGroup {
|
||||
private boolean automaticFailoverEnabled;
|
||||
private boolean multiAzEnabled;
|
||||
private List<ClusterNode> clusterNodes = new ArrayList<>();
|
||||
private List<LogDeliveryConfiguration> logDeliveryConfigurations = new ArrayList<>();
|
||||
|
||||
// Transient fields — not persisted, restored on container restart
|
||||
private transient String containerId;
|
||||
@@ -211,6 +212,12 @@ public class ReplicationGroup {
|
||||
this.clusterNodes = clusterNodes != null ? clusterNodes : new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<LogDeliveryConfiguration> getLogDeliveryConfigurations() { return logDeliveryConfigurations; }
|
||||
public void setLogDeliveryConfigurations(List<LogDeliveryConfiguration> logDeliveryConfigurations) {
|
||||
this.logDeliveryConfigurations = logDeliveryConfigurations == null
|
||||
? new ArrayList<>() : new ArrayList<>(logDeliveryConfigurations);
|
||||
}
|
||||
|
||||
public List<String> getSecurityGroupIds() { return securityGroupIds; }
|
||||
public void setSecurityGroupIds(List<String> securityGroupIds) {
|
||||
this.securityGroupIds = securityGroupIds == null ? new ArrayList<>() : new ArrayList<>(securityGroupIds);
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
package io.floci.aws.services.elasticache;
|
||||
|
||||
import io.floci.aws.services.elasticache.container.ElastiCacheContainerHandle;
|
||||
import io.floci.aws.services.elasticache.container.ElastiCacheContainerManager;
|
||||
import io.quarkus.test.InjectMock;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient;
|
||||
import software.amazon.awssdk.services.elasticache.ElastiCacheClient;
|
||||
import software.amazon.awssdk.services.elasticache.model.DestinationType;
|
||||
import software.amazon.awssdk.services.elasticache.model.ElastiCacheException;
|
||||
import software.amazon.awssdk.services.elasticache.model.LogDeliveryConfiguration;
|
||||
import software.amazon.awssdk.services.elasticache.model.LogDeliveryConfigurationRequest;
|
||||
import software.amazon.awssdk.services.elasticache.model.LogDeliveryConfigurationStatus;
|
||||
import software.amazon.awssdk.services.elasticache.model.LogFormat;
|
||||
import software.amazon.awssdk.services.elasticache.model.LogType;
|
||||
import software.amazon.awssdk.services.elasticache.model.ReplicationGroupNotFoundException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** A replication group reports the log delivery configurations it was created with. */
|
||||
@QuarkusTest
|
||||
class ElastiCacheLogDeliveryIntegrationTest {
|
||||
|
||||
@TestHTTPResource
|
||||
URI endpoint;
|
||||
|
||||
@InjectMock
|
||||
ElastiCacheContainerManager containerManager;
|
||||
|
||||
@BeforeEach
|
||||
void stubBackend() {
|
||||
when(containerManager.tryStart(anyString(), anyString(), anyString())).thenAnswer(invocation ->
|
||||
new ElastiCacheContainerHandle("stub-" + invocation.getArgument(0), invocation.getArgument(0),
|
||||
"127.0.0.1", 16379));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAndDescribeReportTheRequestedLogDeliveryConfigurations() {
|
||||
String groupId = "log-delivery-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String logGroup = "/aws/ec/slow-" + groupId;
|
||||
try (ElastiCacheClient client = client(); CloudWatchLogsClient logs = logs()) {
|
||||
logs.createLogGroup(r -> r.logGroupName(logGroup));
|
||||
List<LogDeliveryConfiguration> created = client.createReplicationGroup(r -> r
|
||||
.replicationGroupId(groupId).replicationGroupDescription("log delivery").engine("redis")
|
||||
.logDeliveryConfigurations(
|
||||
c -> c.logType(LogType.SLOW_LOG).destinationType(DestinationType.CLOUDWATCH_LOGS)
|
||||
.destinationDetails(d -> d.cloudWatchLogsDetails(l -> l.logGroup(logGroup)))
|
||||
.logFormat(LogFormat.JSON).enabled(true),
|
||||
c -> c.logType(LogType.ENGINE_LOG).destinationType(DestinationType.KINESIS_FIREHOSE)
|
||||
.destinationDetails(d -> d.kinesisFirehoseDetails(k -> k.deliveryStream("engine")))
|
||||
.logFormat(LogFormat.TEXT).enabled(true)))
|
||||
.replicationGroup().logDeliveryConfigurations();
|
||||
|
||||
List<LogDeliveryConfiguration> expected = List.of(
|
||||
LogDeliveryConfiguration.builder().logType(LogType.SLOW_LOG)
|
||||
.destinationType(DestinationType.CLOUDWATCH_LOGS)
|
||||
.destinationDetails(d -> d.cloudWatchLogsDetails(l -> l.logGroup(logGroup)))
|
||||
.logFormat(LogFormat.JSON).status(LogDeliveryConfigurationStatus.ACTIVE).build(),
|
||||
LogDeliveryConfiguration.builder().logType(LogType.ENGINE_LOG)
|
||||
.destinationType(DestinationType.KINESIS_FIREHOSE)
|
||||
.destinationDetails(d -> d.kinesisFirehoseDetails(k -> k.deliveryStream("engine")))
|
||||
.logFormat(LogFormat.TEXT).status(LogDeliveryConfigurationStatus.ACTIVE).build());
|
||||
assertEquals(expected, created);
|
||||
assertEquals(expected, client.describeReplicationGroups(r -> r.replicationGroupId(groupId))
|
||||
.replicationGroups().getFirst().logDeliveryConfigurations());
|
||||
client.deleteReplicationGroup(r -> r.replicationGroupId(groupId));
|
||||
logs.deleteLogGroup(r -> r.logGroupName(logGroup));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMissingCloudWatchLogsGroupSettlesTheConfigurationToErrorWithoutCreatingIt() {
|
||||
String groupId = "log-missing-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String logGroup = "/aws/ec/missing-" + groupId;
|
||||
try (ElastiCacheClient client = client(); CloudWatchLogsClient logs = logs()) {
|
||||
client.createReplicationGroup(r -> r.replicationGroupId(groupId).replicationGroupDescription("missing")
|
||||
.engine("redis").logDeliveryConfigurations(c -> c.logType(LogType.SLOW_LOG)
|
||||
.destinationType(DestinationType.CLOUDWATCH_LOGS)
|
||||
.destinationDetails(d -> d.cloudWatchLogsDetails(l -> l.logGroup(logGroup)))
|
||||
.logFormat(LogFormat.JSON).enabled(true)));
|
||||
|
||||
LogDeliveryConfiguration expected = LogDeliveryConfiguration.builder().logType(LogType.SLOW_LOG)
|
||||
.destinationType(DestinationType.CLOUDWATCH_LOGS)
|
||||
.destinationDetails(d -> d.cloudWatchLogsDetails(l -> l.logGroup(logGroup)))
|
||||
.logFormat(LogFormat.JSON).status(LogDeliveryConfigurationStatus.ERROR)
|
||||
.message("Destination log group " + logGroup + " does not exist.").build();
|
||||
assertEquals(List.of(expected), client.describeReplicationGroups(r -> r.replicationGroupId(groupId))
|
||||
.replicationGroups().getFirst().logDeliveryConfigurations());
|
||||
assertEquals(List.of(), logs.describeLogGroups(r -> r.logGroupNamePrefix(logGroup)).logGroups());
|
||||
client.deleteReplicationGroup(r -> r.replicationGroupId(groupId));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"logType=audit-log", "destinationType=s3", "logFormat=xml", "logType="})
|
||||
void aLogDeliveryConfigurationWithAnUnknownOrMissingValueIsRefused(String override) {
|
||||
String groupId = "log-refused-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String[] field = override.split("=", -1);
|
||||
String value = field[1].isEmpty() ? null : field[1];
|
||||
LogDeliveryConfigurationRequest.Builder configuration = LogDeliveryConfigurationRequest.builder()
|
||||
.logType(LogType.SLOW_LOG).destinationType(DestinationType.CLOUDWATCH_LOGS)
|
||||
.destinationDetails(d -> d.cloudWatchLogsDetails(l -> l.logGroup("/aws/ec/slow")))
|
||||
.logFormat(LogFormat.JSON).enabled(true);
|
||||
switch (field[0]) {
|
||||
case "logType" -> configuration.logType(value);
|
||||
case "destinationType" -> configuration.destinationType(value);
|
||||
default -> configuration.logFormat(value);
|
||||
}
|
||||
try (ElastiCacheClient client = client()) {
|
||||
ElastiCacheException refused = assertThrows(ElastiCacheException.class, () -> client
|
||||
.createReplicationGroup(r -> r.replicationGroupId(groupId).replicationGroupDescription("refused")
|
||||
.engine("redis").logDeliveryConfigurations(configuration.build())));
|
||||
|
||||
assertEquals("InvalidParameterValue", refused.awsErrorDetails().errorCode());
|
||||
assertThrows(ReplicationGroupNotFoundException.class,
|
||||
() -> client.describeReplicationGroups(r -> r.replicationGroupId(groupId)));
|
||||
}
|
||||
}
|
||||
|
||||
private CloudWatchLogsClient logs() {
|
||||
return CloudWatchLogsClient.builder().endpointOverride(endpoint).region(Region.US_EAST_1)
|
||||
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test")))
|
||||
.build();
|
||||
}
|
||||
|
||||
private ElastiCacheClient client() {
|
||||
return ElastiCacheClient.builder().endpointOverride(endpoint).region(Region.US_EAST_1)
|
||||
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("test", "test")))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -8,6 +8,7 @@ import io.floci.aws.core.common.ServiceConfigAccess;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsService;
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.services.ec2.model.SecurityGroup;
|
||||
import io.floci.aws.services.ec2.model.Subnet;
|
||||
@@ -106,7 +107,7 @@ class ElastiCacheServerlessServiceTest {
|
||||
kms = mock(KmsService.class);
|
||||
when(kms.describeKey(anyString(), anyString())).thenThrow(new AwsException("NotFoundException", "Missing key", 400));
|
||||
runtime = new ElastiCacheService(containers, proxies, mock(ValkeyClusterFormation.class), factory,
|
||||
config, ec2, resolver, kms, new ElastiCacheProvisioningIds());
|
||||
config, ec2, resolver, kms, mock(CloudWatchLogsService.class), new ElastiCacheProvisioningIds());
|
||||
memcached = new ElastiCacheMemcachedService(mock(ElastiCacheMemcachedContainerManager.class), factory,
|
||||
config, new ElastiCacheProvisioningIds(), resolver);
|
||||
service = new ElastiCacheServerlessService(factory, resolver, runtime, memcached);
|
||||
@@ -390,7 +391,7 @@ class ElastiCacheServerlessServiceTest {
|
||||
|
||||
private ElastiCacheService newRuntime(StorageFactory activeFactory) {
|
||||
return new ElastiCacheService(containers, proxies, mock(ValkeyClusterFormation.class), activeFactory,
|
||||
config, ec2, resolver, kms, new ElastiCacheProvisioningIds());
|
||||
config, ec2, resolver, kms, mock(CloudWatchLogsService.class), new ElastiCacheProvisioningIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsService;
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.services.elasticache.container.ElastiCacheContainerHandle;
|
||||
import io.floci.aws.services.elasticache.container.ElastiCacheContainerManager;
|
||||
@@ -56,7 +57,7 @@ final class ElastiCacheServiceFixture {
|
||||
when(kmsService.describeKey(any(), any())).thenThrow(new AwsException("NotFoundException", "Key not found", 404));
|
||||
service = new ElastiCacheService(containerManager, proxyManager, mock(ValkeyClusterFormation.class),
|
||||
storageFactory, config, mock(Ec2Service.class), new RegionResolver("us-east-1", "000000000000"),
|
||||
kmsService, new ElastiCacheProvisioningIds());
|
||||
kmsService, mock(CloudWatchLogsService.class), new ElastiCacheProvisioningIds());
|
||||
}
|
||||
|
||||
/** The container the group {@code groupId} gets. */
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.floci.aws.core.common.RequestContext;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.cloudwatch.logs.CloudWatchLogsService;
|
||||
import io.floci.aws.services.ec2.Ec2Service;
|
||||
import io.floci.aws.services.ec2.model.Subnet;
|
||||
import io.floci.aws.services.elasticache.container.ElastiCacheContainerHandle;
|
||||
@@ -124,7 +125,7 @@ class ElastiCacheServiceTest {
|
||||
clusterFormation = mock(ValkeyClusterFormation.class);
|
||||
service = new ElastiCacheService(containerManager, proxyManager, clusterFormation,
|
||||
storageFactory, config, ec2Service, new RegionResolver("us-east-1", "000000000000"),
|
||||
kmsService, provisioningIds);
|
||||
kmsService, mock(CloudWatchLogsService.class), provisioningIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,7 +153,7 @@ class ElastiCacheServiceTest {
|
||||
ElastiCacheService svc = new ElastiCacheService(cm, pm, mock(ValkeyClusterFormation.class),
|
||||
sf, cfg, mock(Ec2Service.class),
|
||||
new RegionResolver("us-east-1", "000000000000"),
|
||||
mock(KmsService.class), provisioningIds);
|
||||
mock(KmsService.class), mock(CloudWatchLogsService.class), provisioningIds);
|
||||
|
||||
svc.createReplicationGroup("g1", "d", AuthMode.PASSWORD, null, "us-east-1");
|
||||
|
||||
@@ -1210,7 +1211,7 @@ class ElastiCacheServiceTest {
|
||||
when(config.hostname()).thenReturn(Optional.of("localhost"));
|
||||
return new ElastiCacheService(containerManager, proxyManager, clusterFormation,
|
||||
storageFactory, config, mock(Ec2Service.class),
|
||||
new RegionResolver("us-east-1", "000000000000"), mock(KmsService.class), new ElastiCacheProvisioningIds());
|
||||
new RegionResolver("us-east-1", "000000000000"), mock(KmsService.class), mock(CloudWatchLogsService.class), new ElastiCacheProvisioningIds());
|
||||
}
|
||||
|
||||
private static void stubPerNodeContainers(ElastiCacheContainerManager containerManager) {
|
||||
@@ -1962,7 +1963,7 @@ class ElastiCacheServiceTest {
|
||||
.thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
|
||||
ElastiCacheService svc = new ElastiCacheService(containerManager, proxyManager, clusterFormation,
|
||||
factory, config, mock(Ec2Service.class),
|
||||
new RegionResolver("us-east-1", "000000000000"), kmsService, provisioningIds);
|
||||
new RegionResolver("us-east-1", "000000000000"), kmsService, mock(CloudWatchLogsService.class), provisioningIds);
|
||||
svc.createReplicationGroup("g1", "d", AuthMode.NO_AUTH, null, "us-east-1");
|
||||
|
||||
pausing.pauseOn(PausingStorageBackend.Call.PUT, "g1");
|
||||
@@ -2081,7 +2082,7 @@ class ElastiCacheServiceTest {
|
||||
new AccountAwareStorageBackend<>(new InMemoryStorage<>(), requestContextInstance, "000000000000"));
|
||||
ElastiCacheService svc = new ElastiCacheService(containerManager, proxyManager, clusterFormation,
|
||||
factory, config, mock(Ec2Service.class),
|
||||
new RegionResolver("us-east-1", "000000000000"), kmsService, provisioningIds);
|
||||
new RegionResolver("us-east-1", "000000000000"), kmsService, mock(CloudWatchLogsService.class), provisioningIds);
|
||||
|
||||
CountDownLatch startedLatch = new CountDownLatch(1);
|
||||
CountDownLatch releaseLatch = new CountDownLatch(1);
|
||||
@@ -2131,7 +2132,7 @@ class ElastiCacheServiceTest {
|
||||
new AccountAwareStorageBackend<>(new InMemoryStorage<>(), requestContextInstance, "000000000000"));
|
||||
ElastiCacheService svc = new ElastiCacheService(containerManager, proxyManager, clusterFormation,
|
||||
factory, config, mock(Ec2Service.class),
|
||||
new RegionResolver("us-east-1", "000000000000"), kmsService, provisioningIds);
|
||||
new RegionResolver("us-east-1", "000000000000"), kmsService, mock(CloudWatchLogsService.class), provisioningIds);
|
||||
|
||||
CountDownLatch startedLatch = new CountDownLatch(1);
|
||||
CountDownLatch releaseLatch = new CountDownLatch(1);
|
||||
@@ -2473,7 +2474,7 @@ class ElastiCacheServiceTest {
|
||||
private ElastiCacheService serviceAfterRestart() {
|
||||
return new ElastiCacheService(containerManager, proxyManager, clusterFormation,
|
||||
storageFactory, config, ec2Service, new RegionResolver("us-east-1", "000000000000"),
|
||||
kmsService, provisioningIds);
|
||||
kmsService, mock(CloudWatchLogsService.class), provisioningIds);
|
||||
}
|
||||
|
||||
private ElastiCacheMemcachedService memcachedService() {
|
||||
|
||||
Reference in new issue
Block a user