Skip to content

Interpret timeout zero value as no limit#7023

Merged
jack-berg merged 2 commits intoopen-telemetry:mainfrom
jack-berg:zero-timeout-is-unlimited
Jan 17, 2025
Merged

Interpret timeout zero value as no limit#7023
jack-berg merged 2 commits intoopen-telemetry:mainfrom
jack-berg:zero-timeout-is-unlimited

Conversation

@jack-berg
Copy link
Copy Markdown
Member

Implementation of spec PR: open-telemetry/opentelemetry-specification#4331

Supersedes #6850.

int callTimeoutMillis =
(int) Math.min(Duration.ofNanos(timeoutNanos).toMillis(), Integer.MAX_VALUE);
int connectTimeoutMillis =
(int) Math.min(Duration.ofNanos(connectTimeoutNanos).toMillis(), Integer.MAX_VALUE);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Internally, OkHttp converts durations in int type and time unit millis. Duration allows us to specify a value that overflows OkHttp's internal logic, so we need to add some bounds.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.84%. Comparing base (c8da020) to head (d386c51).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...dk/logs/export/BatchLogRecordProcessorBuilder.java 0.00% 0 Missing and 1 partial ⚠️
...ry/sdk/trace/export/BatchSpanProcessorBuilder.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7023      +/-   ##
============================================
- Coverage     89.95%   89.84%   -0.11%     
- Complexity     6636     6656      +20     
============================================
  Files           745      748       +3     
  Lines         20010    20087      +77     
  Branches       1962     1971       +9     
============================================
+ Hits          17999    18048      +49     
- Misses         1415     1444      +29     
+ Partials        596      595       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

Looks good. I had a small question about negative values and maybe see an issue with MAX_VALUE for Integer in okhttp...but otherwise seems like a good change.


public GrpcExporterBuilder<T> setTimeout(long timeout, TimeUnit unit) {
timeoutNanos = unit.toNanos(timeout);
timeoutNanos = timeout == 0 ? Long.MAX_VALUE : unit.toNanos(timeout);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to think about negative values while we're at it...or leave for a follow-up effort?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do we want to think about negative values while we're at it...or leave for a follow-up effort?

Negative values are rejected upstream of this, e.g.: https://github.com/open-telemetry/opentelemetry-java/blob/main/exporters/otlp/all/src/main/java/io/opentelemetry/exporter/otlp/http/trace/OtlpHttpSpanExporterBuilder.java#L81

We discussed whether to centralize this type of parameter validation in a central place or duplicate it many times in upper layers, and decided on duplicating in upper layers. The idea being, that its much more discoverable for users to discover the requirements of the parameter if the validation is directly in the builder, vs. having to step through an obscure chain of abstractions to reach GrpcExporterBuilder.

We could of course have the checks at multiple layers, but that comes with its own problems of duplication and more edge cases to test if you take a strict view of coverage.

.dispatcher(OkHttpUtil.newDispatcher())
.connectTimeout(Duration.ofNanos(connectionTimeoutNanos))
.callTimeout(Duration.ofNanos(timeoutNanos));
.connectTimeout(Duration.ofMillis(connectTimeoutMillis))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same issue as above with MAX_VALUE causing ISE.

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