-
Notifications
You must be signed in to change notification settings - Fork 5.3k
udpa: context parameter encoding. #12806
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eeef8fa
udpa: context parameter encoding.
htuch db81eae
Merge remote-tracking branch 'upstream/master' into udpa-context-params
htuch 276d9c3
Add 'renderers' to spelling dictionary.
htuch e4a2358
Merge remote-tracking branch 'upstream/master' into udpa-context-params
htuch 7811b03
Release build fixes.
htuch 546cfa3
Merge remote-tracking branch 'upstream/master' into udpa-context-params
htuch dfd353c
Explicit node field names.
htuch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 35 additions & 1 deletion
36
generated_api_shadow/envoy/config/bootstrap/v3/bootstrap.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 35 additions & 1 deletion
36
generated_api_shadow/envoy/config/bootstrap/v4alpha/bootstrap.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,91 @@ | ||
| #include "common/config/udpa_context_params.h" | ||
|
|
||
| #include "common/common/macros.h" | ||
| #include "common/protobuf/utility.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Config { | ||
|
|
||
| namespace { | ||
|
|
||
| using RenderContextParamCb = std::function<std::string(const envoy::config::core::v3::Node& node)>; | ||
| using NodeContextRenderers = absl::flat_hash_map<std::string, RenderContextParamCb>; | ||
|
|
||
| RenderContextParamCb directStringFieldRenderer(const std::string& field) { | ||
| return [field](const envoy::config::core::v3::Node& node) -> std::string { | ||
| return MessageUtil::getStringField(node, field); | ||
| }; | ||
| } | ||
|
|
||
| RenderContextParamCb localityStringFieldRenderer(const std::string& field) { | ||
| return [field](const envoy::config::core::v3::Node& node) -> std::string { | ||
| return MessageUtil::getStringField(node.locality(), field); | ||
| }; | ||
| } | ||
|
|
||
| std::string buildSemanticVersionRenderer(const envoy::config::core::v3::Node& node) { | ||
| const auto& semver = node.user_agent_build_version().version(); | ||
| return fmt::format("{}.{}.{}", semver.major_number(), semver.minor_number(), semver.patch()); | ||
| } | ||
|
|
||
| const NodeContextRenderers& nodeParamCbs() { | ||
| CONSTRUCT_ON_FIRST_USE(NodeContextRenderers, {"id", directStringFieldRenderer("id")}, | ||
htuch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {"cluster", directStringFieldRenderer("cluster")}, | ||
| {"user_agent_name", directStringFieldRenderer("user_agent_name")}, | ||
| {"user_agent_version", directStringFieldRenderer("user_agent_version")}, | ||
| {"locality.region", localityStringFieldRenderer("region")}, | ||
| {"locality.zone", localityStringFieldRenderer("zone")}, | ||
| {"locality.sub_zone", localityStringFieldRenderer("sub_zone")}, | ||
| {"user_agent_build_version.version", buildSemanticVersionRenderer}); | ||
| } | ||
|
|
||
| void mergeMetadataJson(Protobuf::Map<std::string, std::string>& params, | ||
| const ProtobufWkt::Struct& metadata, const std::string& prefix) { | ||
| for (const auto& it : metadata.fields()) { | ||
| params[prefix + it.first] = MessageUtil::getJsonStringFromMessage(it.second); | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| udpa::core::v1::ContextParams UdpaContextParams::encode( | ||
| const envoy::config::core::v3::Node& node, const std::vector<std::string>& node_context_params, | ||
| const udpa::core::v1::ContextParams& resource_context_params, | ||
| const std::vector<std::string>& client_features, | ||
| const absl::flat_hash_map<std::string, std::string>& extra_resource_params) { | ||
| udpa::core::v1::ContextParams context_params; | ||
| auto& mutable_params = *context_params.mutable_params(); | ||
| // 1. Establish base layer of per-node context parameters. | ||
| for (const std::string& ncp : node_context_params) { | ||
| // First attempt field accessors known ahead of time, if that fails we consider the cases of | ||
| // metadata, either directly in the Node message, or nested in the user_agent_build_version. | ||
| if (nodeParamCbs().count(ncp) > 0) { | ||
| mutable_params["udpa.node." + ncp] = nodeParamCbs().at(ncp)(node); | ||
| } else if (ncp == "metadata") { | ||
| mergeMetadataJson(mutable_params, node.metadata(), "udpa.node.metadata."); | ||
| } else if (ncp == "user_agent_build_version.metadata") { | ||
| mergeMetadataJson(mutable_params, node.user_agent_build_version().metadata(), | ||
| "udpa.node.user_agent_build_version.metadata."); | ||
| } | ||
| } | ||
|
|
||
| // 2. Overlay with context parameters from resource name. | ||
| for (const auto& it : resource_context_params.params()) { | ||
| mutable_params[it.first] = it.second; | ||
| } | ||
|
|
||
| // 3. Overlay with per-resource type context parameters. | ||
| for (const std::string& cf : client_features) { | ||
| mutable_params["udpa.client_feature." + cf] = "true"; | ||
| } | ||
|
|
||
| // 4. Overlay with per-resource well-known attributes. | ||
| for (const auto& it : extra_resource_params) { | ||
| mutable_params["udpa.resource." + it.first] = it.second; | ||
| } | ||
|
|
||
| return context_params; | ||
| } | ||
|
|
||
| } // namespace Config | ||
| } // namespace Envoy | ||
This file contains hidden or 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,33 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/config/core/v3/base.pb.h" | ||
|
|
||
| #include "absl/container/flat_hash_map.h" | ||
| #include "udpa/core/v1/context_params.pb.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Config { | ||
|
|
||
| // Utilities for working with context parameters. | ||
| class UdpaContextParams { | ||
| public: | ||
| /** | ||
| * Encode context parameters by following the xDS transport precedence algorithm and applying | ||
| * parameter prefixes. | ||
| * @param node reference to the local Node information. | ||
| * @param node_context_params a list of node fields to include in context parameters. | ||
| * @param resource_context_params context parameters from resource locator. | ||
| * @param client_features client feature capabilities. | ||
| * @param extra_resource_param per-resource type well known attributes. | ||
| * @return udpa::core::v1::ContextParams encoded context parameters. | ||
| */ | ||
| static udpa::core::v1::ContextParams | ||
| encode(const envoy::config::core::v3::Node& node, | ||
| const std::vector<std::string>& node_context_params, | ||
| const udpa::core::v1::ContextParams& resource_context_params, | ||
| const std::vector<std::string>& client_features, | ||
| const absl::flat_hash_map<std::string, std::string>& extra_resource_params); | ||
| }; | ||
|
|
||
| } // namespace Config | ||
| } // namespace Envoy |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/common/exception.h" | ||
|
|
||
| #include "absl/strings/string_view.h" | ||
|
|
||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.