Repository navigation
grid: Add a new class for tracking alternate protocols for a connection to an origin. - #16127
Conversation
…on to an origin. Create a new AlternateProtocols class which tracks the list of alternate protocols which can be used to make connections to origins. Signed-off-by: Ryan Hamilton <[email protected]>
|
/assign @DavidSchinazi |
Signed-off-by: Ryan Hamilton <[email protected]>
Signed-off-by: Ryan Hamilton <[email protected]>
|
/assign-from @envoyproxy/maintainers |
|
@envoyproxy/maintainers assignee is @ggreenway |
alyssawilk
left a comment
There was a problem hiding this comment.
I'm happy to do second pass now that I'm back :-)
Just a few nits and this is good to go!
| void AlternateProtocols::setAlternatives(const Origin& origin, | ||
| const std::vector<AlternateProtocol>& protocols, | ||
| const MonotonicTime& ttl) { | ||
| protocols_[origin] = {protocols, ttl}; |
There was a problem hiding this comment.
probably premature optimization but won't we basically then update the entire vector on every response header? Would it make more sense to just update the ttl if it's new?
There was a problem hiding this comment.
Heh. I think that with small-string optimizations the perf impact should be minimal, but it's pretty trivial to check if they're equal first. Done.
| TimeSource& time_source_; | ||
|
|
||
| // Map from hostname to list of alternate protocols. | ||
| // TODO(RyanTheOptimist): Add a limit to the size of this map and evict based on usage. |
There was a problem hiding this comment.
"Hey have you done any bounds limits on -- Excellent, there's the TODO I was looking for"
There was a problem hiding this comment.
\o/ :)
In Chrome (and I think internal, too) we have an MRUCache class which is basically a map which a max size that automatically evicts the oldest entry when it's full. I don't think we have anything like this in Envoy (based on asking around in slack). Would it make sense to consider adding such a class?
There was a problem hiding this comment.
Hmmmm, I'm trying offhand to think of where else we'd need to use this. I can't think of one offhand but I have trouble imagining this is the first one we've run into. Matt would probably know offhand but I think not worth bugging him on leave.
| // specified origin, or nullptr if not alternatives are found. The returned pointer | ||
| // is owned by the AlternateProtocols and is valid until the next operation on | ||
| // AlternateProtocols. | ||
| const std::vector<AlternateProtocol>* findAlternatives(const Origin& origin); |
There was a problem hiding this comment.
Arguably it's a little more Envoy-ish to return an absl::optional<std::reference_wrapper<<>> but honestly I find pointers way easier to read so I'm going to look the other way here as long as you make the return value const :-P
There was a problem hiding this comment.
some of the messiness of opt ref is encapsulated in Envoy::OptRef : https://github.com/envoyproxy/envoy/blob/main/include/envoy/common/optref.h
In case that helps.
There was a problem hiding this comment.
Ooh, interesting! I've switched to OptRef, thanks!
Does Optref provide some additional type safety beyond a naked pointer?
There was a problem hiding this comment.
Not particularly; it just perhaps conveys intent a little better rather than a null check, and, with the convenience methods on that class, is IMO more on par from a readability perspective.
Signed-off-by: Ryan Hamilton <[email protected]>
Signed-off-by: Ryan Hamilton <[email protected]>
| TimeSource& time_source_; | ||
|
|
||
| // Map from hostname to list of alternate protocols. | ||
| // TODO(RyanTheOptimist): Add a limit to the size of this map and evict based on usage. |
There was a problem hiding this comment.
Hmmmm, I'm trying offhand to think of where else we'd need to use this. I can't think of one offhand but I have trouble imagining this is the first one we've run into. Matt would probably know offhand but I think not worth bugging him on leave.
…ion to an origin. (envoyproxy#16127) grid: Add a new class for tracking alternate protocols for a connection to an origin. Create a new AlternateProtocols class which tracks the list of alternate protocols which can be used to make connections to origins. Risk Level: Low Testing: New Unit tests Docs Changes: N/A Release Notes: N/A Platform Specific Features: N/A Signed-off-by: Ryan Hamilton <[email protected]> Signed-off-by: Gokul Nair <[email protected]>
grid: Add a new class for tracking alternate protocols for a connection to an origin.
Create a new AlternateProtocols class which tracks the list of alternate
protocols which can be used to make connections to origins.
Risk Level: Low
Testing: New Unit tests
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A