-
Notifications
You must be signed in to change notification settings - Fork 21
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
File Sink Client Typing #849
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
michaeldjeffrey
force-pushed
the
mj/file-sink-client-typing
branch
from
August 2, 2024 19:55
414ea05
to
104981b
Compare
Instead of dealing with bundles of Vec<u8> each file sink and client will be paired over any type that can be turned into bytes.
…ost traits To keep from dealing with Vec<u8> and String auto implementations for prost::Message that disallows using a file sync with anything but a prost::Message. We're going to follow the other Msg* trait conventions where we implement them only for the types we are using. This allows someone to make a file sync for whatever type they may have, and convenience for proto types we write reports about.
The abstraction comes in two parts. The first we can get a file sink from a type if it implements the FileSinkWrite trait. The second is a type being able to be written to a file sink if it can be turned into bytes. This separates the convenience from the actual functionality.
this allows us to attach the metric name to the file type implementation, and only have to pass in the calling crate for the prefix. FileSinks are really only created once, and there are not so many of them that owning a string introduces a crazy amount of overhead.
The FileSinkWrite trait is a convenience method for creating file sinks, but it should not be tied to being able to use a file sink. The only requirement for that is being able to turn your message into bytes.
This is a specialized helper function, every crate using it was only using these two options. We can provide the base functionality with a single option. Ideally the Builder would be updated to take some sort of enum for the commit type as it doesn't make a lot of sense to auto_commit on every write _and_ roll the file at a certain interval.
- include new verified mapper code - update deps - fix botched rebase conflicts
michaeldjeffrey
force-pushed
the
mj/file-sink-client-typing
branch
from
August 19, 2024 19:14
104981b
to
b5bbad4
Compare
Taking a static string allows FileSinkWriteExt to be implemented by users outside the oracles codebase, and starts the journey of moving away from the FileType enum.
jeffgrunewald
approved these changes
Aug 23, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
bbalser
approved these changes
Aug 23, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Typing a
FileSInkClient
FileSinkClient
is widely used in this codebase, it will currently write anything to a file that isVec<u8>
.Some parts of Oracles take more than a few handles to
FileSinkClient
, and the only way to know what is being written is by the variable name, and following it's usage to where an actual.write()
happens.Written filenames are determined by a provided
FileType
, but there is no guarantee that the message being written matches theFileType
or the variable name. An example where this could go wrong is during a refactor of a component that takes multipleFileSinkClient
s, and the argument order of a constructor is changed. Being hidden in a larger diff block, it would be a very difficult thing to find. Or adding a file sink to a component, and the argument provided is not in the same position as the argument added.With a
FileSinkClient<T>
, there's less to find. Even if the variable is named incorrectly the compiler would shout at you if the wrong message type was being written.FileSinkWriteExt
traitAn example of this trait
and usage
FileSinks and
prost::Message
impl<T: prost::Message> FileSinkWriteExt for T {}
seemed like a good idea until it was made abundantly clear thatprost::Message
has an impl for basically every type there is. Which makes things like having aFileSinkClient<String>
orFileSinkClient<Vec<u8>>
very difficult, as they would useprost::Message
and the values you get out of the file would be tainted with proto encoding.MsgBytes
The
FileSinkWriteExt
trait sits on top ofMsgBytes
, anything that implementsMsgBytes
can be used with aFileSink
. Implementations forString
,Vec<u8>
, andbytes::Bytes
are provided already in case someone wants to use aFileSink
without a proto message.Assumptions
From what I understand...
auto_commit
saves a file for every write.roll_time
attempts to save a file every so often if there is something to save.It doesn't seem to make sense to me to see if there's something to save and save after every write. The helper combines these two flags behind an
Option
.