-
Notifications
You must be signed in to change notification settings - Fork 44
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
feat: add opencensus tracing/stats support #130
feat: add opencensus tracing/stats support #130
Conversation
Codecov Report
@@ Coverage Diff @@
## master #130 +/- ##
============================================
- Coverage 58.30% 57.17% -1.13%
Complexity 384 384
============================================
Files 47 48 +1
Lines 2331 2377 +46
Branches 261 264 +3
============================================
Hits 1359 1359
- Misses 865 911 +46
Partials 107 107
Continue to review full report at Codecov.
|
@mayurkale22, would you be able to take a quick look at this PR to see if OpenCensus is being used correctly? Thanks heaps. |
d16bb7e
to
da7fead
Compare
pom.xml
Outdated
@@ -162,6 +162,7 @@ | |||
<guava.version>29.0-android</guava.version> | |||
<threeten.version>1.4.4</threeten.version> | |||
<javax.annotations.version>1.3.2</javax.annotations.version> | |||
<opencensus.version>0.24.0</opencensus.version> |
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.
I would use latest version: 0.26.0
.
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.
Recently google-cloud-shared-dependencies was added in this client which is pull latest version automatically.
@@ -546,6 +593,8 @@ ByteString requestTransactionId( | |||
|
|||
com.google.datastore.v1.BeginTransactionResponse beginTransaction( | |||
final com.google.datastore.v1.BeginTransactionRequest requestPb) { | |||
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_BEGINTRANSACTION); | |||
Scope scope = traceUtil.getTracer().withSpan(span); |
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.
Personally, I prefer to use try-with-resources for scope. It implements AutoClosable, so it'll be closed when the try block ends. Ex:
try (Scope s = tracer.withSpan(span)) {
... rest of the logic
}
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.
Done
|
||
DatastoreImpl(DatastoreOptions options) { | ||
super(options); | ||
this.datastoreRpc = options.getDatastoreRpcV1(); | ||
retrySettings = | ||
MoreObjects.firstNonNull(options.getRetrySettings(), ServiceOptions.getNoRetrySettings()); | ||
traceUtil = TraceUtil.getInstance(); |
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.
just set this in the declaration on line 57
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.
Done
@@ -131,29 +136,41 @@ public T call() throws DatastoreException { | |||
@Override | |||
public <T> T runInTransaction(final TransactionCallable<T> callable) { | |||
final DatastoreImpl self = this; |
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.
this self variable seems pointless
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.
Done
throw DatastoreException.translateAndThrow(e); | ||
} finally { | ||
scope.close(); | ||
span.end(TraceUtil.END_SPAN_OPTIONS); | ||
} | ||
} | ||
|
||
@Override | ||
public <T> T runInTransaction( | ||
final TransactionCallable<T> callable, TransactionOptions transactionOptions) { | ||
final DatastoreImpl self = this; |
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.
ditto
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.
Done
} | ||
} | ||
|
||
@Override | ||
public <T> T runInTransaction( | ||
final TransactionCallable<T> callable, TransactionOptions transactionOptions) { | ||
final DatastoreImpl self = this; | ||
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_TRANSACTION); | ||
Scope scope = traceUtil.getTracer().withSpan(span); |
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.
You can use try with resources for the scope
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.
Done
@@ -173,6 +190,8 @@ public T call() throws DatastoreException { | |||
|
|||
com.google.datastore.v1.RunQueryResponse runQuery( | |||
final com.google.datastore.v1.RunQueryRequest requestPb) { | |||
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_RUNQUERY); | |||
Scope scope = traceUtil.getTracer().withSpan(span); |
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.
You can use try with resources for the scope (unless the order of closing the span would be wrong?)
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.
Done
* Helper class for tracing utility. It is used for instrumenting {@link HttpDatastoreRpc} with Open | ||
* Census APIs. | ||
* | ||
* <p>TraceUtil Instance are created by the {@link TraceUtil#getInstance()} method. |
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.
instances
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.
Done
*/ | ||
public class TraceUtil { | ||
private final Tracer tracer = Tracing.getTracer(); | ||
private static TraceUtil traceUtil; |
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.
final
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.
Done
* | ||
* @return An instance of {@link TraceUtil} | ||
*/ | ||
public static TraceUtil getInstance() { |
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.
no need, just create a TraceUtil on the field
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.
Done
// Open Census initialization | ||
CensusHttpModule censusHttpModule = | ||
new CensusHttpModule(TraceUtil.getInstance().getTracer(), true); | ||
delegate = censusHttpModule.getHttpRequestInitializer(delegate); |
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.
try to avoid reassigning local variables
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.
Done
@mayurkale22 PTAL |
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.
Added one comment, overall LGTM.
@@ -397,7 +416,10 @@ protected Entity computeNext() { | |||
EXCEPTION_HANDLER, | |||
getOptions().getClock()); | |||
} catch (RetryHelperException e) { | |||
span.setStatus(Status.UNKNOWN.withDescription(e.getMessage())); |
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.
Any specific reason for Status.UNKNOWN
instead of status.INTERNAL
? Generally, an example of (UNKNOWN) where this error may be returned is if a Status value received from another address space belongs to an error-space that is not known in this address space. On the other side, Internal errors mean some invariants expected by underlying system has been broken.
Also, DEADLINE_EXCEEDED
can be useful in case of retries exceeded.
Having said that, I am not familiar with datastore codebase. Feel free to ignore if you disagree.
@elharo PTAL |
@elharo gentle ping |
26986bd
to
0c18852
Compare
0c18852
to
9d85b03
Compare
@BenWhitehead @elharo PTAL |
google-cloud-datastore/src/main/java/com/google/cloud/datastore/TraceUtil.java
Show resolved
Hide resolved
🤖 I have created a release \*beep\* \*boop\* --- ## [1.104.0](https://www.github.com/googleapis/java-datastore/compare/v1.103.0...v1.104.0) (2020-06-17) ### Features * add opencensus tracing/stats support for Datastore RPC operations ([#130](https://www.github.com/googleapis/java-datastore/issues/130)) ([5aee52f](https://www.github.com/googleapis/java-datastore/commit/5aee52f5013d6780e523e0c6d7d00a1826b83b9b)) * add support to customize gcloud command of LocalDatastoreHelper ([#137](https://www.github.com/googleapis/java-datastore/issues/137)) ([976d979](https://www.github.com/googleapis/java-datastore/commit/976d9791572117dc703d8d7d6963bdd6603ecd63)) ### Bug Fixes * fix version number in changelog to correctly reflect what was released to maven central ([#145](https://www.github.com/googleapis/java-datastore/issues/145)) ([c509a2a](https://www.github.com/googleapis/java-datastore/commit/c509a2a4229f864edef8681677d73f3c7be1101f)) ### Dependencies * update dependency com.google.cloud:google-cloud-shared-dependencies to v0.8.0 ([#161](https://www.github.com/googleapis/java-datastore/issues/161)) ([39c8d72](https://www.github.com/googleapis/java-datastore/commit/39c8d723b318d08ca494b71167eaa80b1df6423d)) * update dependency com.google.cloud:google-cloud-shared-dependencies to v0.8.1 ([#163](https://www.github.com/googleapis/java-datastore/issues/163)) ([7bfa07e](https://www.github.com/googleapis/java-datastore/commit/7bfa07eb3a7cf84fcf3e19f6a33914162fa28499)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please).
Fixes #109