Skip to content
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

Enable reusuable_data memory mode by default #6799

Merged
merged 4 commits into from
Oct 23, 2024

Conversation

jack-berg
Copy link
Member

This PR follows through on the plan to make reuseable data the default memory mode, as discussed in #6469.

I'm personally aware of it being used in several production systems for a while now without issue. If anyone is aware of any risks associated with this, please speak up! If not, this change in defaults will quietly improve the performance of all the opentelemetry-java users who missed the memory mode optimizations we've been making.

@jack-berg jack-berg requested a review from a team as a code owner October 16, 2024 20:46
.setVersion("1.0")
.setSchemaUrl("http://url")
.build())
.setInstrumentationScopeInfo(SCOPE_INFO)
Copy link
Member Author

Choose a reason for hiding this comment

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

This change seems random, but is actually oddly needed for a subtle reason. The OTLP exporter tests generate fake test data, serialize and send it to a mock server, where it is deserialized into generated proto classes and evaluated for equality. As you're probably aware, OTLP payloads consist of a series of enclosing envelopes, e.g. for logs ResourceLogs enclose ScopeLogs enclose LogRecords. When an OTLP exporter recieves a List<LogRecordData>, the records need to be grouped by resource and scope to match the OTLP payload structure. We do this using identity hash maps. Notably, the reuseable memory mode serialization iterates over identity the identity hash maps slightly differently than the immutable memory mode variant. This means that when a group of records is exported with scopes which are equal but not identical, the order of those ScopeLogs in the serialized payload is not the same for immutable memory mode and reuseable memory mode.

We can make the tests pass by having the fake log records use identical scopes, which sidesteps the difference in iteration order between immutable memory mode and reuseable memory mode.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the clarification....this is a clever workaround.

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

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

Project coverage is 90.48%. Comparing base (628db61) to head (a94bf75).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...porter/prometheus/PrometheusHttpServerBuilder.java 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6799      +/-   ##
============================================
+ Coverage     90.37%   90.48%   +0.10%     
- Complexity     6577     6590      +13     
============================================
  Files           731      731              
  Lines         19714    19721       +7     
  Branches       1926     1928       +2     
============================================
+ Hits          17817    17845      +28     
+ Misses         1300     1285      -15     
+ Partials        597      591       -6     

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

@@ -82,7 +83,13 @@ public static PrometheusHttpServerBuilder builder() {
// sequentially.
if (memoryMode == MemoryMode.REUSABLE_DATA) {
executor =
Executors.newSingleThreadExecutor(new DaemonThreadFactory("prometheus-http-server"));
Copy link
Member Author

Choose a reason for hiding this comment

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

newSingleThreadExecutor returns a delegating wrapped ThreadPoolExecutor. One of our tests introspects on the resolved executor and ensures that when memory mode is reuseable, a single thread executor is used. The test is not able to make the required assertions based on the delegating wrapped version returned by Executors.newSingleThreadExecutor.

Copy link
Contributor

Choose a reason for hiding this comment

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

The way you described it makes it sound like a shortcoming in the test/assertions...which is a bummer that the implementation had to change to accommodate it. It seems fine, but I can't fully reason about the impact of having a non-finalizable executorservice. I'm overthinking it.

Comment on lines 156 to 157
"MemoryMode is REUSEABLE_DATA cannot be used with custom executor, "
+ "since data may be corrupted if reading metrics concurrently");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this documented anywhere else?

Copy link
Member

Choose a reason for hiding this comment

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

we'll need to update the docs and change otel.java.experimental.exporter.memory_mode to otel.java.exporter.memory_mode, so we could potentially add in another footnote when we do that.

Copy link
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.

Looking good to me. This is exciting!

Comment on lines 156 to 157
"MemoryMode is REUSEABLE_DATA cannot be used with custom executor, "
+ "since data may be corrupted if reading metrics concurrently");
Copy link
Member

Choose a reason for hiding this comment

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

we'll need to update the docs and change otel.java.experimental.exporter.memory_mode to otel.java.exporter.memory_mode, so we could potentially add in another footnote when we do that.

@jack-berg jack-berg merged commit 10bca8b into open-telemetry:main Oct 23, 2024
18 checks passed
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