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

Adding streaming response to AdminClusters endpoint #33879

Open
wants to merge 70 commits into
base: main
Choose a base branch
from

Conversation

miroswan
Copy link
Contributor

@miroswan miroswan commented Apr 30, 2024

Commit Message: Adding streaming response to AdminClusters endpoint
Additional Description: Leveraging Envoy::Server::Request to implement a streaming response for AdminClusters
Risk Level: medium
Testing: unit / integration / manual
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A
[Optional Runtime guard:]
[Optional Fixes #Issue]: #33879
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

@adisuissa
Copy link
Contributor

Seems that this PR includes many file changes. As it doesn't have reviews yet, can you please rebase it?
/wait

@adisuissa adisuissa self-assigned this May 1, 2024
@adisuissa
Copy link
Contributor

Seems that this PR includes many file changes. As it doesn't have reviews yet, can you please rebase it?

Apologies, I misread the PR contents.
This is quite a big change. Can you please provide some background what is the motivation behind this, and consider breaking it to smaller PRs.

@miroswan
Copy link
Contributor Author

miroswan commented May 1, 2024

Seems that this PR includes many file changes. As it doesn't have reviews yet, can you please rebase it?

Apologies, I misread the PR contents. This is quite a big change. Can you please provide some background what is the motivation behind this, and consider breaking it to smaller PRs.

  1. I've updated the PR description to explain which issue this fixes. It was assigned to me by @jmarantz. The motivation for the change can be found in the issue, but the TL;DR is that a request that needs to construct a response with many clusters can add unnecessary memory pressure and by streaming the response, we can reduce it.
  2. I don't think I'll be rebasing given the guidance here: https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md#submitting-a-pr. If my reviewer (@tonya11en) requests a rebase I'd be happy to do that.
  3. I won't be breaking this up right away since I was asked to not do this until the code could be reviewed holistically.

@adisuissa adisuissa removed the waiting label May 1, 2024
@adisuissa
Copy link
Contributor

Thanks for the info.
The rebasing request was an error on my part because of the big PR and I thought it wasn't intentional.

Assigning @jmarantz who may have the most context.
/assign @jmarantz

@adisuissa adisuissa removed their assignment May 1, 2024
@miroswan
Copy link
Contributor Author

miroswan commented May 1, 2024

There are some aspects to this PR that I believe should be known to folks reviewing:

  1. There is an opportunity to reduce string formatting in the text processor by replacing calls to Buffer::Instance::add with Buffer::Instance::addFragments. We can decide to do this in this PR or reserve for a secondary PR.
  2. I noticed that the JSON encoder used prior to this PR has omit empty behavior. That is to say, values that are false, 0, or an empty object are omitted. I've taken some precaution to replicate this behavior within this PR.
  3. I am interested to know if there are any existing e2e tests or benchmarks against which I can verify the changes.
  4. The unit tests herein verify the changes with more than one cluster to ensure that more than one call to Envoy::Server::Request::nextChunk works as expected.

@jmarantz
Copy link
Contributor

jmarantz commented May 1, 2024

You can do addFragments in this PR or a follow-up; if it adds risk it's fine to do a follow-up

I think you should add a new benchmark, in the style of test/server/admin/stats_handler_speed_test.cc.

I think there are probably some unit & integration tests already. A good way to find them is to inject garbage into your output, run all the tests and see which ones fail :)

However, you can also look at test/integration/integratin_admin_test.cc and the tests in test/server/admin/...

@jmarantz
Copy link
Contributor

jmarantz commented May 1, 2024

Oh, and you can add the new benchmark in a separate PR so we can see the before/after.

@miroswan
Copy link
Contributor Author

miroswan commented May 1, 2024

@jmarantz I'll create a separate Issue/PR to create a benchmark for the AdminClusters handler. We can get get that merged first. I can rebase those changes into this branch and make sure that the performance is improved.

@miroswan
Copy link
Contributor Author

miroswan commented May 1, 2024

@jmarantz Please assign #33918 to me when you have a moment. Thanks!

@miroswan miroswan force-pushed the admin-clusters-streamed branch 3 times, most recently from f5e12db to c2c81e9 Compare May 3, 2024 01:07
Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

flushing comments for now.

source/server/admin/clusters_chunk_processor.cc Outdated Show resolved Hide resolved
source/server/admin/clusters_chunk_processor.cc Outdated Show resolved Hide resolved
source/server/admin/clusters_chunk_processor.cc Outdated Show resolved Hide resolved
source/server/admin/admin.cc Outdated Show resolved Hide resolved
source/server/admin/clusters_chunk_processor.cc Outdated Show resolved Hide resolved
@miroswan
Copy link
Contributor Author

miroswan commented May 8, 2024

flushing comments for now.

Addressed your comments. Thanks.

Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

looking great!

Flushing some more comments. Will continue to review in parallel.

source/server/admin/clusters_chunk_processor.h Outdated Show resolved Hide resolved
source/server/admin/clusters_chunk_processor.h Outdated Show resolved Hide resolved
void render(std::reference_wrapper<const Upstream::Cluster> cluster, Buffer::Instance& response);
void drainBufferIntoResponse(Buffer::Instance& response);
void finalize(Buffer::Instance& response);
void addAddress(Json::Streamer::Map* raw_host_ptr, const Upstream::HostSharedPtr& host,
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we passing by pointer here? In Envoy, non-const refs are preferred unless there's some special reason they should be pointers, in which case there should be comments.

Copy link
Contributor Author

@miroswan miroswan May 10, 2024

Choose a reason for hiding this comment

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

So, the constructors for json maps and arrays in Envoy::Json::Streamer create unique pointers by the name Envoy::Json::Streamer::MapPtr and Envoy::Json::Streamer::ArrayPtr. Within the code, sometimes I need to pass the map or array to a private helper function to do extra work without terminating the array or map (termination happens during deconstruction). By passing the raw pointer, I can loan the pointer to the map or array to the helper function to do work without it owning it and prematurely terminating the the array or map with closing tokens.

I am open to recommendations; this just seemed like the most straight forward way to achieve this. If you think this is sensible I am happy to add comments to each of these private member functions that take the raw pointer.

source/server/admin/clusters_handler.cc Outdated Show resolved Hide resolved
source/server/admin/clusters_params.cc Show resolved Hide resolved
source/server/admin/clusters_request.cc Outdated Show resolved Hide resolved
test/server/admin/clusters_params_test.cc Show resolved Hide resolved
test/server/admin/clusters_params_test.cc Show resolved Hide resolved
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
…tatement

Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
…ig when C++20 is supported

Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
…ery param parsing fails

Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
…n the request classes

Signed-off-by: Demitri Swan <demitriswan@google.com>
Signed-off-by: Demitri Swan <demitriswan@google.com>
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.

None yet

4 participants