Skip to content

Commit

Permalink
Merge branch 'main' into dns_details
Browse files Browse the repository at this point in the history
Signed-off-by: Fredy Wijaya <[email protected]>
  • Loading branch information
fredyw committed Oct 2, 2024
2 parents b3eef94 + 520442a commit 1b9371c
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 16 deletions.
23 changes: 23 additions & 0 deletions source/common/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,28 @@ Utility::buildJitteredExponentialBackOffStrategy(
default_base_interval_ms, default_base_interval_ms * 10, random);
}

absl::Status Utility::validateTerminalFilters(const std::string& name,
const std::string& filter_type,
const std::string& filter_chain_type,
bool is_terminal_filter,
bool last_filter_in_current_config) {
if (is_terminal_filter && !last_filter_in_current_config) {
return absl::InvalidArgumentError(
fmt::format("Error: terminal filter named {} of type {} must be the "
"last filter in a {} filter chain.",
name, filter_type, filter_chain_type));
} else if (!is_terminal_filter && last_filter_in_current_config) {
absl::string_view extra = "";
if (filter_chain_type == "router upstream http") {
extra = " When upstream_http_filters are specified, they must explicitly end with an "
"UpstreamCodec filter.";
}
return absl::InvalidArgumentError(fmt::format("Error: non-terminal filter named {} of type "
"{} is the last filter in a {} filter chain.{}",
name, filter_type, filter_chain_type, extra));
}
return absl::OkStatus();
}

} // namespace Config
} // namespace Envoy
14 changes: 1 addition & 13 deletions source/common/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,19 +424,7 @@ class Utility {
const std::string& filter_type,
const std::string& filter_chain_type,
bool is_terminal_filter,
bool last_filter_in_current_config) {
if (is_terminal_filter && !last_filter_in_current_config) {
return absl::InvalidArgumentError(
fmt::format("Error: terminal filter named {} of type {} must be the "
"last filter in a {} filter chain.",
name, filter_type, filter_chain_type));
} else if (!is_terminal_filter && last_filter_in_current_config) {
return absl::InvalidArgumentError(fmt::format(
"Error: non-terminal filter named {} of type {} is the last filter in a {} filter chain.",
name, filter_type, filter_chain_type));
}
return absl::OkStatus();
}
bool last_filter_in_current_config);

/**
* Prepares the DNS failure refresh backoff strategy given the cluster configuration.
Expand Down
3 changes: 1 addition & 2 deletions source/common/quic/envoy_quic_client_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class EnvoyQuicClientSession : public QuicFilterManagerConnectionImpl,

// PacketsToReadDelegate
size_t numPacketsExpectedPerEventLoop() const override {
// Do one round of reading per active stream, or to see if there's a new
// active stream.
// Do one round of reading per active stream, or to see if there's a new active stream.
return std::max<size_t>(1, GetNumActiveStreams()) * Network::NUM_DATAGRAMS_PER_RECEIVE;
}

Expand Down
1 change: 0 additions & 1 deletion source/common/router/config_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ class RetryPolicyImpl : public RetryPolicy {
// that should be used when with this policy.
std::vector<std::pair<Upstream::RetryHostPredicateFactory&, ProtobufTypes::MessagePtr>>
retry_host_predicate_configs_;
Upstream::RetryPrioritySharedPtr retry_priority_;
// Name and config proto to use to create the RetryPriority to use with this policy. Default
// initialized when no RetryPriority should be used.
std::pair<Upstream::RetryPriorityFactory*, ProtobufTypes::MessagePtr> retry_priority_config_;
Expand Down
1 change: 1 addition & 0 deletions test/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ envoy_cc_test(
"//test/mocks/upstream:thread_local_cluster_mocks",
"//test/test_common:environment_lib",
"//test/test_common:logging_lib",
"//test/test_common:status_utility_lib",
"//test/test_common:test_runtime_lib",
"//test/test_common:utility_lib",
"@com_github_cncf_xds//udpa/type/v1:pkg_cc_proto",
Expand Down
39 changes: 39 additions & 0 deletions test/common/config/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "test/mocks/upstream/thread_local_cluster.h"
#include "test/test_common/environment.h"
#include "test/test_common/logging.h"
#include "test/test_common/status_utility.h"
#include "test/test_common/test_runtime.h"
#include "test/test_common/utility.h"

Expand All @@ -29,6 +30,7 @@
#include "udpa/type/v1/typed_struct.pb.h"
#include "xds/type/v3/typed_struct.pb.h"

using Envoy::StatusHelpers::HasStatusMessage;
using testing::ContainsRegex;
using testing::Eq;
using testing::HasSubstr;
Expand Down Expand Up @@ -894,6 +896,43 @@ TEST(UtilityTest, GetGrpcControlPlane) {
}
}

TEST(UtilityTest, ValidateTerminalFiltersSucceeds) {
EXPECT_OK(Utility::validateTerminalFilters("filter_name", "filter_type", "chain_type",
/*is_terminal_filter=*/true,
/*last_filter_in_current_config=*/true));
EXPECT_OK(Utility::validateTerminalFilters("filter_name", "filter_type", "chain_type",
/*is_terminal_filter=*/false,
/*last_filter_in_current_config=*/false));
}

TEST(UtilityTest, ValidateTerminalFilterFailsWithMisplacedTerminalFilter) {
EXPECT_THAT(
Utility::validateTerminalFilters("filter_name", "filter_type", "chain_type",
/*is_terminal_filter=*/true,
/*last_filter_in_current_config=*/false),
HasStatusMessage("Error: terminal filter named filter_name of type filter_type must be the "
"last filter in a chain_type filter chain."));
}

TEST(UtilityTest, ValidateTerminalFilterFailsWithMissingTerminalFilter) {
EXPECT_THAT(Utility::validateTerminalFilters("filter_name", "filter_type", "chain_type",
/*is_terminal_filter=*/false,
/*last_filter_in_current_config=*/true),
HasStatusMessage("Error: non-terminal filter named filter_name of type "
"filter_type is the last filter in a chain_type filter chain."));
}

TEST(UtilityTest, ValidateTerminalFilterFailsWithMissingUpstreamTerminalFilter) {
EXPECT_THAT(
Utility::validateTerminalFilters("filter_name", "filter_type", "router upstream http",
/*is_terminal_filter=*/false,
/*last_filter_in_current_config=*/true),
HasStatusMessage("Error: non-terminal filter named filter_name of type "
"filter_type is the last filter in a router upstream http filter chain. "
"When upstream_http_filters are specified, they must explicitly end with an "
"UpstreamCodec filter."));
}

} // namespace
} // namespace Config
} // namespace Envoy
2 changes: 2 additions & 0 deletions test/common/quic/envoy_quic_client_stream_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ TEST_F(EnvoyQuicClientStreamTest, GetRequestAndHeaderOnlyResponse) {
const auto result = quic_stream_->encodeHeaders(request_headers_, /*end_stream=*/true);
EXPECT_TRUE(result.ok());

quic_stream_->setFlushTimeout(std::chrono::milliseconds(100)); // No-op

EXPECT_CALL(stream_decoder_, decodeHeaders_(_, /*end_stream=*/false))
.WillOnce(Invoke([](const Http::ResponseHeaderMapPtr& headers, bool) {
EXPECT_EQ("200", headers->getStatusValue());
Expand Down

0 comments on commit 1b9371c

Please sign in to comment.