-
Notifications
You must be signed in to change notification settings - Fork 231
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
add logs with request latency for json readData/metaData API #749
Open
mayanks
wants to merge
2
commits into
GoogleCloudDataproc:master
Choose a base branch
from
mayanks:master
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import static com.google.common.base.Strings.nullToEmpty; | ||
import static java.lang.Math.min; | ||
import static java.lang.Math.toIntExact; | ||
import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
|
||
import com.google.api.client.http.HttpHeaders; | ||
import com.google.api.client.http.HttpResponse; | ||
|
@@ -39,6 +40,7 @@ | |
import com.google.cloud.hadoop.util.ResilientOperation; | ||
import com.google.cloud.hadoop.util.RetryDeterminer; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.base.Stopwatch; | ||
import com.google.common.base.Suppliers; | ||
import com.google.common.flogger.GoogleLogger; | ||
import java.io.ByteArrayInputStream; | ||
|
@@ -66,6 +68,8 @@ public class GoogleCloudStorageReadChannel implements SeekableByteChannel { | |
|
||
private static final String GZIP_ENCODING = "gzip"; | ||
|
||
private static final String GCS_REQUEST_ID_HEADER = "x-guploader-uploadid"; | ||
|
||
// GCS access instance. | ||
private final Storage gcs; | ||
|
||
|
@@ -104,6 +108,8 @@ public class GoogleCloudStorageReadChannel implements SeekableByteChannel { | |
// Size of the contentChannel. | ||
private long contentChannelEnd = -1; | ||
|
||
private Stopwatch stopwatch; | ||
|
||
// Whether to use bounded range requests or streaming requests. | ||
@VisibleForTesting boolean randomAccess; | ||
|
||
|
@@ -229,6 +235,7 @@ protected GoogleCloudStorageItemInfo getInitialMetadata() throws IOException { | |
/** Returns {@link GoogleCloudStorageItemInfo} used to initialize metadata in constructor. */ | ||
private GoogleCloudStorageItemInfo fetchInitialMetadata() throws IOException { | ||
StorageObject object; | ||
Stopwatch metadataStopwatch = Stopwatch.createStarted(); | ||
try { | ||
// Request only fields that are used for metadata initialization | ||
Storage.Objects.Get getObject = createRequest().setFields("contentEncoding,generation,size"); | ||
|
@@ -239,11 +246,26 @@ private GoogleCloudStorageItemInfo fetchInitialMetadata() throws IOException { | |
RetryDeterminer.SOCKET_ERRORS, | ||
IOException.class, | ||
sleeper); | ||
|
||
logger.atFinest().log( | ||
"GoogleCloudStorageReadChannel:getMetadata complete context:%d,time:%d,resource:%s,requestId:%s", | ||
Thread.currentThread().getId(), | ||
metadataStopwatch.elapsed(MILLISECONDS), | ||
resourceId, | ||
getObject.getLastResponseHeaders().getFirstHeaderStringValue(GCS_REQUEST_ID_HEADER)); | ||
} catch (IOException e) { | ||
throw errorExtractor.itemNotFound(e) | ||
? createFileNotFoundException(resourceId, e) | ||
: new IOException("Error reading " + resourceId, e); | ||
if (errorExtractor.itemNotFound(e)) { | ||
throw createFileNotFoundException(resourceId, e); | ||
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. We need to add a log here as well |
||
} else { | ||
logger.atSevere().withCause(e).log( | ||
"GoogleCloudStorageReadChannel:getMetadata exception context:%d,time:%d,resource:%s", | ||
Thread.currentThread().getId(), metadataStopwatch.elapsed(MILLISECONDS), resourceId); | ||
throw new IOException("Error reading " + resourceId, e); | ||
} | ||
} catch (InterruptedException e) { | ||
logger.atSevere().withCause(e).log( | ||
"GoogleCloudStorageReadChannel:getMetadata exception context:%d,time:%d,resource:%s", | ||
Thread.currentThread().getId(), metadataStopwatch.elapsed(MILLISECONDS), resourceId); | ||
Thread.currentThread().interrupt(); | ||
throw new IOException("Thread interrupt received.", e); | ||
} | ||
|
@@ -398,8 +420,12 @@ public int read(ByteBuffer buffer) throws IOException { | |
|
||
++retriesAttempted; | ||
logger.atWarning().withCause(ioe).log( | ||
"Failed read retry #%s/%s for '%s'. Sleeping...", | ||
retriesAttempted, maxRetries, resourceId); | ||
"Failed read context:%d,retry:%s/%s,time:%d,resource:%s", | ||
Thread.currentThread().getId(), | ||
retriesAttempted, | ||
maxRetries, | ||
stopwatch.elapsed(MILLISECONDS), | ||
resourceId); | ||
try { | ||
boolean backOffSuccessful = BackOffUtils.next(sleeper, readBackOff.get()); | ||
if (!backOffSuccessful) { | ||
|
@@ -930,7 +956,17 @@ protected InputStream openStream(long bytesToRead) throws IOException { | |
Storage.Objects.Get getObject = createDataRequest(rangeHeader); | ||
HttpResponse response; | ||
try { | ||
stopwatch = Stopwatch.createStarted(); | ||
response = getObject.executeMedia(); | ||
|
||
logger.atFinest().log( | ||
"openStream complete context:%d,time:%d,bytesToRead:%d,rangeSize:%d,resource:%s,requestId:%s", | ||
Thread.currentThread().getId(), | ||
stopwatch.elapsed(MILLISECONDS), | ||
bytesToRead, | ||
contentChannelEnd - contentChannelPosition, | ||
resourceId, | ||
response.getHeaders().getFirstHeaderStringValue(GCS_REQUEST_ID_HEADER)); | ||
// TODO(b/110832992): validate response range header against expected/request range | ||
} catch (IOException e) { | ||
if (!metadataInitialized && errorExtractor.rangeNotSatisfiable(e) && currentPosition == 0) { | ||
|
@@ -995,13 +1031,21 @@ protected InputStream openStream(long bytesToRead) throws IOException { | |
cacheFooter(response); | ||
if (retriesCount != 0) { | ||
logger.atInfo().log( | ||
"Successfully cached footer after %s retries for '%s'", retriesCount, resourceId); | ||
"Successfully cached footer context:%d,retries:%s,time:%d,resource:%s", | ||
Thread.currentThread().getId(), | ||
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. I don't think we need to log the threadId, it should already be part of the logging pattern (thread Id/name) |
||
retriesCount, | ||
stopwatch.elapsed(MILLISECONDS), | ||
resourceId); | ||
} | ||
break; | ||
} catch (IOException footerException) { | ||
logger.atInfo().withCause(footerException).log( | ||
"Failed to prefetch footer (retry #%s/%s) for '%s'", | ||
retriesCount + 1, maxRetries, resourceId); | ||
logger.atWarning().withCause(footerException).log( | ||
"Failed to prefetch footer context:%d,retry:%s/%s,time:%d,resource:%s", | ||
Thread.currentThread().getId(), | ||
retriesCount + 1, | ||
maxRetries, | ||
stopwatch.elapsed(MILLISECONDS), | ||
resourceId); | ||
if (retriesCount == 0) { | ||
readBackOff.get().reset(); | ||
} | ||
|
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.
we don't need to log the class name
GoogleCloudStorageReadChannel
logging pattern have the fully qualified class name