-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(grpc): Add attributes API #2497
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
base: master
Are you sure you want to change the base?
Conversation
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.
Why doesn't something like the im crate satisfy our needs ? AVL trees seem relatively low level for us to bother implementing if an implementation already exists.
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.
The decision to implement an AVL tree was made to avoid pulling in a new dependency. Since gRPC is used across many projects, any library we add increases the binary size for all downstream users. While the im crate might be more performant due to its use of B-trees, this struct is only used for control plane operations. In my opinion, the performance gain doesn't justify the additional dependency.
I’m open to changing this if we decide that taking on the dependency is acceptable.
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.
It is acceptable to me 1.6k . Although, I'd probably prefer rpds : https://crates.io/crates/rpds , since it's more actively maintained with simiar-ish star count.
I'll defer the decision to @dfawley , if depending on a create for data structures is fine.
| /// Stored types must implement `Any + Send + Sync + Eq + Ord + Debug`. | ||
| #[derive(Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
| pub struct Attributes { | ||
| map: Avl<TypeId, AttributeValue>, |
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.
Okay for now.
But maybe we don't want tie ourselves to an implementation.
Can we abstract operations to a trait instead of concrete AVL to decouple things?
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.
I don't believe any public methods on the Attributes type expose its internal data structure. Could you clarify the benefit of introducing a trait here?
Introducing an interface for a single implementation feels like unnecessary indirection.
grpc/src/attributes/mod.rs
Outdated
| mod avl; | ||
|
|
||
| trait AttributeTrait: Any + Send + Sync + Debug { | ||
| fn as_any(&self) -> &dyn Any; |
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.
any_ref maybe?
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.
Renamed.
|
|
||
| mod avl; | ||
|
|
||
| trait AttributeTrait: Any + Send + Sync + Debug { |
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.
comments for the trait and the methods? It's particularly difficult to understand the need and requirements for ordering ?
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.
NVM. The implementation makes it clear but still worth documenting
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.
Added a rustdoc mentioning that it's required to support value based equality checks instead of pointer comparisions.
|
Added initial set of comments. I'll need some time to learn and review the AVL tree. (or maybe I'll just ask gemini to compare the c++ and rust impl ). |
Attributes Implementation
This change introduces an implementation of the
Attributestype—an immutable map designed for storing arbitrary data.To ensure efficient immutability, the map is backed by a persistent AVL tree, with an implementation based on gRPC C++'s
avl.h. Much like http::Extensions in the Rust ecosystem, these attributes are keyed by the value'sTypeId.Attributeswill facilitate data transfer between various control plane components, including resolvers, LB policies, credentials, and the channel.