Skip to content

Commit cdc4ef8

Browse files
committed
feedback
1 parent 72df025 commit cdc4ef8

File tree

6 files changed

+151
-165
lines changed

6 files changed

+151
-165
lines changed

modules/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.google.cloud.http.HttpTransportOptions;
1818
import com.google.cloud.storage.StorageOptions;
1919
import com.google.cloud.storage.StorageRetryStrategy;
20-
import com.sun.net.httpserver.Headers;
2120
import com.sun.net.httpserver.HttpExchange;
2221
import com.sun.net.httpserver.HttpHandler;
2322

@@ -57,8 +56,6 @@
5756
import java.util.Collection;
5857
import java.util.Collections;
5958
import java.util.Map;
60-
import java.util.regex.Matcher;
61-
import java.util.regex.Pattern;
6259

6360
import static org.elasticsearch.common.io.Streams.readFully;
6461
import static org.elasticsearch.repositories.blobstore.BlobStoreTestUtil.randomPurpose;
@@ -106,7 +103,11 @@ protected Map<String, HttpHandler> createHttpHandlers() {
106103

107104
@Override
108105
protected HttpHandler createErroneousHttpHandler(final HttpHandler delegate) {
109-
return new GoogleErroneousHttpHandler(delegate, randomIntBetween(2, 3));
106+
if (delegate instanceof FakeOAuth2HttpHandler) {
107+
return new GoogleErroneousHttpHandler(delegate, randomIntBetween(2, 3));
108+
} else {
109+
return new GoogleCloudStorageStatsCollectorHttpHandler(new GoogleErroneousHttpHandler(delegate, randomIntBetween(2, 3)));
110+
}
110111
}
111112

112113
@Override
@@ -222,6 +223,11 @@ public void testWriteFileMultipleOfChunkSize() throws IOException {
222223
}
223224
}
224225

226+
@Override
227+
public void testRequestStats() throws Exception {
228+
super.testRequestStats();
229+
}
230+
225231
public static class TestGoogleCloudStoragePlugin extends GoogleCloudStoragePlugin {
226232

227233
public TestGoogleCloudStoragePlugin(Settings settings) {
@@ -357,42 +363,24 @@ protected boolean canFailRequest(final HttpExchange exchange) {
357363
@SuppressForbidden(reason = "this tests uses a HttpServer to emulate an GCS endpoint")
358364
private static class GoogleCloudStorageStatsCollectorHttpHandler extends HttpStatsCollectorHandler {
359365

360-
public static final Pattern contentRangeMatcher = Pattern.compile("bytes \\d+-(\\d+)/(\\d+)");
361-
362366
GoogleCloudStorageStatsCollectorHttpHandler(final HttpHandler delegate) {
363367
super(delegate);
364368
}
365369

366370
@Override
367371
public void maybeTrack(HttpExchange exchange) {
368372
final String request = exchange.getRequestMethod() + " " + exchange.getRequestURI().toString();
369-
final Headers requestHeaders = exchange.getRequestHeaders();
370373
if (Regex.simpleMatch("GET */storage/v1/b/*/o/*", request)) {
371374
trackRequest(StorageOperation.GET.key());
372375
} else if (Regex.simpleMatch("GET /storage/v1/b/*/o*", request)) {
373376
trackRequest(StorageOperation.LIST.key());
374377
} else if (Regex.simpleMatch("POST /upload/storage/v1/b/*uploadType=resumable*", request)) {
375-
// Resumable uploads are billed as a single operation, that's the reason we're tracking the request only first part
376-
// See https://cloud.google.com/storage/docs/resumable-uploads#introduction
378+
trackRequest(StorageOperation.INSERT.key());
379+
} else if (Regex.simpleMatch("PUT /upload/storage/v1/b/*uploadType=resumable*", request)) {
377380
trackRequest(StorageOperation.INSERT.key());
378381
} else if (Regex.simpleMatch("POST /upload/storage/v1/b/*uploadType=multipart*", request)) {
379382
trackRequest(StorageOperation.INSERT.key());
380383
}
381384
}
382-
383-
boolean isLastPart(Headers requestHeaders) {
384-
if (requestHeaders.containsKey("Content-range") == false) return false;
385-
386-
// https://cloud.google.com/storage/docs/json_api/v1/parameters#contentrange
387-
final String contentRange = requestHeaders.getFirst("Content-range");
388-
389-
final Matcher matcher = contentRangeMatcher.matcher(contentRange);
390-
391-
if (matcher.matches() == false) return false;
392-
393-
String upperBound = matcher.group(1);
394-
String totalLength = matcher.group(2);
395-
return Integer.parseInt(upperBound) == Integer.parseInt(totalLength) - 1;
396-
}
397385
}
398386
}

0 commit comments

Comments
 (0)