Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate limiter #278

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More javadoc
  • Loading branch information
andrew4699 committed Sep 18, 2024
commit 48d0f495bea6ecbd0bde66575e1396a1a2890e8b
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
public class NoOpRateLimiter implements RateLimiter {
@Override
public boolean trySpend(double itemCost) {
System.out.println("ANDREW: trySpend returning true");
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Integration test that verifies the timeout behavior for fetching async rate limiters. This is in
* its own test class because the Dropwizard app is per test class and there isn't a great way to
* allow tests to clear the rate limiter cache.
*/
@ExtendWith({
DropwizardExtensionsSupport.class,
PolarisConnectionExtension.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/** Main integration tests for rate limiting */
@ExtendWith({
DropwizardExtensionsSupport.class,
PolarisConnectionExtension.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.apache.polaris.service.test;

// import io.opentelemetry.sdk.common.Clock;
import org.apache.polaris.service.ratelimiting.Clock;

/** Mock clock for setting the current time (as perceived by the rate limiter) to anything */
public class MockClock implements Clock {
long nanos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import org.apache.polaris.service.ratelimiting.RateLimiter;
import org.apache.polaris.service.ratelimiting.RateLimiterFactory;

/**
* Factory that constructs a standard OpenTelemetryRateLimiter but with a mock Clock and an optional
* construction delay
*/
@JsonTypeName("mock")
public class MockRateLimiterFactory implements RateLimiterFactory {
public static MockClock clock = new MockClock();
Expand All @@ -49,7 +53,6 @@ public CompletableFuture<RateLimiter> createRateLimiter(String key, Clock clock)
} catch (InterruptedException e) {
}

System.out.println("ANDREW: got here");
return new OpenTelemetryRateLimiter(
requestsPerSecond, requestsPerSecond * windowSeconds, MockRateLimiterFactory.clock);
});
Expand Down