Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package google.registry.beam.spec11;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.http.HttpHeaders.RETRY_AFTER;
import static org.apache.http.HttpStatus.SC_OK;
import static org.apache.http.HttpStatus.SC_TOO_MANY_REQUESTS;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
Expand All @@ -33,6 +35,7 @@
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.windowing.GlobalWindow;
import org.apache.beam.sdk.values.KV;
import org.apache.http.Header;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
Expand Down Expand Up @@ -229,6 +232,14 @@ private void processResponse(
throws IOException {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != SC_OK) {
if (statusCode == SC_TOO_MANY_REQUESTS) {
Header retryAfterHeader = response.getFirstHeader(RETRY_AFTER);
if (retryAfterHeader != null) {
logger.atWarning().log(
"SafeBrowsing API returned 429 with Retry-After header: %s",
retryAfterHeader.getValue());
}
}
throw new IOException(
String.format("Got unexpected status code %s from response.", statusCode));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Spec11PipelineOptions provideOptions() {
EvaluateSafeBrowsingFn provideSafeBrowsingFn(
Spec11PipelineOptions options, Clock clock, Sleeper sleeper) {
// Have a noticeably longer backoff for SafeBrowsing retries to mitigate any 429s
Retrier safeBrowsingRetrier = new Retrier(sleeper, 4, 1000L);
Retrier safeBrowsingRetrier = new Retrier(sleeper, 9, 1000L);
return new EvaluateSafeBrowsingFn(
options.getSafeBrowsingApiKey(), safeBrowsingRetrier, clock);
}
Expand Down
Loading