Skip to content

grid: Add a new class for tracking alternate protocols for a connection to an origin. - #16127

Merged
alyssawilk merged 5 commits into
envoyproxy:mainfrom
RyanTheOptimist:alternate_protocols
Apr 27, 2021
Merged

alyssawilk merged 5 commits into
envoyproxy:mainfrom
RyanTheOptimist:alternate_protocols

Conversation

@RyanTheOptimist

Copy link
Copy Markdown
Contributor

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

…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]>
@RyanTheOptimist

Copy link
Copy Markdown
Contributor Author

/assign @DavidSchinazi

@DavidSchinazi DavidSchinazi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

Signed-off-by: Ryan Hamilton <[email protected]>
DavidSchinazi
DavidSchinazi previously approved these changes Apr 23, 2021
@RyanTheOptimist

Copy link
Copy Markdown
Contributor Author

/assign-from @envoyproxy/maintainers

@repokitteh-read-only

Copy link
Copy Markdown

@envoyproxy/maintainers assignee is @ggreenway

🐱

Caused by: a #16127 (comment) was created by @RyanTheOptimist.

see: more, trace.

@alyssawilk alyssawilk assigned alyssawilk and unassigned ggreenway Apr 26, 2021

@alyssawilk alyssawilk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"Hey have you done any bounds limits on -- Excellent, there's the TODO I was looking for"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

\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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ooh, interesting! I've switched to OptRef, thanks!

Does Optref provide some additional type safety beyond a naked pointer?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@alyssawilk
alyssawilk merged commit ca4ca98 into envoyproxy:main Apr 27, 2021
gokulnair pushed a commit to gokulnair/envoy that referenced this pull request May 6, 2021
…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]>
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.

5 participants