Skip to content

Commit

Permalink
proto: moving a utility to the one call location
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk committed Nov 13, 2024
1 parent ffba866 commit f9917ac
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 26 deletions.
8 changes: 0 additions & 8 deletions source/common/protobuf/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,6 @@ void MessageUtil::redact(Protobuf::Message& message) {
::Envoy::redact(&message, /* ancestor_is_sensitive = */ false);
}

void MessageUtil::wireCast(const Protobuf::Message& src, Protobuf::Message& dst) {
// This should should generally succeed, but if there are malformed UTF-8 strings in a message,
// this can fail.
if (!dst.ParseFromString(src.SerializeAsString())) {
throwEnvoyExceptionOrPanic("Unable to deserialize during wireCast()");
}
}

std::string MessageUtil::toTextProto(const Protobuf::Message& message) {
#if defined(ENVOY_ENABLE_FULL_PROTOS)
std::string text_format;
Expand Down
11 changes: 0 additions & 11 deletions source/common/protobuf/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,6 @@ class MessageUtil {
*/
static void redact(Protobuf::Message& message);

/**
* Reinterpret a Protobuf message as another Protobuf message by converting to wire format and
* back. This only works for messages that can be effectively duck typed this way, e.g. with a
* subtype relationship modulo field name.
*
* @param src source message.
* @param dst destination message.
* @throw EnvoyException if a conversion error occurs.
*/
static void wireCast(const Protobuf::Message& src, Protobuf::Message& dst);

/**
* Sanitizes a string to contain only valid UTF-8. Invalid UTF-8 characters will be replaced. If
* the input string is valid UTF-8, it will be returned unmodified.
Expand Down
5 changes: 1 addition & 4 deletions source/extensions/common/tap/admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ class AdminHandler : public Singleton::Instance,

// Returns true if the trace buffer is full (reached max_buf_size_) false otherwise
bool full() const {
if (!buffer_) {
return false;
}
return (buffer_->size() == max_buf_size_);
return (buffer_ && buffer_->size() == max_buf_size_);
}

// Return true if the buffer has already been flushed, false otherwise.
Expand Down
3 changes: 1 addition & 2 deletions source/extensions/common/tap/extension_config_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ ExtensionConfigBase::ExtensionConfigBase(
: proto_config_(proto_config), config_factory_(std::move(config_factory)), tls_slot_(tls) {
tls_slot_.set([](Event::Dispatcher&) { return std::make_shared<TlsFilterConfig>(); });

switch (proto_config_.config_type_case()) {
switch (proto_config_.config_type_case())
case envoy::extensions::common::tap::v3::CommonExtensionConfig::ConfigTypeCase::kAdminConfig: {
admin_handler_ = AdminHandler::getSingleton(admin, singleton_manager, main_thread_dispatcher);
admin_handler_->registerConfig(*this, proto_config_.admin_config().config_id());
ENVOY_LOG(debug, "initializing tap extension with admin endpoint (config_id={})",
proto_config_.admin_config().config_id());
break;
}
case envoy::extensions::common::tap::v3::CommonExtensionConfig::ConfigTypeCase::kStaticConfig: {
// Right now only one sink is supported.
ASSERT(proto_config_.static_config().output_config().sinks().size() == 1);
Expand Down
6 changes: 5 additions & 1 deletion source/extensions/common/tap/tap_config_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ TapConfigBaseImpl::TapConfigBaseImpl(const envoy::config::tap::v3::TapConfig& pr
// Fallback to use the deprecated match_config field and upgrade (wire cast) it to the new
// MatchPredicate which is backward compatible with the old MatchPredicate originally
// introduced in the Tap filter.
MessageUtil::wireCast(proto_config.match_config(), match);
if (!match.ParseFromString(proto_config.match_config().SerializeAsString())) {
// This should should generally succeed, but if there are malformed UTF-8 strings in a
// message, this can fail.
throw EnvoyException("Unable to deserialize during wireCast()");
}
} else {
throw EnvoyException(fmt::format("Neither match nor match_config is set in TapConfig: {}",
proto_config.DebugString()));
Expand Down
1 change: 1 addition & 0 deletions tools/code_format/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ paths:
- test/common/grpc/codec_fuzz_test.cc
- test/common/grpc/codec_test.cc
- test/common/protobuf/utility_test.cc
- source/extensions/common/tap/tap_config_base.cc
- test/extensions/bootstrap/wasm/test_data/speed_cpp.cc
- test/extensions/filters/common/expr/context_test.cc
- test/extensions/filters/http/common/fuzz/uber_filter.h
Expand Down

0 comments on commit f9917ac

Please sign in to comment.