Skip to content
Merged
2 changes: 1 addition & 1 deletion bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def envoy_api_deps(skip_targets):
native.git_repository(
name = "envoy_api",
remote = REPO_LOCATIONS["envoy_api"],
commit = "b9e89d760d4849812b43a0979aa756137563bf83",
commit = "2ece56b705813e1a7176ceb73abf4fb67563f676",
)
api_bind_targets = [
"address",
Expand Down
4 changes: 2 additions & 2 deletions configs/google_com_proxy.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static_resources:
socket_address: { address: 127.0.0.1, port_value: 10000 }
filter_chains:
- filters:
- name: http_connection_manager
- name: envoy.http_connection_manager
config:
stat_prefix: ingress_http
codec_type: AUTO
Expand All @@ -23,7 +23,7 @@ static_resources:
- match: { prefix: "/" }
route: { host_rewrite: www.google.com, cluster: service_google }
http_filters:
- name: router
- name: envoy.router
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really appreciate the cleanup here! :)

config: { deprecated_v1: true }
clusters:
- name: service_google
Expand Down
10 changes: 10 additions & 0 deletions include/envoy/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ load(

envoy_package()

envoy_cc_library(
name = "access_log_config_interface",
hdrs = ["access_log_config.h"],
deps = [
":filter_config_interface",
"//include/envoy/access_log:access_log_interface",
"//source/common/protobuf",
],
)

envoy_cc_library(
name = "admin_interface",
hdrs = ["admin.h"],
Expand Down
51 changes: 51 additions & 0 deletions include/envoy/server/access_log_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include <string>

#include "envoy/http/access_log.h"
#include "envoy/server/filter_config.h"

#include "common/protobuf/protobuf.h"

namespace Envoy {
namespace Server {
namespace Configuration {

/**
* Implemented for each AccessLog::Instance and registered via Registry::registerFactory or the
* convenience class RegisterFactory.
*/
class AccessLogInstanceFactory {
public:
virtual ~AccessLogInstanceFactory() {}

/**
* Create a particular AccessLog::Instance implementation from a config proto. If the
* implementation is unable to produce a factory with the provided parameters, it should throw an
* EnvoyException. The returned pointer should never be nullptr.
* @param config the custom configuration for this access log type.
* @param filter filter to determine whether a particular request should be logged. If no filter
* was specified in the configuration, argument will be nullptr.
* @param context general filter context through which persistent resources can be accessed.
*/
virtual Http::AccessLog::InstanceSharedPtr
createAccessLogInstance(const Protobuf::Message& config, Http::AccessLog::FilterPtr&& filter,
FactoryContext& context) PURE;

/**
* @return ProtobufTypes::MessagePtr create empty config proto message for v2. The config, which
* arrives in an opaque google.protobuf.Struct message, will be converted to JSON and then parsed
* into this empty proto.
*/
virtual ProtobufTypes::MessagePtr createEmptyConfigProto() PURE;

/**
* @return std::string the identifying name for a particular AccessLog::Instance implementation
* produced by the factory.
*/
virtual std::string name() const PURE;
};

} // namespace Configuration
} // namespace Server
} // namespace Envoy
13 changes: 13 additions & 0 deletions source/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ envoy_cc_library(
":utility_lib",
"//include/envoy/json:json_object_interface",
"//source/common/common:assert_lib",
"//source/common/config:well_known_names",
"//source/common/json:config_schemas_lib",
"//source/common/protobuf:utility_lib",
],
Expand Down Expand Up @@ -119,6 +120,7 @@ envoy_cc_library(
"//include/envoy/json:json_object_interface",
"//source/common/common:assert_lib",
"//source/common/common:utility_lib",
"//source/common/config:well_known_names",
"//source/common/json:config_schemas_lib",
"//source/common/protobuf",
"//source/common/protobuf:utility_lib",
Expand Down Expand Up @@ -176,6 +178,7 @@ envoy_cc_library(
":address_json_lib",
":json_utility_lib",
":tls_context_json_lib",
":well_known_names",
"//include/envoy/json:json_object_interface",
"//source/common/common:assert_lib",
"//source/common/json:config_schemas_lib",
Expand Down Expand Up @@ -214,6 +217,7 @@ envoy_cc_library(
":base_json_lib",
":json_utility_lib",
":metadata_lib",
":well_known_names",
"//include/envoy/json:json_object_interface",
"//source/common/common:assert_lib",
"//source/common/json:config_schemas_lib",
Expand Down Expand Up @@ -259,10 +263,19 @@ envoy_cc_library(
":json_utility_lib",
"//include/envoy/config:subscription_interface",
"//include/envoy/local_info:local_info_interface",
"//include/envoy/registry",
"//include/envoy/upstream:cluster_manager_interface",
"//source/common/common:assert_lib",
"//source/common/common:hex_lib",
"//source/common/common:singleton",
"//source/common/json:config_schemas_lib",
"//source/common/protobuf",
"//source/common/protobuf:utility_lib",
],
)

envoy_cc_library(
name = "well_known_names",
hdrs = ["well_known_names.h"],
deps = ["//source/common/common:singleton"],
)
5 changes: 3 additions & 2 deletions source/common/config/bootstrap_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common/config/json_utility.h"
#include "common/config/lds_json.h"
#include "common/config/utility.h"
#include "common/config/well_known_names.h"
#include "common/json/config_schemas.h"
#include "common/protobuf/utility.h"

Expand Down Expand Up @@ -71,7 +72,7 @@ void BootstrapJson::translateBootstrap(const Json::Object& json_config,
auto* stats_sinks = bootstrap.mutable_stats_sinks();
if (json_config.hasObject("statsd_udp_ip_address")) {
auto* stats_sink = stats_sinks->Add();
stats_sink->set_name("envoy.statsd");
stats_sink->set_name(Config::StatsSinkNames::get().STATSD);
envoy::api::v2::StatsdSink statsd_sink;
AddressJson::translateAddress(json_config.getString("statsd_udp_ip_address"), false, true,
*statsd_sink.mutable_address());
Expand All @@ -80,7 +81,7 @@ void BootstrapJson::translateBootstrap(const Json::Object& json_config,

if (json_config.hasObject("statsd_tcp_cluster_name")) {
auto* stats_sink = stats_sinks->Add();
stats_sink->set_name("envoy.statsd");
stats_sink->set_name(Config::StatsSinkNames::get().STATSD);
envoy::api::v2::StatsdSink statsd_sink;
statsd_sink.set_tcp_cluster_name(json_config.getString("statsd_tcp_cluster_name"));
MessageUtil::jsonConvert(statsd_sink, *stats_sink->mutable_config());
Expand Down
19 changes: 17 additions & 2 deletions source/common/config/filter_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common/config/protocol_json.h"
#include "common/config/rds_json.h"
#include "common/config/utility.h"
#include "common/config/well_known_names.h"
#include "common/json/config_schemas.h"
#include "common/protobuf/protobuf.h"
#include "common/protobuf/utility.h"
Expand Down Expand Up @@ -88,8 +89,18 @@ void FilterJson::translateAccessLogFilter(

void FilterJson::translateAccessLog(const Json::Object& json_access_log,
envoy::api::v2::filter::AccessLog& access_log) {
JSON_UTIL_SET_STRING(json_access_log, access_log, path);
JSON_UTIL_SET_STRING(json_access_log, access_log, format);
envoy::api::v2::filter::FileAccessLog file_access_log;

JSON_UTIL_SET_STRING(json_access_log, file_access_log, path);
JSON_UTIL_SET_STRING(json_access_log, file_access_log, format);

ProtobufWkt::Struct& custom_config = *access_log.mutable_config();
MessageUtil::jsonConvert(file_access_log, custom_config);

// Statically registered access logs are a v2-only feature, so use the standard internal file
// access log for json config conversion.
access_log.set_name(Config::AccessLogNames::get().FILE);

if (json_access_log.hasObject("filter")) {
translateAccessLogFilter(*json_access_log.getObject("filter"), *access_log.mutable_filter());
}
Expand Down Expand Up @@ -123,6 +134,10 @@ void FilterJson::translateHttpConnectionManager(
for (const auto& json_filter : json_http_connection_manager.getObjectArray("filters", true)) {
auto* filter = http_connection_manager.mutable_http_filters()->Add();
JSON_UTIL_SET_STRING(*json_filter, *filter, name);

// Translate v1 name to v2 name.
filter->set_name(
Config::HttpFilterNames::get().v1_converter_.getV2Name(json_filter->getString("name")));
JSON_UTIL_SET_STRING(*json_filter, *filter->mutable_deprecated_v1(), type);

const std::string json_config = "{\"deprecated_v1\": true, \"value\": " +
Expand Down
6 changes: 5 additions & 1 deletion source/common/config/lds_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "common/config/address_json.h"
#include "common/config/json_utility.h"
#include "common/config/tls_context_json.h"
#include "common/config/well_known_names.h"
#include "common/json/config_schemas.h"
#include "common/network/utility.h"

Expand All @@ -25,7 +26,10 @@ void LdsJson::translateListener(const Json::Object& json_listener,

for (const auto& json_filter : json_listener.getObjectArray("filters", true)) {
auto* filter = filter_chain->mutable_filters()->Add();
JSON_UTIL_SET_STRING(*json_filter, *filter, name);

// Translate v1 name to v2 name.
filter->set_name(
Config::NetworkFilterNames::get().v1_converter_.getV2Name(json_filter->getString("name")));
JSON_UTIL_SET_STRING(*json_filter, *filter->mutable_deprecated_v1(), type);

const std::string json_config = "{\"deprecated_v1\": true, \"value\": " +
Expand Down
24 changes: 0 additions & 24 deletions source/common/config/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,5 @@ class Metadata {
const std::string& key);
};

/**
* Well-known metadata filter namespaces.
*/
class MetadataFilterValues {
public:
// Filter namespace for built-in load balancer.
const std::string ENVOY_LB = "envoy.lb";
// Filter namespace for built-in router opaque data.
const std::string ENVOY_ROUTER = "envoy.router";
};

typedef ConstSingleton<MetadataFilterValues> MetadataFilters;

/**
* Keys for MetadataFilterConstants::ENVOY_LB metadata.
*/
class MetadataEnvoyLbKeyValues {
public:
// Key in envoy.lb filter namespace for endpoint canary bool value.
const std::string CANARY = "canary";
};

typedef ConstSingleton<MetadataEnvoyLbKeyValues> MetadataEnvoyLbKeys;

} // namespace Config
} // namespace Envoy
3 changes: 2 additions & 1 deletion source/common/config/rds_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "common/config/base_json.h"
#include "common/config/json_utility.h"
#include "common/config/metadata.h"
#include "common/config/well_known_names.h"
#include "common/json/config_schemas.h"

namespace Envoy {
Expand Down Expand Up @@ -267,7 +268,7 @@ void RdsJson::translateRoute(const Json::Object& json_route, envoy::api::v2::Rou
if (json_route.hasObject("opaque_config")) {
const Json::ObjectSharedPtr obj = json_route.getObject("opaque_config");
auto& filter_metadata =
(*route.mutable_metadata()->mutable_filter_metadata())[MetadataFilters::get().ENVOY_ROUTER];
(*route.mutable_metadata()->mutable_filter_metadata())[HttpFilterNames::get().ROUTER];
obj->iterate([&filter_metadata](const std::string& name, const Json::Object& value) {
(*filter_metadata.mutable_fields())[name].set_string_value(value.asString());
return true;
Expand Down
48 changes: 48 additions & 0 deletions source/common/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include "envoy/config/subscription.h"
#include "envoy/json/json_object.h"
#include "envoy/local_info/local_info.h"
#include "envoy/registry/registry.h"
#include "envoy/upstream/cluster_manager.h"

#include "common/common/singleton.h"
#include "common/protobuf/protobuf.h"
#include "common/protobuf/utility.h"

#include "api/base.pb.h"
#include "api/filter/http_connection_manager.pb.h"
Expand Down Expand Up @@ -132,6 +134,52 @@ class Utility {
static SubscriptionStats generateStats(Stats::Scope& scope) {
return {ALL_SUBSCRIPTION_STATS(POOL_COUNTER(scope))};
}

/**
* Get a Factory from the registry with a particular name (and templated type) with error checking
* to ensure the name and factory are valid.
* @param name string identifier for the particular implementation. Note: this is a proto string
* because it is assumed that this value will be pulled directly from the configuration proto.
*/
template <class Factory> static Factory& getAndCheckFactory(const ProtobufTypes::String& name) {
if (name.empty()) {
throw EnvoyException("Provided name for static registration lookup was empty.");
}

Factory* factory = Registry::FactoryRegistry<Factory>::getFactory(name);

if (factory == nullptr) {
throw EnvoyException(
fmt::format("Didn't find a registered implementation for name: '{}'", name));
}

return *factory;
}

/**
* Translate a nested config into a proto message provided by the implementation factory.
* @param enclosing_message proto that contains a field 'config'. Note: the enclosing proto is
* provided because for statically registered implementations, a custom config is generally
* optional, which means the conversion must be done conditionally.
* @param factory implementation factory with the method 'createEmptyConfigProto' to produce a
* proto to be filled with the translated configuration.
*/
template <class ProtoMessage, class Factory>
static ProtobufTypes::MessagePtr translateToFactoryConfig(const ProtoMessage& enclosing_message,
Factory& factory) {
ProtobufTypes::MessagePtr config = factory.createEmptyConfigProto();

if (config == nullptr) {
throw EnvoyException(fmt::format(
"{} factory returned nullptr instead of empty config message.", factory.name()));
}

if (enclosing_message.has_config()) {
MessageUtil::jsonConvert(enclosing_message.config(), *config);
}

return config;
}
};

} // namespace Config
Expand Down
Loading