Skip to content

Commit

Permalink
Fix RedissonRateLimiter issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhiguo committed Jan 15, 2025
1 parent a4215dd commit b0dcb71
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import com.jd.live.agent.governance.policy.lane.LaneSpace;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

/**
* The {@code LaneMetadata} class encapsulates the metadata for a lane request.
*/
@Getter
@Builder
@ToString
public class LaneMetadata {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public abstract class AbstractRateLimiterGroup extends AbstractRateLimiter {
*/
public AbstractRateLimiterGroup(RateLimitPolicy policy) {
super(policy, TimeUnit.NANOSECONDS);
}

/**
* Initializes the rate limiter group by creating the individual rate limiters
* based on the sliding windows defined in the rate limit policy.
*/
public void init() {
int i = 0;
for (SlidingWindow window : policy.getSlidingWindows()) {
limiters.add(create(window, policy.getName() + "-" + i++));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class LeakyBucketLimiterGroup extends AbstractRateLimiterGroup {

public LeakyBucketLimiterGroup(RateLimitPolicy policy) {
super(policy);
init();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SmoothBurstyLimiterGroup extends AbstractRateLimiterGroup {

public SmoothBurstyLimiterGroup(RateLimitPolicy policy) {
super(policy);
init();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SmoothWarmupLimiterGroup extends AbstractRateLimiterGroup {

public SmoothWarmupLimiterGroup(RateLimitPolicy policy) {
super(policy);
init();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ public String get(@RequestParam("id") Integer id, HttpServletRequest servletRequ
default:
servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
}
return status.getDescription();
return status.getDescription() == null ? "Unknown error" : status.getDescription();
} catch (IllegalStateException e) {
servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return e.getMessage();
} catch (Exception e) {
servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
return e.getMessage();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public void get(UserGetRequest request, StreamObserver<UserGetResponse> response
responseObserver.onError(new RuntimeException("error"));
return;
}
if (request.getId() >= 100) {
try {
Thread.sleep(request.getId());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
UserGetResponse.Builder builder = UserGetResponse.newBuilder();
builder.setId(request.getId())
.setName("index:" + request.getId() + ", time:" + System.currentTimeMillis())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class RedissonRateLimiterGroup extends AbstractRateLimiterGroup {
public RedissonRateLimiterGroup(RedisClientManager manager, RateLimitPolicy policy) {
super(policy);
this.manager = manager;
init();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Resilience4jRateLimiterGroup extends AbstractRateLimiterGroup {

public Resilience4jRateLimiterGroup(RateLimitPolicy policy) {
super(policy);
init();
}

@Override
Expand Down

0 comments on commit b0dcb71

Please sign in to comment.