Skip to content

Commit

Permalink
Update envoy to v1.30.1. (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuoyang2016 authored May 10, 2024
1 parent 09b23cf commit d830bca
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Required by envoy and its tests
build --define=grpc_no_ares=true
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build --cxxopt=-std=c++20 --host_cxxopt=-std=c++20

# We already have absl in the build, define absl=1 to tell googletest to use absl for backtrace.
build --define absl=1
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# 3) Check if envoy_build_config/extensions_build_config.bzl is up-to-date.
# Try to match it with the one in source/extensions and comment out unneeded extensions.

ENVOY_SHA1 = "6b9db09c69965d5bfb37bdd29693f8b7f9e9e9ec" # v1.27.1, 2023.10.11
ENVOY_SHA1 = "816188b86a0a52095b116b107f576324082c7c02" # v1.30.1

ENVOY_SHA256 = "d6cde20343d67fa4e25b9047bd805c522ece80b8058f1f311cb90ee7f3287f63"
ENVOY_SHA256 = "41064ee8fbafc2ac3fd0d6531a106139adbbea3585defff22fdb99e06d7862e5"

http_archive(
name = "envoy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ TEST_F(CheckResponseConverterTest, ConvertConsumerInfo) {
EXPECT_EQ(info.consumer_number, std::to_string(consumer_number));
}

TEST_F(CheckResponseConverterTest,
ApiKeyUidCarriedInCheckResponseInfo) {
TEST_F(CheckResponseConverterTest, ApiKeyUidCarriedInCheckResponseInfo) {
CheckResponseInfo info;
CheckResponse response;
response.mutable_check_info()->set_api_key_uid("fake_api_key_uid");
Expand Down
7 changes: 4 additions & 3 deletions src/api_proxy/service_control/request_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ constexpr char kServiceControlBackendProtocol[] =
constexpr char kServiceControlConsumerProject[] =
"serviceruntime.googleapis.com/consumer_project";
constexpr char kApiKeyPrefix[] = "apikey:";


// User agent label value
// The value for kUserAgent should be configured at service control server.
Expand Down Expand Up @@ -384,8 +383,10 @@ Status set_credential_id(const SupportedLabel& l, const ReportRequestInfo& info,
api_key::ApiKeyState::VERIFIED) {
ASSERT(!info.api_key.empty(),
"API Key must be set, otherwise consumer would not be verified.");
(*labels)[l.name] = absl::StrCat(kApiKeyPrefix, info.check_response_info.api_key_uid.empty() ? info.api_key
: info.check_response_info.api_key_uid);
(*labels)[l.name] =
absl::StrCat(kApiKeyPrefix, info.check_response_info.api_key_uid.empty()
? info.api_key
: info.check_response_info.api_key_uid);
} else if (!info.auth_issuer.empty()) {
std::string base64_issuer = Envoy::Base64Url::encode(
info.auth_issuer.data(), info.auth_issuer.size());
Expand Down
2 changes: 1 addition & 1 deletion src/envoy/http/backend_auth/config_parser_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ AudienceContext::AudienceContext(
const FilterConfig& filter_config,
const token::TokenSubscriberFactory& token_subscriber_factory,
GetTokenFunc access_token_fn)
: tls_(context.threadLocal()) {
: tls_(context.serverFactoryContext().threadLocal()) {
tls_.set(
[](Envoy::Event::Dispatcher&) { return std::make_shared<TokenCache>(); });

Expand Down
2 changes: 1 addition & 1 deletion src/envoy/http/grpc_metadata_scrubber/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ envoy_cc_library(
repository = "@envoy",
deps = [
":filter_lib",
"@envoy//source/exe:envoy_common_lib",
"@envoy//source/exe:all_extensions_lib",
],
)

Expand Down
2 changes: 1 addition & 1 deletion src/envoy/http/header_sanitizer/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ envoy_cc_library(
deps = [
":filter_lib",
"//api/envoy/v12/http/header_sanitizer:config_proto_cc_proto",
"@envoy//source/exe:envoy_common_lib",
"@envoy//source/exe:all_extensions_lib",
],
)
8 changes: 4 additions & 4 deletions src/envoy/http/service_control/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ envoy_cc_library(
],
repository = "@envoy",
deps = [
"@envoy//source/exe:envoy_common_lib",
"@envoy//source/exe:all_extensions_lib",
],
)

Expand All @@ -188,7 +188,7 @@ envoy_cc_library(
"//src/envoy/utils:rc_detail_utils_lib",
"@envoy//source/common/grpc:status_lib",
"@envoy//source/common/http:headers_lib",
"@envoy//source/exe:envoy_common_lib",
"@envoy//source/exe:all_extensions_lib",
"@envoy//source/extensions/filters/http/common:pass_through_filter_lib",
],
)
Expand All @@ -203,7 +203,7 @@ envoy_cc_library(
":filter_stats_lib",
":handler_impl_lib",
":service_control_call_impl_lib",
"@envoy//source/exe:envoy_common_lib",
"@envoy//source/exe:all_extensions_lib",
],
)

Expand All @@ -215,7 +215,7 @@ envoy_cc_library(
deps = [
":filter_config_lib",
":filter_lib",
"@envoy//source/exe:envoy_common_lib",
"@envoy//source/exe:all_extensions_lib",
],
)

Expand Down
14 changes: 8 additions & 6 deletions src/envoy/http/service_control/config_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ FilterConfigParser::FilterConfigParser(const FilterConfig& config,
service_map_.emplace(service.service_name(), ServiceContextPtr(srv_ctx));
}
if (first_srv_ctx == nullptr) {
throw Envoy::ProtoValidationException("Empty services", config_);
Envoy::ProtoExceptionUtil::throwProtoValidationException("Empty services",
config_);
}

if (service_map_.size() < static_cast<size_t>(config_.services_size())) {
throw Envoy::ProtoValidationException("Duplicated service names", config_);
Envoy::ProtoExceptionUtil::throwProtoValidationException(
"Duplicated service names", config_);
}

for (const auto& requirement : config_.requirements()) {
const auto service_it = service_map_.find(requirement.service_name());
if (service_it == service_map_.end()) {
throw Envoy::ProtoValidationException("Invalid service name",
requirement);
Envoy::ProtoExceptionUtil::throwProtoValidationException(
"Invalid service name", requirement);
}
requirements_map_.emplace(requirement.operation_name(),
RequirementContextPtr(new RequirementContext(
Expand All @@ -60,8 +62,8 @@ FilterConfigParser::FilterConfigParser(const FilterConfig& config,

if (requirements_map_.size() <
static_cast<size_t>(config_.requirements_size())) {
throw Envoy::ProtoValidationException("Duplicated operation names",
config_);
Envoy::ProtoExceptionUtil::throwProtoValidationException(
"Duplicated operation names", config_);
}

// Construct a requirement for non matched requests
Expand Down
2 changes: 1 addition & 1 deletion src/envoy/http/service_control/config_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ServiceContext {
min_stream_report_interval_ms_ = kDefaultMinStreamReportIntervalMs;
}
if (min_stream_report_interval_ms_ < kLowerBoundMinStreamReportIntervalMs) {
throw Envoy::ProtoValidationException(
Envoy::ProtoExceptionUtil::throwProtoValidationException(
absl::StrCat("min_stream_report_interval_ms must be larger than: ",
kLowerBoundMinStreamReportIntervalMs),
config);
Expand Down
17 changes: 7 additions & 10 deletions src/envoy/http/service_control/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void ServiceControlFilter::rejectRequest(Envoy::Http::Code code,
decoder_callbacks_->sendLocalReply(code, error_msg, nullptr, absl::nullopt,
rc_detail);
decoder_callbacks_->streamInfo().setResponseFlag(
Envoy::StreamInfo::ResponseFlag::UnauthorizedExternalService);
Envoy::StreamInfo::UnauthorizedExternalService);
}

Envoy::Http::FilterDataStatus ServiceControlFilter::decodeData(
Expand All @@ -132,20 +132,17 @@ Envoy::Http::FilterTrailersStatus ServiceControlFilter::decodeTrailers(
}

void ServiceControlFilter::log(
const Envoy::Http::RequestHeaderMap* request_headers,
const Envoy::Http::ResponseHeaderMap* response_headers,
const Envoy::Http::ResponseTrailerMap* response_trailers,
const Envoy::StreamInfo::StreamInfo&, Envoy::AccessLog::AccessLogType) {
const Envoy::Formatter::HttpFormatterContext& context,
const Envoy::StreamInfo::StreamInfo&) {
ENVOY_LOG(debug, "Called ServiceControl Filter : {}", __func__);
if (!handler_) {
if (!request_headers) return;
handler_ =
factory_.createHandler(*request_headers, decoder_callbacks_, stats_);
handler_ = factory_.createHandler(context.requestHeaders(),
decoder_callbacks_, stats_);
}

Envoy::Tracing::Span& parent_span = decoder_callbacks_->activeSpan();
handler_->callReport(request_headers, response_headers, response_trailers,
parent_span);
handler_->callReport(&context.requestHeaders(), &context.responseHeaders(),
&context.responseTrailers(), parent_span);
}

} // namespace service_control
Expand Down
7 changes: 2 additions & 5 deletions src/envoy/http/service_control/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ class ServiceControlFilter
Envoy::Http::RequestTrailerMap&) override;

// Called when the request is completed.
void log(const Envoy::Http::RequestHeaderMap* request_headers,
const Envoy::Http::ResponseHeaderMap* response_headers,
const Envoy::Http::ResponseTrailerMap* response_trailers,
const Envoy::StreamInfo::StreamInfo& stream_info,
Envoy::AccessLog::AccessLogType access_log_type) override;
void log(const Envoy::Formatter::HttpFormatterContext& context,
const Envoy::StreamInfo::StreamInfo& stream_info) override;

// For Handler::CheckDoneCallback, called when callCheck() is done
void onCheckDone(const absl::Status& status,
Expand Down
5 changes: 3 additions & 2 deletions src/envoy/http/service_control/filter_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class ServiceControlFilterConfig
proto_config)),
call_factory_(proto_config_, stats_prefix, context),
config_parser_(*proto_config_, call_factory_),
handler_factory_(context.api().randomGenerator(), config_parser_,
context.timeSource()) {}
handler_factory_(context.serverFactoryContext().api().randomGenerator(),
config_parser_,
context.serverFactoryContext().timeSource()) {}

const ServiceControlHandlerFactory& handler_factory() const {
return handler_factory_;
Expand Down
8 changes: 5 additions & 3 deletions src/envoy/http/service_control/filter_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ DEFINE_PROTO_FUZZER(
NiceMock<MockFactoryContext> context;
NiceMock<Envoy::Upstream::MockThreadLocalCluster> thread_local_cluster;
NiceMock<Envoy::Http::MockAsyncClientRequest> request(
&context.cluster_manager_.thread_local_cluster_.async_client_);
&context.server_factory_context_.cluster_manager_.thread_local_cluster_
.async_client_);
NiceMock<Envoy::Http::MockStreamDecoderFilterCallbacks>
mock_decoder_callbacks;

Expand All @@ -82,7 +83,7 @@ DEFINE_PROTO_FUZZER(

// Callback for token subscriber to start.
Envoy::Event::TimerCb onReadyCallback;
EXPECT_CALL(context.dispatcher_, createTimer_(_))
EXPECT_CALL(context.server_factory_context_.dispatcher_, createTimer_(_))
.WillRepeatedly(
Invoke([&onReadyCallback](const Envoy::Event::TimerCb& cb) {
ENVOY_LOG_MISC(trace, "Mocking dispatcher createTimer");
Expand All @@ -92,7 +93,8 @@ DEFINE_PROTO_FUZZER(

// Mock the http async client.
int resp_num = 0;
EXPECT_CALL(context.cluster_manager_, getThreadLocalCluster(_))
EXPECT_CALL(context.server_factory_context_.cluster_manager_,
getThreadLocalCluster(_))
.WillRepeatedly(Return(&thread_local_cluster));
EXPECT_CALL(thread_local_cluster.async_client_, send_(_, _, _))
.WillRepeatedly(Invoke([&request, &input, &resp_num](
Expand Down
37 changes: 11 additions & 26 deletions src/envoy/http/service_control/filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ TEST_F(ServiceControlFilterTest, DecodeHeadersMissingHeaders) {

// Filter should reject this request
EXPECT_CALL(mock_decoder_callbacks_.stream_info_,
setResponseFlag(
Envoy::StreamInfo::ResponseFlag::UnauthorizedExternalService))
setResponseFlag(Envoy::StreamInfo::UnauthorizedExternalService))
.Times(2);

EXPECT_CALL(mock_decoder_callbacks_,
Expand Down Expand Up @@ -146,10 +145,8 @@ TEST_F(ServiceControlFilterTest, DecodeHeadersSyncBadStatus) {
"service_control_check_error{API_KEY_INVALID}");
}));

EXPECT_CALL(
mock_decoder_callbacks_.stream_info_,
setResponseFlag(
Envoy::StreamInfo::ResponseFlag::UnauthorizedExternalService));
EXPECT_CALL(mock_decoder_callbacks_.stream_info_,
setResponseFlag(Envoy::StreamInfo::UnauthorizedExternalService));
EXPECT_CALL(
mock_decoder_callbacks_,
sendLocalReply(Envoy::Http::Code::Unauthorized, "UNAUTHENTICATED: test",
Expand Down Expand Up @@ -202,10 +199,8 @@ TEST_F(ServiceControlFilterTest, DecodeHeadersAsyncBadStatus) {
filter_->decodeHeaders(req_headers_, true));

// Filter should reject this request
EXPECT_CALL(
mock_decoder_callbacks_.stream_info_,
setResponseFlag(
Envoy::StreamInfo::ResponseFlag::UnauthorizedExternalService));
EXPECT_CALL(mock_decoder_callbacks_.stream_info_,
setResponseFlag(Envoy::StreamInfo::UnauthorizedExternalService));

EXPECT_CALL(
mock_decoder_callbacks_,
Expand All @@ -215,22 +210,12 @@ TEST_F(ServiceControlFilterTest, DecodeHeadersAsyncBadStatus) {
kBadStatus, "service_control_check_error{API_KEY_INVALID}");
}

TEST_F(ServiceControlFilterTest, LogWithoutHandlerOrHeaders) {
// Test: If no handler and no headers, a handler is not created
EXPECT_CALL(mock_handler_factory_, createHandler(_, _, _)).Times(0);

// Filter has no handler. If it tries to callReport, it will seg fault
filter_->log(nullptr, &resp_headers_, &resp_trailer_,
mock_decoder_callbacks_.stream_info_,
Envoy::AccessLog::AccessLogType::NotSet);
}

TEST_F(ServiceControlFilterTest, LogWithoutHandler) {
// Test: When a Filter has no Handler yet, another is created for log()
EXPECT_CALL(*mock_handler_, callReport(_, _, _, _));
filter_->log(&req_headers_, &resp_headers_, &resp_trailer_,
mock_decoder_callbacks_.stream_info_,
Envoy::AccessLog::AccessLogType::NotSet);
Envoy::Formatter::HttpFormatterContext context(&req_headers_, &resp_headers_,
&resp_trailer_);
filter_->log(context, mock_decoder_callbacks_.stream_info_);
}

TEST_F(ServiceControlFilterTest, LogWithHandler) {
Expand All @@ -240,9 +225,9 @@ TEST_F(ServiceControlFilterTest, LogWithHandler) {

EXPECT_CALL(mock_handler_factory_, createHandler(_, _, _)).Times(0);
EXPECT_CALL(*mock_handler_, callReport(_, _, _, _));
filter_->log(&req_headers_, &resp_headers_, &resp_trailer_,
mock_decoder_callbacks_.stream_info_,
Envoy::AccessLog::AccessLogType::NotSet);
Envoy::Formatter::HttpFormatterContext context(&req_headers_, &resp_headers_,
&resp_trailer_);
filter_->log(context, mock_decoder_callbacks_.stream_info_);
}

TEST_F(ServiceControlFilterTest, DecodeHelpersWhileStopped) {
Expand Down
20 changes: 11 additions & 9 deletions src/envoy/http/service_control/handler_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,24 @@ inline int64_t convertNsToMs(std::chrono::nanoseconds ns) {
return std::chrono::duration_cast<std::chrono::milliseconds>(ns).count();
}

bool extractAPIKeyFromQuery(const Envoy::Http::RequestHeaderMap& headers,
const std::string& query, bool& were_params_parsed,
Envoy::Http::Utility::QueryParams& parsed_params,
std::string& api_key) {
bool extractAPIKeyFromQuery(
const Envoy::Http::RequestHeaderMap& headers, const std::string& query,
bool& were_params_parsed,
Envoy::Http::Utility::QueryParamsMulti& parsed_params,
std::string& api_key) {
if (!were_params_parsed) {
if (headers.Path() == nullptr) {
return false;
}
parsed_params = Envoy::Http::Utility::parseQueryString(
parsed_params = Envoy::Http::Utility::QueryParamsMulti::parseQueryString(
headers.Path()->value().getStringView());
were_params_parsed = true;
}

const auto& it = parsed_params.find(query);
if (it != parsed_params.end()) {
api_key = it->second;
std::optional<std::string> query_param_value =
parsed_params.getFirstValue(query);
if (query_param_value.has_value()) {
api_key = *query_param_value;
return true;
}
return false;
Expand Down Expand Up @@ -309,7 +311,7 @@ bool extractAPIKey(
// If checking multiple headers, cache the parameters so they are only parsed
// once
bool were_params_parsed{false};
Envoy::Http::Utility::QueryParams parsed_params;
Envoy::Http::Utility::QueryParamsMulti parsed_params;

for (const auto& location : locations) {
switch (location.key_case()) {
Expand Down
3 changes: 2 additions & 1 deletion src/envoy/http/service_control/http_call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ class HttpCallImpl : public HttpCall,
request_span_->setTag(Envoy::Tracing::Tags::get().HttpMethod, "POST");

Envoy::Http::RequestMessagePtr message = prepareHeaders(token);
request_span_->injectContext(message->headers(), nullptr);
Envoy::Tracing::HttpTraceContext trace_context(message->headers());
request_span_->injectContext(trace_context, nullptr);
ENVOY_LOG(debug, "http call from [uri = {}]: start", uri_);

const auto thread_local_cluster =
Expand Down
11 changes: 6 additions & 5 deletions src/envoy/http/service_control/service_control_call_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ ServiceControlCallImpl::ServiceControlCallImpl(
Envoy::Server::Configuration::FactoryContext& context)
: filter_config_(*proto_config),
token_subscriber_factory_(context),
tls_(context.threadLocal()) {
tls_(context.serverFactoryContext().threadLocal()) {
// Pass shared_ptr of proto_config to the function capture so that
// it will not be released when the function is called.
tls_.set([proto_config, &config, stats_prefix, &scope = context.scope(),
&cm = context.clusterManager(),
&time_source =
context.timeSource()](Envoy::Event::Dispatcher& dispatcher) {
tls_.set([proto_config, &config, stats_prefix,
&scope = context.serverFactoryContext().scope(),
&cm = context.serverFactoryContext().clusterManager(),
&time_source = context.serverFactoryContext().timeSource()](
Envoy::Event::Dispatcher& dispatcher) {
return std::make_shared<ThreadLocalCache>(config, *proto_config,
stats_prefix, scope, cm,
time_source, dispatcher);
Expand Down
Loading

0 comments on commit d830bca

Please sign in to comment.