Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/envoyproxy/envoy into add…
Browse files Browse the repository at this point in the history
…-supports_pthread_getname_np-definition

Signed-off-by: Alan Chiu <achiu@lyft.com>
  • Loading branch information
Alan Chiu committed Jul 14, 2020
2 parents bf90d74 + 0c6523c commit 354fa04
Show file tree
Hide file tree
Showing 46 changed files with 872 additions and 241 deletions.
4 changes: 2 additions & 2 deletions GOVERNANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
questions and do all reviews, but it is their responsibility to make sure that everything is
being actively covered by someone.
* The on-call rotation is tracked at Opsgenie. The calendar is visible
[here](https://calendar.google.com/calendar/embed?src=ms6efr2erlvum9aolnvg1688cd3mu85e%40import.calendar.google.com&ctz=America%2FNew_York)
or you can subscribe to the iCal feed [here](https://app.opsgenie.com/webcal/getRecentSchedule?webcalToken=75f2990470ca21de1033ecf4586bea1e40bae32bf3c39e2289f6186da1904ee0&scheduleId=a3505963-c064-4c97-8865-947dfcb06060)
[here](https://calendar.google.com/calendar/embed?src=d6glc0l5rc3v235q9l2j29dgovh3dn48%40import.calendar.google.com&ctz=America%2FNew_York)
or you can subscribe to the iCal feed [here](webcal://kubernetes.app.opsgenie.com/webapi/webcal/getRecentSchedule?webcalToken=39dd1a892faa8d0d689f889b9d09ae787355ddff894396546726a5a02bac5b26&scheduleId=a3505963-c064-4c97-8865-947dfcb06060)

## Cutting a release

Expand Down
4 changes: 4 additions & 0 deletions api/envoy/config/route/v3/route_components.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,10 @@ message RateLimit {
// Metadata struct that defines the key and path to retrieve the string value. A match will
// only happen if the value in the dynamic metadata is of type string.
type.metadata.v3.MetadataKey metadata_key = 2 [(validate.rules).message = {required: true}];

// An optional value to use if *metadata_key* is empty. If not set and
// no value is present under the metadata_key then no descriptor is generated.
string default_value = 3;
}

oneof action_specifier {
Expand Down
4 changes: 4 additions & 0 deletions api/envoy/config/route/v4alpha/route_components.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/envoy/data/dns/v3/dns_table.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ message DnsTable {
"envoy.data.dns.v2alpha.DnsTable.DnsVirtualDomain";

// A domain name for which Envoy will respond to query requests
string name = 1 [(validate.rules).string = {min_len: 2 well_known_regex: HTTP_HEADER_NAME}];
string name = 1 [(validate.rules).string = {min_len: 1 well_known_regex: HTTP_HEADER_NAME}];

// The configuration containing the method to determine the address of this endpoint
DnsEndpoint endpoint = 2;

// Sets the TTL in DNS answers from Envoy returned to the client. The default TTL is 300s
google.protobuf.Duration answer_ttl = 3 [(validate.rules).duration = {gte {seconds: 60}}];
google.protobuf.Duration answer_ttl = 3 [(validate.rules).duration = {gte {seconds: 30}}];
}

// Control how many times Envoy makes an attempt to forward a query to an external DNS server
Expand Down
4 changes: 2 additions & 2 deletions api/envoy/data/dns/v4alpha/dns_table.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Removed Config or Runtime

New Features
------------
* grpc-json: support specifying `response_body` field in for `google.api.HttpBody` message.
* tap: added :ref:`generic body matcher<envoy_v3_api_msg_config.tap.v3.HttpGenericBodyMatch>` to scan http requests and responses for text or hex patterns.

Deprecated
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated_api_shadow/envoy/data/dns/v3/dns_table.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated_api_shadow/envoy/data/dns/v4alpha/dns_table.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions include/envoy/common/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ struct mmsghdr {
};
#endif

#define SUPPORTS_GETIFADDRS
#ifdef WIN32
#undef SUPPORTS_GETIFADDRS
#endif

// https://android.googlesource.com/platform/prebuilts/ndk/+/dev/platform/sysroot/usr/include/ifaddrs.h
#ifdef __ANDROID_API__
#if __ANDROID_API__ < 24
#undef SUPPORTS_GETIFADDRS
#endif // __ANDROID_API__ < 24
#endif // ifdef __ANDROID_API__

#ifdef __linux__
#define SUPPORTS_PTHREAD_GETNAME_NP 1
#endif
Expand Down
32 changes: 2 additions & 30 deletions include/envoy/server/overload_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,8 @@ using OverloadActionCb = std::function<void(OverloadActionState)>;
*/
class ThreadLocalOverloadState : public ThreadLocal::ThreadLocalObject {
public:
const OverloadActionState& getState(const std::string& action) {
auto it = actions_.find(action);
if (it == actions_.end()) {
it = actions_.insert(std::make_pair(action, OverloadActionState::Inactive)).first;
}
return it->second;
}

void setState(const std::string& action, OverloadActionState state) {
auto it = actions_.find(action);
if (it == actions_.end()) {
actions_[action] = state;
} else {
it->second = state;
}
}

private:
std::unordered_map<std::string, OverloadActionState> actions_;
// Get a thread-local reference to the value for the given action key.
virtual const OverloadActionState& getState(const std::string& action) PURE;
};

/**
Expand Down Expand Up @@ -106,17 +89,6 @@ class OverloadManager {
* an alternative to registering a callback for overload action state changes.
*/
virtual ThreadLocalOverloadState& getThreadLocalOverloadState() PURE;

/**
* Convenience method to get a statically allocated reference to the inactive overload
* action state. Useful for code that needs to initialize a reference either to an
* entry in the ThreadLocalOverloadState map (if overload behavior is enabled) or to
* some other static memory location set to the inactive state (if overload behavior
* is disabled).
*/
static const OverloadActionState& getInactiveState() {
CONSTRUCT_ON_FIRST_USE(OverloadActionState, OverloadActionState::Inactive);
}
};

} // namespace Server
Expand Down
2 changes: 2 additions & 0 deletions source/common/common/random_generator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include "envoy/common/random_generator.h"

namespace Envoy {
Expand Down
14 changes: 5 additions & 9 deletions source/common/http/conn_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ ConnectionManagerImpl::ConnectionManagerImpl(ConnectionManagerConfig& config,
Http::Context& http_context, Runtime::Loader& runtime,
const LocalInfo::LocalInfo& local_info,
Upstream::ClusterManager& cluster_manager,
Server::OverloadManager* overload_manager,
Server::OverloadManager& overload_manager,
TimeSource& time_source)
: config_(config), stats_(config_.stats()),
conn_length_(new Stats::HistogramCompletableTimespanImpl(
Expand All @@ -113,14 +113,10 @@ ConnectionManagerImpl::ConnectionManagerImpl(ConnectionManagerConfig& config,
random_generator_(random_generator), http_context_(http_context), runtime_(runtime),
local_info_(local_info), cluster_manager_(cluster_manager),
listener_stats_(config_.listenerStats()),
overload_stop_accepting_requests_ref_(
overload_manager ? overload_manager->getThreadLocalOverloadState().getState(
Server::OverloadActionNames::get().StopAcceptingRequests)
: Server::OverloadManager::getInactiveState()),
overload_disable_keepalive_ref_(
overload_manager ? overload_manager->getThreadLocalOverloadState().getState(
Server::OverloadActionNames::get().DisableHttpKeepAlive)
: Server::OverloadManager::getInactiveState()),
overload_stop_accepting_requests_ref_(overload_manager.getThreadLocalOverloadState().getState(
Server::OverloadActionNames::get().StopAcceptingRequests)),
overload_disable_keepalive_ref_(overload_manager.getThreadLocalOverloadState().getState(
Server::OverloadActionNames::get().DisableHttpKeepAlive)),
time_source_(time_source) {}

const ResponseHeaderMap& ConnectionManagerImpl::continueHeader() {
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/conn_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>,
Random::RandomGenerator& random_generator, Http::Context& http_context,
Runtime::Loader& runtime, const LocalInfo::LocalInfo& local_info,
Upstream::ClusterManager& cluster_manager,
Server::OverloadManager* overload_manager, TimeSource& time_system);
Server::OverloadManager& overload_manager, TimeSource& time_system);
~ConnectionManagerImpl() override;

static ConnectionManagerStats generateStats(const std::string& prefix, Stats::Scope& scope);
Expand Down
2 changes: 1 addition & 1 deletion source/common/network/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void Utility::throwWithMalformedIp(absl::string_view ip_address) {
// need to be updated in the future. Discussion can be found at Github issue #939.
Address::InstanceConstSharedPtr Utility::getLocalAddress(const Address::IpVersion version) {
Address::InstanceConstSharedPtr ret;
#ifndef WIN32
#ifdef SUPPORTS_GETIFADDRS
struct ifaddrs* ifaddr;
struct ifaddrs* ifa;

Expand Down
15 changes: 10 additions & 5 deletions source/common/router/router_ratelimit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,25 @@ bool GenericKeyAction::populateDescriptor(const Router::RouteEntry&,

DynamicMetaDataAction::DynamicMetaDataAction(
const envoy::config::route::v3::RateLimit::Action::DynamicMetaData& action)
: metadata_key_(action.metadata_key()), descriptor_key_(action.descriptor_key()) {}
: metadata_key_(action.metadata_key()), descriptor_key_(action.descriptor_key()),
default_value_(action.default_value()) {}

bool DynamicMetaDataAction::populateDescriptor(
const Router::RouteEntry&, RateLimit::Descriptor& descriptor, const std::string&,
const Http::HeaderMap&, const Network::Address::Instance&,
const envoy::config::core::v3::Metadata* dynamic_metadata) const {
const ProtobufWkt::Value& metadata_value =
Envoy::Config::Metadata::metadataValue(dynamic_metadata, metadata_key_);
if (metadata_value.kind_case() != ProtobufWkt::Value::kStringValue) {
return false;

if (!metadata_value.string_value().empty()) {
descriptor.entries_.push_back({descriptor_key_, metadata_value.string_value()});
return true;
} else if (metadata_value.string_value().empty() && !default_value_.empty()) {
descriptor.entries_.push_back({descriptor_key_, default_value_});
return true;
}
descriptor.entries_.push_back({descriptor_key_, metadata_value.string_value()});

return !metadata_value.string_value().empty();
return false;
}

HeaderValueMatchAction::HeaderValueMatchAction(
Expand Down
1 change: 1 addition & 0 deletions source/common/router/router_ratelimit.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class DynamicMetaDataAction : public RateLimitAction {
private:
const Envoy::Config::MetadataKey metadata_key_;
const std::string descriptor_key_;
const std::string default_value_;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/filters/common/lua/lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ThreadLocalState::ThreadLocalState(const std::string& code, ThreadLocal::SlotAll

// First verify that the supplied code can be parsed.
CSmartPtr<lua_State, lua_close> state(lua_open());
ASSERT(state.get() != nullptr, "unable to create new lua state object");
RELEASE_ASSERT(state.get() != nullptr, "unable to create new Lua state object");
luaL_openlibs(state.get());

if (0 != luaL_dostring(state.get(), code.c_str())) {
Expand Down Expand Up @@ -92,7 +92,7 @@ CoroutinePtr ThreadLocalState::createCoroutine() {
}

ThreadLocalState::LuaThreadLocal::LuaThreadLocal(const std::string& code) : state_(lua_open()) {
ASSERT(state_.get() != nullptr, "unable to create new lua state object");
RELEASE_ASSERT(state_.get() != nullptr, "unable to create new Lua state object");
luaL_openlibs(state_.get());
int rc = luaL_dostring(state_.get(), code.c_str());
ASSERT(rc == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,70 @@

#include "google/api/httpbody.pb.h"

using Envoy::Protobuf::io::CodedInputStream;
using Envoy::Protobuf::io::CodedOutputStream;
using Envoy::Protobuf::io::StringOutputStream;
using Envoy::Protobuf::io::ZeroCopyInputStream;

namespace Envoy {
namespace Extensions {
namespace HttpFilters {
namespace GrpcJsonTranscoder {

namespace {

// Embedded messages are treated the same way as strings (wire type 2).
constexpr uint32_t ProtobufLengthDelimitedField = 2;

bool parseMessageByFieldPath(CodedInputStream* input,
absl::Span<const Protobuf::Field* const> field_path,
Protobuf::Message* message) {
if (field_path.empty()) {
return message->MergeFromCodedStream(input);
}

const uint32_t expected_tag = (field_path.front()->number() << 3) | ProtobufLengthDelimitedField;
for (;;) {
const uint32_t tag = input->ReadTag();
if (tag == expected_tag) {
uint32_t length = 0;
if (!input->ReadVarint32(&length)) {
return false;
}
auto limit = input->IncrementRecursionDepthAndPushLimit(length);
if (!parseMessageByFieldPath(input, field_path.subspan(1), message)) {
return false;
}
if (!input->DecrementRecursionDepthAndPopLimit(limit.first)) {
return false;
}
} else if (tag == 0) {
return true;
} else {
if (!Protobuf::internal::WireFormatLite::SkipField(input, tag)) {
return false;
}
}
}
}
} // namespace

bool HttpBodyUtils::parseMessageByFieldPath(ZeroCopyInputStream* stream,
const std::vector<const Protobuf::Field*>& field_path,
Protobuf::Message* message) {
CodedInputStream input(stream);
input.SetRecursionLimit(field_path.size());

return GrpcJsonTranscoder::parseMessageByFieldPath(&input, absl::MakeConstSpan(field_path),
message);
}

void HttpBodyUtils::appendHttpBodyEnvelope(
Buffer::Instance& output, const std::vector<const Protobuf::Field*>& request_body_field_path,
std::string content_type, uint64_t content_length) {
// Manually encode the protobuf envelope for the body.
// See https://developers.google.com/protocol-buffers/docs/encoding#embedded for wire format.

// Embedded messages are treated the same way as strings (wire type 2).
constexpr uint32_t ProtobufLengthDelimitedField = 2;

std::string proto_envelope;
{
// For memory safety, the StringOutputStream needs to be destroyed before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace GrpcJsonTranscoder {

class HttpBodyUtils {
public:
static bool parseMessageByFieldPath(Protobuf::io::ZeroCopyInputStream* stream,
const std::vector<const Protobuf::Field*>& field_path,
Protobuf::Message* message);
static void
appendHttpBodyEnvelope(Buffer::Instance& output,
const std::vector<const Protobuf::Field*>& request_body_field_path,
Expand Down
Loading

0 comments on commit 354fa04

Please sign in to comment.