Skip to content

Conversation

@AgraVator
Copy link
Contributor

@AgraVator AgraVator commented May 14, 2025

implements A96

@AgraVator AgraVator force-pushed the implement-otel-retry-metric branch from a7a16ce to 3529769 Compare May 27, 2025 07:02
@AgraVator AgraVator force-pushed the implement-otel-retry-metric branch from 3529769 to bd69ed5 Compare June 24, 2025 11:38
Optional<MetricData> metric = openTelemetryTesting.getMetrics().stream()
.filter(m -> m.getName().equals(metricName))
.findFirst();
if (metric.isPresent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When will this metric not be present for the operations done by the tested on the tracer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whenever they are not enabled or have default values

Copy link
Contributor

Choose a reason for hiding this comment

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

As this is test code, it is risky to have the assertion inside an if statement. If the absence of the metric is not expected, then it should not cause the test to pass.

@AgraVator AgraVator requested a review from kannanjgithub July 14, 2025 06:58
Optional<MetricData> metric = openTelemetryTesting.getMetrics().stream()
.filter(m -> m.getName().equals(metricName))
.findFirst();
if (metric.isPresent()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whenever they are not enabled or have default values

Comment on lines +352 to 357
if (info.isTransparentRetry()) {
transparentRetriesPerCall.incrementAndGet();
} else if (info.isHedging()) {
hedgedAttemptsPerCall.incrementAndGet();
} else {
attemptsPerCall.incrementAndGet();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this not assume them to be mutually exclusive ?

return new ClientStreamTracer() {};
}
if (++activeStreams == 1 && attemptStopwatch.isRunning()) {
attemptStopwatch.stop();
Copy link
Member

Choose a reason for hiding this comment

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

This attemptStopwatch looks to be for grpc.client.attempt.duration? This looks busted (pre-existing). It looks like attemptStopwatch is tracking the retry_delay right now, as it only runs when there are no streams. Each stream needs its own attempt stopwatch, right? But right now there is only one per call.

Copy link
Contributor

Choose a reason for hiding this comment

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

CallAttemptsTracerFactory.attemptEnded is for recording a stream ended (StatsTraceContext.streamClosed calls it), so for the first attempt and each retry attempt end the attemptStopWatch is started, so it does measure the time between stream attempts, not per call.

But there is a problem. RetriableStream creates its own anonymous tracerFactory and not take the one put by MetricsClientInterceptor in the callOptions, so this needs to change.

I have a question. A call can only have 1 stream, and the only way the activeStreams can be > 1 is if the tracer factory is shared between calls (and that would mess up the calculation for time between stream attempts anyway). The way the OpenTelemetryMetricsModule.MetricsClientInterceptor creates the factory though is per call, not shared between calls. So we we can never have > 1 streams and there should be no need for synchronization either.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I said about RetriableStream's anonymous tracerFactory is not a problem, StatsTraceContext.streamClosed iterates over all tracers and calls stream closed on each of them.

}
if (++activeStreams == 1 && attemptStopwatch.isRunning()) {
attemptStopwatch.stop();
retryDelayNanos = attemptStopwatch.elapsed(TimeUnit.NANOSECONDS);
Copy link
Member

Choose a reason for hiding this comment

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

I can't tell how retryDelayNanos is synchronized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its the same as with OpenCensus

@AgraVator AgraVator requested a review from ejona86 August 13, 2025 11:27
@AgraVator AgraVator merged commit d380191 into grpc:master Sep 24, 2025
16 checks passed
AgraVator added a commit to AgraVator/grpc-java that referenced this pull request Sep 26, 2025
AgraVator added a commit to AgraVator/grpc-java that referenced this pull request Sep 26, 2025
AgraVator added a commit to AgraVator/grpc-java that referenced this pull request Oct 1, 2025
AgraVator added a commit to AgraVator/grpc-java that referenced this pull request Oct 6, 2025
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.

3 participants