-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add GCS telemtry with ThreadLocal #125452
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b5da931
add GCS telemtry with threadlocals
mhl-b 4af0aed
Update docs/changelog/125452.yaml
mhl-b 63166e4
fix compilation
mhl-b 5b7fe05
Merge branch 'gcp-metrics-threadlocal' of github.com:mhl-b/elasticsea…
mhl-b 0d4f8f8
Merge branch 'main' into gcp-metrics-threadlocal
mhl-b 761f358
Merge remote-tracking branch 'upstream/main' into gcp-metrics-threadl…
mhl-b 111e19b
update
mhl-b 1086bc7
cleanup
mhl-b c252f22
Merge remote-tracking branch 'upstream/main' into gcp-metrics-threadl…
mhl-b 1ae87f5
typo
mhl-b 5a30e10
test fix
mhl-b bbaa3a7
temp test fix
mhl-b d4f30d8
fix metrics for serverless
mhl-b 72df025
serverless fix
mhl-b cdc4ef8
feedback
mhl-b e0bde89
remove client CacheKey
mhl-b 8f8a73c
feedback
mhl-b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 125452 | ||
summary: Add GCS telemetry with `ThreadLocal` | ||
area: Snapshot/Restore | ||
type: enhancement | ||
issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
import com.google.cloud.http.HttpTransportOptions; | ||
import com.google.cloud.storage.StorageOptions; | ||
import com.google.cloud.storage.StorageRetryStrategy; | ||
import com.sun.net.httpserver.Headers; | ||
import com.sun.net.httpserver.HttpExchange; | ||
import com.sun.net.httpserver.HttpHandler; | ||
|
||
|
@@ -57,15 +56,12 @@ | |
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static org.elasticsearch.common.io.Streams.readFully; | ||
import static org.elasticsearch.repositories.blobstore.BlobStoreTestUtil.randomPurpose; | ||
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.CREDENTIALS_FILE_SETTING; | ||
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.ENDPOINT_SETTING; | ||
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageClientSettings.TOKEN_URI_SETTING; | ||
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageOperationsStats.Operation; | ||
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageRepository.BASE_PATH; | ||
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageRepository.BUCKET; | ||
import static org.elasticsearch.repositories.gcs.GoogleCloudStorageRepository.CLIENT_NAME; | ||
|
@@ -107,7 +103,11 @@ protected Map<String, HttpHandler> createHttpHandlers() { | |
|
||
@Override | ||
protected HttpHandler createErroneousHttpHandler(final HttpHandler delegate) { | ||
return new GoogleErroneousHttpHandler(delegate, randomIntBetween(2, 3)); | ||
if (delegate instanceof FakeOAuth2HttpHandler) { | ||
return new GoogleErroneousHttpHandler(delegate, randomIntBetween(2, 3)); | ||
} else { | ||
return new GoogleCloudStorageStatsCollectorHttpHandler(new GoogleErroneousHttpHandler(delegate, randomIntBetween(2, 3))); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -223,15 +223,20 @@ public void testWriteFileMultipleOfChunkSize() throws IOException { | |
} | ||
} | ||
|
||
@Override | ||
public void testRequestStats() throws Exception { | ||
super.testRequestStats(); | ||
} | ||
|
||
public static class TestGoogleCloudStoragePlugin extends GoogleCloudStoragePlugin { | ||
|
||
public TestGoogleCloudStoragePlugin(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
protected GoogleCloudStorageService createStorageService(Settings settings) { | ||
return new GoogleCloudStorageService(settings) { | ||
protected GoogleCloudStorageService createStorageService(boolean isServerless) { | ||
return new GoogleCloudStorageService() { | ||
@Override | ||
StorageOptions createStorageOptions( | ||
final GoogleCloudStorageClientSettings gcsClientSettings, | ||
|
@@ -277,7 +282,8 @@ public Map<String, Repository.Factory> getRepositories( | |
this.storageService, | ||
clusterService, | ||
bigArrays, | ||
recoverySettings | ||
recoverySettings, | ||
new GcsRepositoryStatsCollector() | ||
) { | ||
@Override | ||
protected GoogleCloudStorageBlobStore createBlobStore() { | ||
|
@@ -288,7 +294,8 @@ protected GoogleCloudStorageBlobStore createBlobStore() { | |
storageService, | ||
bigArrays, | ||
randomIntBetween(1, 8) * 1024, | ||
BackoffPolicy.noBackoff() | ||
BackoffPolicy.noBackoff(), | ||
this.statsCollector() | ||
) { | ||
@Override | ||
long getLargeBlobThresholdInBytes() { | ||
|
@@ -356,43 +363,24 @@ protected boolean canFailRequest(final HttpExchange exchange) { | |
@SuppressForbidden(reason = "this tests uses a HttpServer to emulate an GCS endpoint") | ||
private static class GoogleCloudStorageStatsCollectorHttpHandler extends HttpStatsCollectorHandler { | ||
|
||
public static final Pattern contentRangeMatcher = Pattern.compile("bytes \\d+-(\\d+)/(\\d+)"); | ||
|
||
GoogleCloudStorageStatsCollectorHttpHandler(final HttpHandler delegate) { | ||
super(delegate); | ||
} | ||
|
||
@Override | ||
public void maybeTrack(HttpExchange exchange) { | ||
final String request = exchange.getRequestMethod() + " " + exchange.getRequestURI().toString(); | ||
final Headers requestHeaders = exchange.getRequestHeaders(); | ||
if (Regex.simpleMatch("GET */storage/v1/b/*/o/*", request)) { | ||
trackRequest(Operation.GET_OBJECT.key()); | ||
trackRequest(StorageOperation.GET.key()); | ||
} else if (Regex.simpleMatch("GET /storage/v1/b/*/o*", request)) { | ||
trackRequest(Operation.LIST_OBJECTS.key()); | ||
} else if (Regex.simpleMatch("PUT /upload/storage/v1/b/*uploadType=resumable*", request) && isLastPart(requestHeaders)) { | ||
// Resumable uploads are billed as a single operation, that's the reason we're tracking | ||
// the request only when it's the last part. | ||
// See https://cloud.google.com/storage/docs/resumable-uploads#introduction | ||
trackRequest(Operation.INSERT_OBJECT.key()); | ||
trackRequest(StorageOperation.LIST.key()); | ||
} else if (Regex.simpleMatch("POST /upload/storage/v1/b/*uploadType=resumable*", request)) { | ||
trackRequest(StorageOperation.INSERT.key()); | ||
} else if (Regex.simpleMatch("PUT /upload/storage/v1/b/*uploadType=resumable*", request)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. count all requests now, not operations |
||
trackRequest(StorageOperation.INSERT.key()); | ||
} else if (Regex.simpleMatch("POST /upload/storage/v1/b/*uploadType=multipart*", request)) { | ||
trackRequest(Operation.INSERT_OBJECT.key()); | ||
trackRequest(StorageOperation.INSERT.key()); | ||
} | ||
} | ||
|
||
boolean isLastPart(Headers requestHeaders) { | ||
if (requestHeaders.containsKey("Content-range") == false) return false; | ||
|
||
// https://cloud.google.com/storage/docs/json_api/v1/parameters#contentrange | ||
final String contentRange = requestHeaders.getFirst("Content-range"); | ||
|
||
final Matcher matcher = contentRangeMatcher.matcher(contentRange); | ||
|
||
if (matcher.matches() == false) return false; | ||
|
||
String upperBound = matcher.group(1); | ||
String totalLength = matcher.group(2); | ||
return Integer.parseInt(upperBound) == Integer.parseInt(totalLength) - 1; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helper to run from ide