mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(pipes): validate ParallelizationFactor on Kinesis and DynamoDB sources (#3192)
* feat(pipes): validate ParallelizationFactor on Kinesis and DynamoDB sources SourceParameters is stored as an opaque JsonNode, so ParallelizationFactor already round-tripped through CreatePipe, UpdatePipe and DescribePipe with no bounds applied at all. Apply the AWS constraints in validateSourceConfiguration, which both the create and update paths already run: - reject the field on a source its parameter block does not describe, for example KinesisStreamParameters.ParallelizationFactor on an SQS source - require a numeric, then an integral value - require a value in [1, 10], reported with the offending value The tiering and message shape follow LambdaService.parseScalingConfig, which applies the equivalent MaximumConcurrency bounds for SQS event source mappings. The value is persisted and returned on the wire but not yet enforced: the poller opens an iterator on a single hardcoded shard and delivers one batch at a time, so there is no per-shard concurrency to scale. Record that on both iterator initializers and in an enforcement-status note in the docs, matching how ScalingConfig documents the same gap for Lambda. * fix(pipes): reject a ParallelizationFactor wider than an int asLong hands back the low 64 bits of a BigInteger, so a value such as 2^64 + 5 read as 5 and passed the [1, 10] bounds check: CreatePipe accepted it over raw HTTP and persisted the original digits. Gate the bounds on canConvertToInt and report the value with asText, so an oversized literal is rejected and named in full. Real AWS rejects it too, the field being an int32. Also correct the docs: ListPipes returns pipe summaries and omits SourceParameters entirely, so only DescribePipe echoes the factor back.
This commit is contained in:
1 parent
5864b013d2
commit
5fd89e27bc
6 files changed
+392
-3
No files matched your search
@@ -280,6 +280,11 @@ public class PipesPoller implements Resettable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an iterator on the stream's first shard. Floci polls that one shard and delivers one
|
||||
* batch at a time, so a pipe's {@code ParallelizationFactor} is persisted and returned on the
|
||||
* wire but not enforced here: see docs/services/pipes.md.
|
||||
*/
|
||||
private String initKinesisIterator(String streamName, String region, String accountId) {
|
||||
try {
|
||||
return (accountId != null)
|
||||
@@ -506,6 +511,10 @@ public class PipesPoller implements Resettable {
|
||||
return failed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an iterator on the stream's first shard, under the same single-shard limit as
|
||||
* {@link #initKinesisIterator}.
|
||||
*/
|
||||
private String initDynamoDbIterator(String streamArn) {
|
||||
try {
|
||||
return dynamoDbStreamService.getShardIterator(
|
||||
|
||||
@@ -33,6 +33,9 @@ public class PipesService implements TagHandler, ResourceProvider {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(PipesService.class);
|
||||
|
||||
private static final int MIN_PARALLELIZATION_FACTOR = 1;
|
||||
private static final int MAX_PARALLELIZATION_FACTOR = 10;
|
||||
|
||||
private final StorageBackend<String, Pipe> storage;
|
||||
private final RegionResolver regionResolver;
|
||||
private final PipesPoller poller;
|
||||
@@ -324,11 +327,10 @@ public class PipesService implements TagHandler, ResourceProvider {
|
||||
}
|
||||
if (source.startsWith("smk://")) {
|
||||
requireKafkaParameters(sourceParameters, "SelfManagedKafkaParameters");
|
||||
return;
|
||||
}
|
||||
if (source.contains(":kafka:")) {
|
||||
} else if (source.contains(":kafka:")) {
|
||||
requireKafkaParameters(sourceParameters, "ManagedStreamingKafkaParameters");
|
||||
}
|
||||
validateParallelizationFactor(source, sourceParameters);
|
||||
}
|
||||
|
||||
private void requireKafkaParameters(JsonNode sourceParameters, String parameterBlock) {
|
||||
@@ -342,4 +344,49 @@ public class PipesService implements TagHandler, ResourceProvider {
|
||||
"SourceParameters." + parameterBlock + ".TopicName is required", 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the AWS bounds on {@code ParallelizationFactor}. It is a member of the Kinesis and
|
||||
* DynamoDB Stream parameter blocks only, so a value carried by a block that does not describe
|
||||
* the pipe's source is rejected rather than silently kept.
|
||||
*/
|
||||
private void validateParallelizationFactor(String source, JsonNode sourceParameters) {
|
||||
if (sourceParameters == null) {
|
||||
return;
|
||||
}
|
||||
validateParallelizationFactorBlock(sourceParameters, "KinesisStreamParameters",
|
||||
"Kinesis stream", source.contains(":kinesis:"));
|
||||
validateParallelizationFactorBlock(sourceParameters, "DynamoDBStreamParameters",
|
||||
"DynamoDB Stream", source.contains(":dynamodb:"));
|
||||
}
|
||||
|
||||
private void validateParallelizationFactorBlock(JsonNode sourceParameters, String parameterBlock,
|
||||
String sourceDescription, boolean sourceMatchesBlock) {
|
||||
JsonNode factor = sourceParameters.path(parameterBlock).path("ParallelizationFactor");
|
||||
if (factor.isMissingNode() || factor.isNull()) {
|
||||
return;
|
||||
}
|
||||
String property = "SourceParameters." + parameterBlock + ".ParallelizationFactor";
|
||||
if (!sourceMatchesBlock) {
|
||||
throw new AwsException("ValidationException",
|
||||
property + " is only supported for " + sourceDescription + " sources", 400);
|
||||
}
|
||||
if (!factor.isNumber()) {
|
||||
throw new AwsException("ValidationException",
|
||||
property + " must be a numeric value", 400);
|
||||
}
|
||||
if (!factor.isIntegralNumber()) {
|
||||
throw new AwsException("ValidationException",
|
||||
property + " must be an integer", 400);
|
||||
}
|
||||
// canConvertToInt keeps a value wider than an int out of the bounds check: asLong would
|
||||
// hand back the low 64 bits of a BigInteger, so 2^64 + 5 would read as 5 and be accepted.
|
||||
if (!factor.canConvertToInt()
|
||||
|| factor.intValue() < MIN_PARALLELIZATION_FACTOR
|
||||
|| factor.intValue() > MAX_PARALLELIZATION_FACTOR) {
|
||||
throw new AwsException("ValidationException",
|
||||
property + " must be between " + MIN_PARALLELIZATION_FACTOR + " and "
|
||||
+ MAX_PARALLELIZATION_FACTOR + " (got " + factor.asText() + ")", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user