From b49a7b04f2005d3338c537fd9c007545205796cb Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Fri, 27 Sep 2024 20:46:06 -0700 Subject: [PATCH] Handle special case --- .../java/io/grpc/xds/internal/rlqs/RlqsEngine.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xds/src/main/java/io/grpc/xds/internal/rlqs/RlqsEngine.java b/xds/src/main/java/io/grpc/xds/internal/rlqs/RlqsEngine.java index c1090110afd..8b1f159ec07 100644 --- a/xds/src/main/java/io/grpc/xds/internal/rlqs/RlqsEngine.java +++ b/xds/src/main/java/io/grpc/xds/internal/rlqs/RlqsEngine.java @@ -56,6 +56,10 @@ public RlqsEngine( public RlqsRateLimitResult rateLimit(HttpMatchInput input) { RlqsBucketSettings bucketSettings = bucketMatchers.match(input); RlqsBucketId bucketId = bucketSettings.toBucketId(input); + // Special case when bucket id builder not set. + if (bucketId == null) { + return rateLimitWithoutReports(bucketSettings); + } RlqsBucket bucket = bucketCache.getOrCreate(bucketId, bucketSettings, newBucket -> { // Called if a new bucket was created. scheduleImmediateReport(newBucket); @@ -64,6 +68,13 @@ public RlqsRateLimitResult rateLimit(HttpMatchInput input) { return bucket.rateLimit(); } + private static RlqsRateLimitResult rateLimitWithoutReports(RlqsBucketSettings bucketSettings) { + if (bucketSettings.noAssignmentStrategy().rateLimit()) { + return RlqsRateLimitResult.deny(bucketSettings.denyResponse()); + } + return RlqsRateLimitResult.allow(); + } + private void onBucketsUpdate(List bucketActions) { // TODO(sergiitk): [impl] ensure no more than 1 update at a time. for (RlqsUpdateBucketAction bucketAction : bucketActions) {