fix(pipes): build flat Kinesis record shape with correct field values (#7554)

buildKinesisRecordNodes previously used valueToTree + PascalCase key
reads, losing all values and producing a nested kinesis object. Now
reads KinesisRecord getters directly and builds the flat Pipes shape,
with eventVersion, kinesisSchemaVersion, invokeIdentityArn and a
shardId-000000000000:<sequence> eventID.

- Fix PipesTargetInvoker base64 decoding for flat shape
- Decode base64 Kinesis data in PipesFilterMatcher before JSON parsing,
  through a helper shared with PipesTargetInvoker

Refs #7481

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-11-10 11:48:03 -04:00
1 parent baa834101d
commit 8d95688eec
6 files changed
+101 -34

No files matched your search

@@ -106,15 +106,25 @@ public class PipesFilterMatcher {
}
JsonNode value = actual == null || !actual.isObject() ? null : actual.get(field.getKey());
JsonNode expected = field.getValue();
// Kinesis data arrives base64-encoded; decode it for both object and array patterns.
JsonNode decodedValue = value;
if (value != null && value.isTextual() && "data".equals(field.getKey())
&& actual != null && "aws:kinesis".equals(actual.path("eventSource").asText())) {
String decoded = PipesTargetInvoker.decodedSourceText(field.getKey(), value.asText(),
actual);
if (!decoded.equals(value.asText()) && decoder != null) {
decodedValue = decoder.getNodeFactory().textNode(decoded);
}
}
if (expected.isObject()) {
boolean nestedMatches = value == null
? matches(expected, null, decoder)
: matchesNested(expected, decoded(value, decoder), decoder);
: matchesNested(expected, decoded(decodedValue, decoder), decoder);
if (!nestedMatches) {
return false;
}
} else if (expected.isArray()) {
if (!matchesAlternatives(field.getKey(), expected, value)) {
if (!matchesAlternatives(field.getKey(), expected, decodedValue)) {
return false;
}
} else {
@@ -749,22 +749,27 @@ public class PipesPoller implements Resettable {
return nodes;
}
private List<ObjectNode> buildKinesisRecordNodes(List<?> records, Pipe pipe, String region) {
List<ObjectNode> buildKinesisRecordNodes(List<?> records, Pipe pipe, String region) {
List<ObjectNode> nodes = new ArrayList<>();
for (Object record : records) {
ObjectNode node = objectMapper.valueToTree(record);
KinesisRecord kr = (KinesisRecord) record;
ObjectNode eventRecord = objectMapper.createObjectNode();
eventRecord.put("eventSource", "aws:kinesis");
eventRecord.put("eventSourceARN", pipe.getSource());
eventRecord.put("eventVersion", "1.0");
eventRecord.put("eventID", "shardId-000000000000:" + kr.getSequenceNumber());
eventRecord.put("eventName", "aws:kinesis:record");
eventRecord.put("invokeIdentityArn", pipe.getRoleArn());
eventRecord.put("awsRegion", region);
eventRecord.put("eventID", pipe.getSource() + ":" +
node.path("SequenceNumber").asText());
ObjectNode kinesis = eventRecord.putObject("kinesis");
kinesis.put("partitionKey", node.path("PartitionKey").asText());
kinesis.put("sequenceNumber", node.path("SequenceNumber").asText());
kinesis.put("approximateArrivalTimestamp",
node.path("ApproximateArrivalTimestamp").asDouble());
kinesis.put("data", node.path("Data").asText());
eventRecord.put("eventSourceARN", pipe.getSource());
eventRecord.put("kinesisSchemaVersion", "1.0");
eventRecord.put("partitionKey", kr.getPartitionKey());
eventRecord.put("sequenceNumber", kr.getSequenceNumber());
eventRecord.put("approximateArrivalTimestamp",
kr.getApproximateArrivalTimestamp() != null
? kr.getApproximateArrivalTimestamp().toEpochMilli() / 1000.0 : 0.0);
String data = kr.getData() != null
? Base64.getEncoder().encodeToString(kr.getData()) : "";
eventRecord.put("data", data);
nodes.add(eventRecord);
}
return nodes;
@@ -379,14 +379,13 @@ public class PipesTargetInvoker {
JsonNode current = objectMapper.readTree(json);
String previousSegment = null;
JsonNode container = null;
JsonNode outer = null;
boolean sourceFieldDecoded = false;
for (String segment : segments) {
// AWS Pipes parses an encoded source body when traversing into it.
if (!sourceFieldDecoded && isEncodedSourceField(previousSegment) && current.isTextual()) {
try {
JsonNode decoded = objectMapper.readTree(
decodedSourceText(previousSegment, current.asText(), container, outer));
decodedSourceText(previousSegment, current.asText(), container));
if (decoded != null && (decoded.isObject() || decoded.isArray())) {
current = decoded;
}
@@ -401,7 +400,6 @@ public class PipesTargetInvoker {
if (next.isMissingNode() || next.isNull()) {
return null;
}
outer = container;
container = current;
current = next;
previousSegment = segment;
@@ -409,7 +407,7 @@ public class PipesTargetInvoker {
if (!sourceFieldDecoded && isEncodedSourceField(previousSegment) && current.isTextual()) {
// SQS bodies commonly contain a JSON document as a string. Pipes input
// transformation resolves that document when the body itself is selected.
String text = decodedSourceText(previousSegment, current.asText(), container, outer);
String text = decodedSourceText(previousSegment, current.asText(), container);
try {
JsonNode decoded = objectMapper.readTree(text);
if (decoded != null && (decoded.isObject() || decoded.isArray())) {
@@ -439,10 +437,9 @@ public class PipesTargetInvoker {
* is not base64.
*
* @param container the object that holds {@code field}
* @param outer the object that holds {@code container}
*/
private static String decodedSourceText(String field, String text, JsonNode container, JsonNode outer) {
if (!isBase64SourceField(field, container, outer)) {
public static String decodedSourceText(String field, String text, JsonNode container) {
if (!isBase64SourceField(field, container)) {
return text;
}
try {
@@ -453,10 +450,9 @@ public class PipesTargetInvoker {
}
}
private static boolean isBase64SourceField(String field, JsonNode container, JsonNode outer) {
private static boolean isBase64SourceField(String field, JsonNode container) {
if ("data".equals(field)) {
return outer != null && "aws:kinesis".equals(outer.path("eventSource").asText())
&& outer.path("kinesis") == container;
return container != null && "aws:kinesis".equals(container.path("eventSource").asText());
}
if ("key".equals(field) || "value".equals(field)) {
return container != null && isKafkaEventSource(container.path("eventSource").asText());