-
Notifications
You must be signed in to change notification settings - Fork 5.5k
admin: Add an API on Server to initiate a programmatic admin request. #3667
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
Changes from 4 commits
034b5ff
1f45160
d9ac410
a22b7de
61d532f
355e071
a7e84e2
3b2f6b4
be5aa96
1228879
c7d9f6e
7b0ea3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #include <map> | ||
| #include <string> | ||
|
|
||
| namespace Envoy { | ||
| namespace Http { | ||
| namespace Utility { | ||
|
|
||
| // TODO(jmarantz): this should probably be a proper class, with methods to serialize | ||
| // using proper formatting. Perhaps similar to | ||
| // https://github.com/apache/incubator-pagespeed-mod/blob/master/pagespeed/kernel/http/query_params.h | ||
|
|
||
| typedef std::map<std::string, std::string> QueryParams; | ||
|
|
||
| } // namespace Utility | ||
| } // namespace Http | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
|
|
||
| #include "envoy/access_log/access_log.h" | ||
| #include "envoy/api/api.h" | ||
| #include "envoy/http/query_params.h" | ||
| #include "envoy/init/init.h" | ||
| #include "envoy/local_info/local_info.h" | ||
| #include "envoy/network/listen_socket.h" | ||
|
|
@@ -184,6 +185,23 @@ class Instance { | |
| * @return the flush interval of stats sinks. | ||
| */ | ||
| virtual std::chrono::milliseconds statsFlushInterval() const PURE; | ||
|
|
||
| /** | ||
| * Defines a callback that is run when an admin request completes.. | ||
| * The first parameter to the function is the response-headers, which | ||
| * will generally have Content-Type and Status fields. | ||
| */ | ||
| typedef std::function<void(Http::Code, Http::HeaderMap&, absl::string_view)> AdminResponseHandler; | ||
|
|
||
| /** | ||
| * Admin requests are generally handled by posting to the 'main' thread, so | ||
| * a callback must be supplied which will be called when the response is handled. | ||
| * | ||
| * @param path The admin request URL path as a string. | ||
| * @param params map of parameter names and values. | ||
| */ | ||
| virtual void adminRequest(absl::string_view path, const Http::Utility::QueryParams& params, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The server instance already exposes an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point, that shouldn simplify the PR. Thanks.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns out not to dramatically simplify the PR as I just pushed the mocking boilerplate out of server and into admin :) |
||
| absl::string_view method, AdminResponseHandler& response_handler) PURE; | ||
| }; | ||
|
|
||
| } // namespace Server | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,5 +183,22 @@ OwnedImpl::OwnedImpl(const Instance& data) : OwnedImpl() { add(data); } | |
|
|
||
| OwnedImpl::OwnedImpl(const void* data, uint64_t size) : OwnedImpl() { add(data, size); } | ||
|
|
||
| std::string OwnedImpl::toString() const { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this different to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked at linearize and though they seem similar, I don't see how either can be efficiently implemented on the other.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, you could linearize and then create a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. linearize mutates the buffer IIUC; I thought it made sense to have a simple observer that can return the fully flattened string. Moreover it exists in the codebase now, in a test helper, and I'm mostly just moving it. However per your other comment -- I don't really need this in the interface, as everywhere in tests and in admin.cc where it's needed, I have an OwnedImpl. Removed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think mutating is a benefit here, it's kind of like defragging. At least naively, it seems you should be able to implement it about as efficiently as the |
||
| uint64_t num_slices = getRawSlices(nullptr, 0); | ||
| RawSlice slices[num_slices]; | ||
| getRawSlices(slices, num_slices); | ||
| size_t len = 0; | ||
| for (RawSlice& slice : slices) { | ||
| len += slice.len_; | ||
| } | ||
| std::string output; | ||
| output.reserve(len); | ||
| for (RawSlice& slice : slices) { | ||
| output.append(static_cast<const char*>(slice.mem_), slice.len_); | ||
| } | ||
|
|
||
| return output; | ||
| } | ||
|
|
||
| } // namespace Buffer | ||
| } // namespace Envoy | ||
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.
Note: this method was previously implemented as a test utility; I made it slightly faster by right-sizing the string buffer first, and moving it into source/...