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

[disk-buffering] - Single responsibility for disk exporters #1161

Merged
merged 25 commits into from
Jan 23, 2024

Conversation

breedx-splk
Copy link
Contributor

@breedx-splk breedx-splk commented Jan 17, 2024

So I think that it is a little confusing that there were classes like DiskExporter (and all their type-specific friends) that did double duty -- that is they both wrote to AND read from the on-disk buffer.

The directionality of DiskExporter always suggested (to me at least) that export was done to the disk. Even if wasn't your immediate instinct, at least you'll hopefully agree with me that decomposing into separate responsibility units has merit.

I offer up a decomposition which turns DiskExporter into ToDiskExporter and FromDiskExporter. I hope that it's much easier to follow which is which.

You might notice that there's asymmetry between the "to disk" type specific classes and the (lack of) type specific "from disk" classes. This is primarily due to the fact that the SDK classes (SdkTracerProvider, SdkMeterProvider, SdkLoggerProvider) need signal-specific implementation classes...which the impls here are. The "from disk" classes do not have this same problem because there is no sdk coupling, just api delegation.

@breedx-splk breedx-splk requested a review from a team January 17, 2024 08:08
@breedx-splk breedx-splk marked this pull request as draft January 17, 2024 08:09
@breedx-splk
Copy link
Contributor Author

Ah combining exporters into single package made them all internal. Lemme fix that.

@breedx-splk breedx-splk marked this pull request as ready for review January 17, 2024 23:48
Copy link
Contributor

@LikeTheSalad LikeTheSalad left a comment

Choose a reason for hiding this comment

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

This new concept is great, thank you!

Just a couple of comments but overall I think we should go with it.

disk-buffering/DESIGN.md Outdated Show resolved Hide resolved
private final StorageBuilder storageBuilder = Storage.builder();

@CanIgnoreReturnValue
public FromDiskExporterBuilder<T> setFolderName(String folderName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The folder name and the serializer must be the same as the ones used in each ToDiskExporter impl for it to work properly, so I'm a bit concerned about providing this builder publicly as it seems like it could be easy to misconfigure it. Instead, I would move it (and also FromDiskExporter.java) to the internal package and create public implementations for each signal in this package, similarly to what's done for the ToDiskExporters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I gave that a shot....and it ended up working out and now there's nice parity between the ToDisk and the FromDisk per signal types. Thanks for the idea!

Unfortunately, it ended up being a LOT of work to get the tests shored up. For starters, we were several versions behind on the protobufs...and I got us on the latest. The latest, tho, includes the TraceFlags as part of the protos, which we hadn't accounted for. There's also asymmetry in several places because the TraceFlags are not serialized into protobufs for the Exemplars (and maybe also for parent context, I forget).

I any case, I had to shim in a bunch of slightly different expected results, which contain the TraceFlags.getSampled() which is what we hard-code to on the de-serialization side. I think overall though it probably cleaned up the tests a little and definitely encouraged some reuse.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh man, I know how painful dealing with these serializations is, especially when it comes to metrics! 😩 thank you for taking the time to update it 🙏

/**
* The root storage location for buffered telemetry.
*/
public abstract File getRootDir();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is cool! After using this tool a couple of times, I just ended up passing the same root file everywhere which wasn't too nice, this is much cleaner.

Copy link
Contributor

Choose a reason for hiding this comment

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

Somehow I just noticed that this is in the internal package 🤦‍♂️ it shouldn't. I guess I'll address it after this PR is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah please this one is already super heavy. :) Thank you!

return this;
}
// @CanIgnoreReturnValue
// public ToDiskExporterBuilder<T> setRootDir(File rootDir) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this shouldn't be commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The root dir is now part of the storage configuration, so it doesn't belong on this builder any longer (see the build() method for when it's used).

I'll remove this commented/boneyard tho.

@breedx-splk
Copy link
Contributor Author

@open-telemetry/java-maintainers we have component-owners approvals. ❤️ 🙏🏻 Thanks.

@trask trask merged commit 3f7db8b into open-telemetry:main Jan 23, 2024
14 checks passed
psx95 pushed a commit to psx95/opentelemetry-java-contrib that referenced this pull request Jan 26, 2024
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.

4 participants