Skip to content

chore(Datastore): Add Operation and Attempt metrics for HttpJson transport#12063

Open
lqiu96 wants to merge 16 commits intomainfrom
http-metrics-operations-attempt
Open

chore(Datastore): Add Operation and Attempt metrics for HttpJson transport#12063
lqiu96 wants to merge 16 commits intomainfrom
http-metrics-operations-attempt

Conversation

@lqiu96
Copy link
Member

@lqiu96 lqiu96 commented Mar 10, 2026

This adds operation and attempt metrics that are being recorded via Gax. Since gRPC can integrate natively with Gax, this metrics are captured. This instruments the metrics to be collected via HttpJson.

Sample view of the metrics collected:
image

@lqiu96 lqiu96 requested a review from jinseopkim0 March 10, 2026 19:25
Copy link
Contributor

@jinseopkim0 jinseopkim0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/Datatore/Datastore/ in title of the PR.

<O> O invokeRpc(Callable<O> block, String startSpan, String methodName) {
TraceUtil.Span span = otelTraceUtil.startSpan(startSpan);
Stopwatch stopwatch = isHttpTransport ? Stopwatch.createStarted() : null;
String operationStatus = StatusCode.Code.OK.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an exception other than RetryHelperException occurs, then we would be returning operationStatus = OK in the finally block, right? Would it be better to initially set operationStatus to something like UNKNOWN and set it to OK just before returning?

e.g.

String operationStatus = StatusCode.Code.UNKNOWN.toString();
try (TraceUtil.Scope ignored = span.makeCurrent()) {
    // ...
    O result = RetryHelper.runWithRetries(...);
    operationStatus = StatusCode.Code.OK.toString();
    return result;
} catch (RetryHelperException e) {
    // ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a TODO in the link:

// TODO: remove RetryHelperException, throw InterruptedException or
// ExecutionException#getCause() explicitly

I'm thinking it would be more future-proof if we do not assume that all exceptions will be RetryHelperExceptions. (Also, would it be possible for JVM throw errors like OutOfMemoryErrors?) WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing that in RetryHelper may happen in the future and that change impacts quite a bit of code in java-core. I don't think this PR needs to plan for it.

If I catch for Exception, then I'll need to modify code here: https://github.com/googleapis/sdk-platform-java/blob/7ab6d2e5784f264558b7aca6f23e771361dbea3a/java-core/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java#L270

as the logic in DatstoreException.translateAndThrow(e) calls BaseServiceException.translate(ex);

I'll update it to default to UNKNOWN and we can update the RetryHelper in a future change

@lqiu96 lqiu96 changed the title chore(Datatore): Add Operation and Attempt metrics for HttpJson transport chore(Datastore): Add Operation and Attempt metrics for HttpJson transport Mar 10, 2026
@lqiu96 lqiu96 requested a review from jinseopkim0 March 10, 2026 21:16
@lqiu96 lqiu96 marked this pull request as ready for review March 11, 2026 20:03
@lqiu96 lqiu96 requested a review from a team as a code owner March 11, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants