fix(mq): return CreateBroker members from DescribeBroker (#5211)

* fix(mq): return CreateBroker members from DescribeBroker

CreateBroker accepted securityGroups, subnetIds, logs,
maintenanceWindowStartTime, storageType, authenticationStrategy,
encryptionOptions and configuration, but discarded them, so
DescribeBroker never returned them. Carry them through
CreateBrokerParams to the persisted Broker and into the DescribeBroker
response, with configuration reported as configurations.current as in
the AWS shape. Absent members are omitted, and brokers persisted before
this change still load.

RabbitMQ users stay out of DescribeBroker (#1951).

* fix(mq): report DescribeBroker logs as a LogsSummary

general and generalLogGroup are required in LogsSummary; general defaults
to false and the log group is /aws/amazonmq/broker/<broker-id>/general.
audit/auditLogGroup are reported only when audit logging was requested.

* fix(mq): report only the general log group in LogsSummary

Audit logs are ActiveMQ-only, and Floci emulates RabbitMQ brokers.
Document DescribeBroker's logs as a LogsSummary rather than an echo.

* fix(mq): stream broker logs to the general log group DescribeBroker reports

RabbitMqManager streamed container logs to /aws/amazonmq/broker/<id>
while DescribeBroker named /aws/amazonmq/broker/<id>/general. Both now
take the name from Broker.generalLogGroup().
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-07 09:14:41 -04:00
1 parent 5fc8b0418c
commit 73133b472a
9 files changed
+263 -4

No files matched your search

@@ -3,9 +3,13 @@ package io.github.hectorvent.floci.services.amazonmq;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
@@ -50,6 +54,67 @@ class AmazonMqControllerIntegrationTest {
.body("volumeId", nullValue());
}
@Test
void describeBrokerReturnsCreateBrokerMembers() {
String brokerId = given()
.contentType("application/json")
.body("""
{"brokerName": "it-members", "engineType": "RABBITMQ",
"deploymentMode": "SINGLE_INSTANCE", "hostInstanceType": "mq.t3.micro",
"publiclyAccessible": false,
"securityGroups": ["sg-0123"], "subnetIds": ["subnet-0abc"],
"logs": {"general": true},
"maintenanceWindowStartTime": {"dayOfWeek": "MONDAY", "timeOfDay": "02:00", "timeZone": "UTC"},
"storageType": "EBS", "authenticationStrategy": "SIMPLE",
"encryptionOptions": {"kmsKeyId": "arn:aws:kms:us-east-1:000000000000:key/k1", "useAwsOwnedKey": false},
"configuration": {"id": "c-123", "revision": 2},
"users": [{"username": "admin", "password": "AdminPass123", "consoleAccess": true}]}
""")
.when()
.post("/v1/brokers")
.then()
.statusCode(200)
.extract().path("brokerId");
given()
.when()
.get("/v1/brokers/{id}", brokerId)
.then()
.statusCode(200)
.body("securityGroups", equalTo(List.of("sg-0123")))
.body("subnetIds", equalTo(List.of("subnet-0abc")))
.body("logs.general", equalTo(true))
.body("logs.generalLogGroup", equalTo("/aws/amazonmq/broker/" + brokerId + "/general"))
.body("maintenanceWindowStartTime.dayOfWeek", equalTo("MONDAY"))
.body("maintenanceWindowStartTime.timeOfDay", equalTo("02:00"))
.body("maintenanceWindowStartTime.timeZone", equalTo("UTC"))
.body("storageType", equalTo("EBS"))
.body("authenticationStrategy", equalTo("SIMPLE"))
.body("encryptionOptions.kmsKeyId", equalTo("arn:aws:kms:us-east-1:000000000000:key/k1"))
.body("encryptionOptions.useAwsOwnedKey", equalTo(false))
.body("configurations.current.id", equalTo("c-123"))
.body("configurations.current.revision", equalTo(2))
.body("configuration", nullValue())
// RabbitMQ users stay out of DescribeBroker (see createThenDescribeBroker).
.body("users", nullValue());
}
@Test
void describeBrokerOmitsUnsetOptionalMembers() {
String brokerId = createRabbitBroker("it-minimal");
given()
.when()
.get("/v1/brokers/{id}", brokerId)
.then()
.statusCode(200)
.body("$", not(hasKey("securityGroups")))
.body("logs.general", equalTo(false))
.body("logs.generalLogGroup", equalTo("/aws/amazonmq/broker/" + brokerId + "/general"))
.body("$", not(hasKey("configurations")))
.body("$", not(hasKey("encryptionOptions")));
}
@Test
void listBrokersIncludesCreated() {
createRabbitBroker("it-list");
@@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -161,6 +162,37 @@ class RabbitMqManagerTest {
assertEquals("http://172.17.0.5:15672", broker.getBrokerInstances().get(0).getConsoleURL());
}
/** Container logs stream to the log group DescribeBroker names as generalLogGroup. */
@Test
void startContainerStreamsLogsToGeneralLogGroup() {
EmulatorConfig config = configWithDefaultPortRanges();
ContainerLifecycleManager lifecycleManager = Mockito.mock(ContainerLifecycleManager.class);
when(lifecycleManager.createAndStart(any())).thenReturn(
new ContainerLifecycleManager.ContainerInfo("container-id", Map.of(
5672, new ContainerLifecycleManager.EndpointInfo("localhost", 5672),
15672, new ContainerLifecycleManager.EndpointInfo("localhost", 15672))));
ContainerBuilder containerBuilder = Mockito.mock(ContainerBuilder.class);
selfReturningBuilder(containerBuilder);
PortAllocator portAllocator = Mockito.mock(PortAllocator.class);
when(portAllocator.allocate(5672, 5699)).thenReturn(5672);
when(portAllocator.allocate(15672, 15699)).thenReturn(15672);
ContainerLogStreamer logStreamer = Mockito.mock(ContainerLogStreamer.class);
RabbitMqManager manager = new RabbitMqManager(containerBuilder, lifecycleManager,
logStreamer, Mockito.mock(ContainerDetector.class),
portAllocator, config, regionResolver());
Broker broker = broker("b-1");
manager.startContainer(broker);
assertEquals("/aws/amazonmq/broker/b-1/general", broker.generalLogGroup());
verify(logStreamer).attach(eq("container-id"), eq(broker.generalLogGroup()),
any(), any(), eq("amazonmq:b-1"));
}
/**
* The reservation must die with the container: without the release, repeated
* create/delete cycles exhaust the configured ranges and later brokers can
@@ -3,7 +3,11 @@ package io.github.hectorvent.floci.services.amazonmq.model;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
class BrokerTest {
@@ -29,4 +33,35 @@ class BrokerTest {
assertEquals("000000000000", roundTripped.getAccountId());
assertEquals("a1b2c3", roundTripped.getVolumeId());
}
@Test
void createBrokerMembersPersistAcrossSerialization() throws Exception {
ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
Broker broker = new Broker("b-1", "arn", "n", "RABBITMQ", "3.13", "SINGLE_INSTANCE", "mq.t3.micro");
broker.setSecurityGroups(List.of("sg-1"));
broker.setMaintenanceWindowStartTime(Map.of("dayOfWeek", "MONDAY"));
broker.setConfiguration(Map.of("id", "c-1", "revision", 2));
broker.setStorageType("EBS");
Broker roundTripped = mapper.readValue(mapper.writeValueAsString(broker), Broker.class);
assertEquals(List.of("sg-1"), roundTripped.getSecurityGroups());
assertEquals(Map.of("dayOfWeek", "MONDAY"), roundTripped.getMaintenanceWindowStartTime());
assertEquals(Map.of("id", "c-1", "revision", 2), roundTripped.getConfiguration());
assertEquals("EBS", roundTripped.getStorageType());
}
/** A broker persisted before these members existed must still load, with them absent. */
@Test
void brokerPersistedWithoutNewMembersStillLoads() throws Exception {
ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
Broker old = mapper.readValue(
"{\"brokerId\":\"b-1\",\"brokerName\":\"n\",\"engineType\":\"RABBITMQ\",\"containerId\":\"c\"}",
Broker.class);
assertEquals("b-1", old.getBrokerId());
assertNull(old.getSecurityGroups());
assertNull(old.getConfiguration());
assertNull(old.getEncryptionOptions());
}
}