forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
discovery: refactor configuration ingestion.
Previously, the gRPC muxes required that decoding an opaque resource to obtain its name, then dispatch to the relevant subscription, which would again decode the opaque resource. This is pretty horrible efficiency wise, in particular when upgrading from v2 -> v3. In this patch, we introduce a DecodedResource wrapper and OpaqueResourceDecoder. The config ingestion module, e.g. GrpcMuxImpl, uses the OpaqueResourceDecoder to produce a typed DecodedResource, performing the decode once. This DecodedResource is then dispatched to the watching subscription. This provides > 20% speedup on the v2 -> v3 tax for eds_speed_test, decreasing from an overhead of 3.2x to 2.5x. It's also likely to unlock further optimizations as we now have a wrapper resource and simplifies subscription implementations, as they no longer need to deal with delta vs. SotW resource decoding in different ways. Risk level: Medium (configuration ingestion path changes). Testing: New unit tests for DecodedResourceImpl/OpaqueResourceDecoderImpl, updated existing unit tests to work with new interfaces. Partial solution to envoyproxy#11362 Signed-off-by: Harvey Tuch <htuch@google.com>
- Loading branch information
Showing
74 changed files
with
1,433 additions
and
1,093 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
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,62 @@ | ||
#pragma once | ||
|
||
#include "envoy/config/subscription.h" | ||
|
||
#include "common/protobuf/utility.h" | ||
|
||
namespace Envoy { | ||
namespace Config { | ||
|
||
namespace { | ||
|
||
std::vector<std::string> | ||
repeatedPtrFieldToVector(const Protobuf::RepeatedPtrField<std::string>& xs) { | ||
std::vector<std::string> ys; | ||
std::copy(xs.begin(), xs.end(), std::back_inserter(ys)); | ||
return ys; | ||
} | ||
|
||
} // namespace | ||
|
||
class DecodedResourceImpl : public DecodedResource { | ||
public: | ||
DecodedResourceImpl(OpaqueResourceDecoder& resource_decoder, const ProtobufWkt::Any& resource, | ||
const std::string& version) | ||
: DecodedResourceImpl(resource_decoder, {}, Protobuf::RepeatedPtrField<std::string>(), | ||
resource, true, version) {} | ||
DecodedResourceImpl(OpaqueResourceDecoder& resource_decoder, | ||
const envoy::service::discovery::v3::Resource& resource) | ||
: DecodedResourceImpl(resource_decoder, resource.name(), resource.aliases(), | ||
resource.resource(), resource.has_resource(), resource.version()) {} | ||
DecodedResourceImpl(ProtobufTypes::MessagePtr resource, const std::string& name, | ||
const std::vector<std::string>& aliases, const std::string& version) | ||
: resource_(std::move(resource)), has_resource_(true), name_(name), aliases_(aliases), | ||
version_(version) {} | ||
|
||
// Config::DecodedResource | ||
const std::string& name() const override { return name_; } | ||
const std::vector<std::string>& aliases() const override { return aliases_; } | ||
const std::string& version() const override { return version_; }; | ||
const Protobuf::Message& resource() const override { return *resource_; }; | ||
bool hasResource() const override { return has_resource_; } | ||
|
||
private: | ||
DecodedResourceImpl(OpaqueResourceDecoder& resource_decoder, absl::optional<std::string> name, | ||
const Protobuf::RepeatedPtrField<std::string>& aliases, | ||
const ProtobufWkt::Any& resource, bool has_resource, | ||
const std::string& version) | ||
: resource_(resource_decoder.decodeResource(resource)), has_resource_(has_resource), | ||
name_(name ? *name : resource_decoder.resourceName(*resource_)), | ||
aliases_(repeatedPtrFieldToVector(aliases)), version_(version) {} | ||
|
||
const ProtobufTypes::MessagePtr resource_; | ||
const bool has_resource_; | ||
const std::string name_; | ||
const std::vector<std::string> aliases_; | ||
const std::string version_; | ||
}; | ||
|
||
using DecodedResourceImplPtr = std::unique_ptr<DecodedResourceImpl>; | ||
|
||
} // namespace Config | ||
} // 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.