-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[admin] config_dump scaffolding and routes endpoint (#2771)
This is a step towards dumping configs in proto form. There is a new config_dump endpoint, which spits out all registered configs. It's pretty-printed JSON for now; obviously we can play with format/serialization. Anyone can add a config via the ConfigTracker object that hangs off Admin. ConfigTracker makes the whole thing RAII-y, so that the list of config providers is maintained opaquely. This means the end user doesn't have to worry about ownership, capturing this, etc. Contrast with current unenforced pair of addHandler/removeHandler. This sort of managed weak ownership can be useful all over envoy; just in this diff I left a comment where something like ConfigTracker would delete a bunch of fragile code and confusion. I will genericize it in a future diff though, so let's focus on the functionality here and try to punt on extended discussion of this component and its possibilities. To demonstrate all the structured admin/config dumping scaffolding, I implemented it all for routes. See the data-plane-api PR (envoyproxy/data-plane-api#532) for context. But you can see how other config_dump handlers and, hopefully, all admin endpoints can be turned into structured, arbitrarily consumable proto via this setup. Risk Level: Medium. New feature on admin subsystem, intended to be minimally intrusive into rest of server Testing: New + existing unit. Tested locally with sudo ./bazel-bin/source/exe/envoy-static -c examples/front-proxy/front-envoy.yaml Output looks like: https://gist.github.com/jsedgwick/3a46408a9728ccef9a63d32b4c463c2b Docs Changes: I put TODO doxme everywhere I plan to add docs once the code/API is agreed upon. I won't merge this PR until docs are in. Release Notes: TODO pending consensus on this PR Issues: Makes progress on #2421, #2172 API Changes:] envoyproxy/data-plane-api#532 Deprecated: Current routes endpoint should be considered marked for deletion, but I'll do that in a subsequent PR. There should be some nice cleanup in addition to code deletion with this change. Signed-off-by: James Sedgwick <[email protected]>
- Loading branch information
Showing
24 changed files
with
473 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <map> | ||
#include <memory> | ||
|
||
#include "envoy/common/pure.h" | ||
|
||
#include "common/common/non_copyable.h" | ||
#include "common/protobuf/protobuf.h" | ||
|
||
namespace Envoy { | ||
namespace Server { | ||
|
||
/** | ||
* ConfigTracker is used by the `/config_dump` admin endpoint to manage storage of config-providing | ||
* callbacks with weak ownership semantics. Callbacks added to ConfigTracker only live as long as | ||
* the returned EntryOwner object (or ConfigTracker itself, if shorter). Keys should be descriptors | ||
* of the configs provided by the corresponding callback. They must be unique. | ||
* ConfigTracker is *not* threadsafe. | ||
*/ | ||
class ConfigTracker { | ||
public: | ||
typedef std::function<ProtobufTypes::MessagePtr()> Cb; | ||
typedef std::map<std::string, Cb> CbsMap; | ||
|
||
/** | ||
* EntryOwner supplies RAII semantics for entries in the map. | ||
* The entry is not removed until the EntryOwner or the ConfigTracker itself is destroyed, | ||
* whichever happens first. When you add() an entry, you must hold onto the returned | ||
* owner object for as long as you want the entry to stay in the map. | ||
*/ | ||
class EntryOwner { | ||
public: | ||
virtual ~EntryOwner() {} | ||
|
||
protected: | ||
EntryOwner(){}; // A sly way to make this class "abstract." | ||
}; | ||
typedef std::unique_ptr<EntryOwner> EntryOwnerPtr; | ||
|
||
virtual ~ConfigTracker(){}; | ||
|
||
/** | ||
* @return const CbsMap& The map of string keys to tracked callbacks. | ||
*/ | ||
virtual const CbsMap& getCallbacksMap() const PURE; | ||
|
||
/** | ||
* Add a new callback to the map under the given key | ||
* @param key the map key for the new callback. | ||
* @param cb the callback to add. *must not* return nullptr. | ||
* @return EntryOwnerPtr the new entry's owner object. nullptr if the key is already present. | ||
*/ | ||
virtual EntryOwnerPtr add(const std::string& key, Cb cb) PURE; | ||
}; | ||
|
||
} // namespace Server | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.