mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(eventbridge): answer PutEvents to a missing event bus as AWS does (#6748)
A PutEvents entry naming an event bus that does not exist failed with InvalidArgument "EventBus not found" and counted in FailedEntryCount. The EventBridge User Guide, on handling PutEvents failures: "If you use PutEvents to publish an event to an event bus that does not exist, EventBridge event matching will not find a corresponding rule and will drop the event. Although EventBridge will send a 200 response, it will not fail the request or include the event in the FailedEntryCount value of the request response." botocore models no not-found error for PutEvents, only InternalException, and the API Reference lists none. Such an entry is now answered as published, with an event id and not counted as failed, and dropped: it reaches no rule and no archive. Floci logs the drop at INFO. An entry that is not valid, missing a required field or with a Detail that is no JSON object, still fails as before, whichever bus it names. Only the PutEvents action changes. Floci's own deliveries to a bus, for a rule's event bus target, a pipe, a schedule, a Lambda destination or a replay, still fail an entry for a bus that does not exist: the guide's sentence is about the action, and no document says how AWS answers those deliveries. Step Functions' optimized events:putEvents integration calls the action, so a task publishing to a missing bus no longer fails with EventBridge.FailedEntry; step-functions.md listed that as a deviation, which is gone. Its two tests that used a missing bus to have an entry rejected now leave out the entry's Source instead, and a third checks that a task publishing to a missing bus succeeds.
This commit is contained in:
1 parent
b6d9e4c7a4
commit
32cbf73adc
8 files changed
+133
-8
No files matched your search
@@ -235,6 +235,24 @@ class EventBridgeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(26)
|
||||
void putEventsToAnEventBusThatDoesNotExistIsAnsweredAsPublished() {
|
||||
PutEventsResponse response = eb.putEvents(PutEventsRequest.builder()
|
||||
.entries(PutEventsRequestEntry.builder()
|
||||
.eventBusName(TestFixtures.uniqueName("eb-missing-bus"))
|
||||
.source("com.myapp")
|
||||
.detailType("OrderPlaced")
|
||||
.detail("{}")
|
||||
.build())
|
||||
.build());
|
||||
|
||||
assertThat(response.failedEntryCount()).isZero();
|
||||
assertThat(response.entries()).hasSize(1);
|
||||
assertThat(response.entries().get(0).eventId()).isNotBlank();
|
||||
assertThat(response.entries().get(0).errorCode()).isNull();
|
||||
}
|
||||
|
||||
// ──────────────────────────── InputTransformer ────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
@@ -243,6 +243,7 @@ aws events put-targets \
|
||||
## Current Behavior
|
||||
|
||||
- `PutEvents` reports success once the source bus accepts an event. Target delivery failures are retried and dead-lettered as described above, and otherwise surface only as a `WARN` in the Floci logs.
|
||||
- A `PutEvents` entry for an event bus that does not exist is answered as AWS answers it: with an event id, not counted in `FailedEntryCount`, and dropped, as no rule matches it. Floci logs the drop at `INFO`. Floci's own deliveries to a bus, for a rule, a pipe or a schedule, are unchanged: an entry for a bus that does not exist fails there.
|
||||
- A `Detail` forwarded to an event bus must be a JSON object, as in AWS; anything else is dropped, including an `InputPath` selecting a scalar such as `$.detail.orderId` or an envelope carrying `"detail": null`.
|
||||
- A bus ARN naming another account is forwarded under that account, so the target bus and its rules resolve there.
|
||||
- Onward delivery from that bus follows each target type: SQS and Step Functions resolve cross-account, while Lambda, SNS, Batch and Firehose resolve in the caller's account.
|
||||
|
||||
@@ -646,15 +646,15 @@ fails the task with `SNS.NotFoundException` and a missing `Message` with
|
||||
cause is the response serialized as a string, so a `Catch` can read which entry was rejected:
|
||||
|
||||
```json
|
||||
{"FailedEntryCount":1,"Entries":[{"EventId":"08cbdc46-…"},{"ErrorCode":"InvalidArgument","ErrorMessage":"EventBus not found: no-such-bus"}]}
|
||||
{"FailedEntryCount":1,"Entries":[{"EventId":"08cbdc46-…"},{"ErrorCode":"InvalidArgument","ErrorMessage":"Parameter Source is not valid. Reason: Source is a required argument."}]}
|
||||
```
|
||||
|
||||
The optimized integration accepts `Detail` as a JSON object in JSONPath and JSONata workflows. It
|
||||
serializes that object once for the EventBridge request, preserving nested values and escaped text.
|
||||
The direct EventBridge API continues to accept its native string-valued `Detail` field.
|
||||
|
||||
One deviation, and it belongs to EventBridge rather than to the integration: Floci rejects an entry
|
||||
addressed to an event bus that does not exist, while AWS accepts it and returns an `EventId`.
|
||||
An entry addressed to an event bus that does not exist is accepted with an `EventId`, as in AWS, and
|
||||
dropped, so it does not fail the task.
|
||||
|
||||
## JSONata expressions are validated when the state machine is created
|
||||
|
||||
|
||||
+1
-1
@@ -393,7 +393,7 @@ public class EventBridgeHandler {
|
||||
entries.add(entry);
|
||||
}
|
||||
}
|
||||
EventBridgeService.PutEventsResult result = eventBridgeService.putEvents(entries, region);
|
||||
EventBridgeService.PutEventsResult result = eventBridgeService.putEventsFromRequest(entries, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("FailedEntryCount", result.failedCount());
|
||||
ArrayNode resultEntries = response.putArray("Entries");
|
||||
|
||||
@@ -916,6 +916,25 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
* {@code null} whenever the target is in the caller's own account.
|
||||
*/
|
||||
public PutEventsResult putEvents(List<Map<String, Object>> entries, String region, String accountId) {
|
||||
return putEvents(entries, region, accountId, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes the entries of a {@code PutEvents} request. As {@link #putEvents(List, String)}, except that
|
||||
* an entry for an event bus that does not exist is answered as published, with an event id and not
|
||||
* counted as failed, and goes no further, as the EventBridge User Guide gives it: "If you use PutEvents
|
||||
* to publish an event to an event bus that does not exist, EventBridge event matching will not find a
|
||||
* corresponding rule and will drop the event. Although EventBridge will send a 200 response, it will not
|
||||
* fail the request or include the event in the FailedEntryCount value of the request response." Floci's
|
||||
* own deliveries to a bus, for a rule, a pipe or a schedule, go through {@link #putEvents} and still fail
|
||||
* such an entry: the guide's sentence is about the action, and no document says how AWS answers them.
|
||||
*/
|
||||
public PutEventsResult putEventsFromRequest(List<Map<String, Object>> entries, String region) {
|
||||
return putEvents(entries, region, null, true);
|
||||
}
|
||||
|
||||
private PutEventsResult putEvents(List<Map<String, Object>> entries, String region, String accountId,
|
||||
boolean dropForMissingBus) {
|
||||
int failed = 0;
|
||||
List<Map<String, String>> resultEntries = new ArrayList<>();
|
||||
|
||||
@@ -969,6 +988,12 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
|
||||
if ("default".equals(effectiveBus)) {
|
||||
getOrCreateDefaultBus(region);
|
||||
} else if (accountGet(busStore, accountId, busStoreKey).isEmpty()) {
|
||||
if (dropForMissingBus) {
|
||||
LOG.infov("PutEvents dropped an event for event bus {0}, which does not exist in {1}",
|
||||
effectiveBus, region);
|
||||
resultEntries.add(Map.of("EventId", UUID.randomUUID().toString()));
|
||||
continue;
|
||||
}
|
||||
failed++;
|
||||
Map<String, String> errorEntry = new HashMap<>();
|
||||
errorEntry.put("ErrorCode", "InvalidArgument");
|
||||
|
||||
+26
@@ -9,6 +9,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@@ -293,4 +294,29 @@ class EventBridgeIntegrationTest {
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void putEventsToAnEventBusThatDoesNotExistIsAnsweredAsPublished() {
|
||||
given()
|
||||
.contentType(EVENT_BRIDGE_CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSEvents.PutEvents")
|
||||
.body("""
|
||||
{
|
||||
"Entries": [
|
||||
{"Source": "com.mycompany.myapp", "DetailType": "t", "Detail": "{}",
|
||||
"EventBusName": "eb-integration-missing-bus"},
|
||||
{"Source": "com.mycompany.myapp", "DetailType": "t", "Detail": "{",
|
||||
"EventBusName": "eb-integration-missing-bus"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("FailedEntryCount", equalTo(1))
|
||||
.body("Entries", hasSize(2))
|
||||
.body("Entries[0].EventId", notNullValue())
|
||||
.body("Entries[0].ErrorCode", nullValue())
|
||||
.body("Entries[1].ErrorCode", equalTo("MalformedDetail"));
|
||||
}
|
||||
}
|
||||
+31
@@ -1027,6 +1027,37 @@ class EventBridgeServiceTest {
|
||||
assertEquals(1, result.failedCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* A request's entry for an event bus that does not exist is answered as published and dropped: it gets an
|
||||
* event id, is not counted as failed and reaches no rule, the default bus's included. An entry that is not
|
||||
* valid still fails, whatever bus it names.
|
||||
*/
|
||||
@Test
|
||||
void aRequestsEntryForANonExistentBusIsAnsweredAsPublishedAndDropped() {
|
||||
service.putRule("on-my-app", null, "{\"source\":[\"my.app\"]}", null, RuleState.ENABLED,
|
||||
null, null, null, REGION);
|
||||
Target target = new Target();
|
||||
target.setId("t1");
|
||||
target.setArn("arn:aws:sqs:us-east-1:000000000000:queue-1");
|
||||
service.putTargets("on-my-app", null, List.of(target), REGION);
|
||||
|
||||
EventBridgeService.PutEventsResult result = service.putEventsFromRequest(List.of(
|
||||
Map.of("Source", "my.app", "DetailType", "Test", "Detail", "{}", "EventBusName", "non-existent-bus"),
|
||||
Map.of("Source", "my.app", "DetailType", "Test", "Detail", "{}"),
|
||||
Map.of("Source", "my.app", "DetailType", "Test", "Detail", "{", "EventBusName", "non-existent-bus")),
|
||||
REGION);
|
||||
|
||||
assertEquals(1, result.failedCount());
|
||||
assertEquals(3, result.entries().size());
|
||||
assertNotNull(result.entries().get(0).get("EventId"));
|
||||
assertNull(result.entries().get(0).get("ErrorCode"));
|
||||
assertNotNull(result.entries().get(1).get("EventId"));
|
||||
assertEquals("MalformedDetail", result.entries().get(2).get("ErrorCode"));
|
||||
verify(dispatcherMock).dispatch(anyString(), any(Target.class),
|
||||
contains("\"event-bus-name\":\"default\""), anyString(), any());
|
||||
verify(dispatcherMock).dispatch(anyString(), any(Target.class), anyString(), anyString(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putEventsShouldInvokeLambdaTarget() {
|
||||
service.putRule("my-rule", null, "{\"source\":[\"my.app\"]}", null, RuleState.ENABLED,
|
||||
|
||||
+28
-4
@@ -203,8 +203,7 @@ class StepFunctionsPutEventsIntegrationTest {
|
||||
"Arguments": {
|
||||
"Entries": [
|
||||
{"Source": "floci.unrouted", "DetailType": "t", "Detail": "{}"},
|
||||
{"EventBusName": "no-such-bus", "Source": "floci.unrouted",
|
||||
"DetailType": "t", "Detail": "{}"}
|
||||
{"DetailType": "t", "Detail": "{}"}
|
||||
]
|
||||
},
|
||||
"End": true
|
||||
@@ -236,8 +235,7 @@ class StepFunctionsPutEventsIntegrationTest {
|
||||
"Type": "Task",
|
||||
"Resource": "RESOURCE_ARN",
|
||||
"Arguments": {
|
||||
"Entries": [{"EventBusName": "no-such-bus", "Source": "floci.unrouted",
|
||||
"DetailType": "t", "Detail": "{}"}]
|
||||
"Entries": [{"DetailType": "t", "Detail": "{}"}]
|
||||
},
|
||||
"Catch": [{"ErrorEquals": ["EventBridge.FailedEntry"], "Next": "Recovered"}],
|
||||
"End": true
|
||||
@@ -254,6 +252,32 @@ class StepFunctionsPutEventsIntegrationTest {
|
||||
assertTrue(mapper.readTree(succeedingOutputOf(smArn)).path("recovered").asBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void anEntryForAnEventBusThatDoesNotExistIsAcceptedAndDoesNotFailTheTask() throws Exception {
|
||||
String smArn = createStateMachine("put-events-missing-bus", """
|
||||
{
|
||||
"QueryLanguage": "JSONata",
|
||||
"StartAt": "Publish",
|
||||
"States": {
|
||||
"Publish": {
|
||||
"Type": "Task",
|
||||
"Resource": "RESOURCE_ARN",
|
||||
"Arguments": {
|
||||
"Entries": [{"EventBusName": "no-such-bus", "Source": "floci.unrouted",
|
||||
"DetailType": "t", "Detail": "{}"}]
|
||||
},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""".replace("RESOURCE_ARN", RESOURCE));
|
||||
|
||||
JsonNode result = mapper.readTree(succeedingOutputOf(smArn));
|
||||
assertEquals(0, result.path("FailedEntryCount").asInt());
|
||||
assertFalse(result.path("Entries").get(0).path("EventId").asText().isBlank());
|
||||
}
|
||||
|
||||
private static List<String> fieldNames(JsonNode node) {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
node.fieldNames().forEachRemaining(names::add);
|
||||
|
||||
Reference in new issue
Block a user