Skip to content

Commit

Permalink
Http filter cleanup after V2 API changes (envoyproxy#1944)
Browse files Browse the repository at this point in the history
Signed-off-by: Shriram Rajagopalan <[email protected]>
  • Loading branch information
rshriram authored and mattklein123 committed Oct 26, 2017
1 parent 13e4151 commit 747fe8d
Show file tree
Hide file tree
Showing 27 changed files with 231 additions and 183 deletions.
32 changes: 30 additions & 2 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ def envoy_api_deps(skip_targets):
native.git_repository(
name = "envoy_api",
remote = REPO_LOCATIONS["envoy_api"],
commit = "d4988844024d0bcff4bcd030552eabe3396203fa",
commit = "f2c1dc99df64144f76107725bde870dd6827e044",
)

api_bind_targets = [
"address",
"base",
Expand All @@ -127,13 +128,40 @@ def envoy_api_deps(skip_targets):
actual = "@envoy_api//api:" + t + "_cc",
)
filter_bind_targets = [
"http_connection_manager",
"fault",
]
for t in filter_bind_targets:
native.bind(
name = "envoy_filter_" + t,
actual = "@envoy_api//api/filter:" + t + "_cc",
)
http_filter_bind_targets = [
"http_connection_manager",
"router",
"buffer",
"transcoder",
"rate_limit",
"ip_tagging",
"health_check",
"fault",
]
for t in http_filter_bind_targets:
native.bind(
name = "envoy_filter_" + t,
actual = "@envoy_api//api/filter/http:" + t + "_cc",
)
network_filter_bind_targets = [
"tcp_proxy",
"mongo_proxy",
"redis_proxy",
"rate_limit",
"client_ssl_auth",
]
for t in network_filter_bind_targets:
native.bind(
name = "envoy_filter_" + t,
actual = "@envoy_api//api/filter/network:" + t + "_cc",
)
native.bind(
name = "http_api_protos",
actual = "@googleapis//:http_api_protos",
Expand Down
4 changes: 2 additions & 2 deletions include/envoy/router/route_config_provider_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "envoy/thread_local/thread_local.h"
#include "envoy/upstream/cluster_manager.h"

#include "api/filter/http_connection_manager.pb.h"
#include "api/filter/http/http_connection_manager.pb.h"

namespace Envoy {
namespace Router {
Expand All @@ -39,7 +39,7 @@ class RouteConfigProviderManager {
* @param init_manager supplies the init manager.
*/
virtual RouteConfigProviderSharedPtr
getRouteConfigProvider(const envoy::api::v2::filter::Rds& rds, Upstream::ClusterManager& cm,
getRouteConfigProvider(const envoy::api::v2::filter::http::Rds& rds, Upstream::ClusterManager& cm,
Stats::Scope& scope, const std::string& stat_prefix,
Init::Manager& init_manager) PURE;
};
Expand Down
39 changes: 20 additions & 19 deletions source/common/config/filter_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ namespace Config {
namespace {

void translateComparisonFilter(const Json::Object& config,
envoy::api::v2::filter::ComparisonFilter& filter) {
envoy::api::v2::filter::http::ComparisonFilter& filter) {
const std::string op = config.getString("op");
if (op == ">=") {
filter.set_op(envoy::api::v2::filter::ComparisonFilter::GE);
filter.set_op(envoy::api::v2::filter::http::ComparisonFilter::GE);
} else {
ASSERT(op == "=");
filter.set_op(envoy::api::v2::filter::ComparisonFilter::EQ);
filter.set_op(envoy::api::v2::filter::http::ComparisonFilter::EQ);
}

auto* runtime = filter.mutable_value();
Expand All @@ -32,41 +32,42 @@ void translateComparisonFilter(const Json::Object& config,
}

void translateStatusCodeFilter(const Json::Object& config,
envoy::api::v2::filter::StatusCodeFilter& filter) {
envoy::api::v2::filter::http::StatusCodeFilter& filter) {
translateComparisonFilter(config, *filter.mutable_comparison());
}

void translateDurationFilter(const Json::Object& config,
envoy::api::v2::filter::DurationFilter& filter) {
envoy::api::v2::filter::http::DurationFilter& filter) {
translateComparisonFilter(config, *filter.mutable_comparison());
}

void translateRuntimeFilter(const Json::Object& config,
envoy::api::v2::filter::RuntimeFilter& filter) {
envoy::api::v2::filter::http::RuntimeFilter& filter) {
filter.set_runtime_key(config.getString("key"));
}

void translateRepeatedFilter(
const Json::Object& config,
Protobuf::RepeatedPtrField<envoy::api::v2::filter::AccessLogFilter>& filters) {
Protobuf::RepeatedPtrField<envoy::api::v2::filter::http::AccessLogFilter>& filters) {
for (const auto& json_filter : config.getObjectArray("filters")) {
FilterJson::translateAccessLogFilter(*json_filter, *filters.Add());
}
}

void translateOrFilter(const Json::Object& config, envoy::api::v2::filter::OrFilter& filter) {
void translateOrFilter(const Json::Object& config, envoy::api::v2::filter::http::OrFilter& filter) {
translateRepeatedFilter(config, *filter.mutable_filters());
}

void translateAndFilter(const Json::Object& config, envoy::api::v2::filter::AndFilter& filter) {
void translateAndFilter(const Json::Object& config,
envoy::api::v2::filter::http::AndFilter& filter) {
translateRepeatedFilter(config, *filter.mutable_filters());
}

} // namespace

void FilterJson::translateAccessLogFilter(
const Json::Object& json_access_log_filter,
envoy::api::v2::filter::AccessLogFilter& access_log_filter) {
envoy::api::v2::filter::http::AccessLogFilter& access_log_filter) {
const std::string type = json_access_log_filter.getString("type");
if (type == "status_code") {
translateStatusCodeFilter(json_access_log_filter,
Expand All @@ -88,8 +89,8 @@ void FilterJson::translateAccessLogFilter(
}

void FilterJson::translateAccessLog(const Json::Object& json_access_log,
envoy::api::v2::filter::AccessLog& access_log) {
envoy::api::v2::filter::FileAccessLog file_access_log;
envoy::api::v2::filter::http::AccessLog& access_log) {
envoy::api::v2::filter::http::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);
Expand All @@ -108,11 +109,11 @@ void FilterJson::translateAccessLog(const Json::Object& json_access_log,

void FilterJson::translateHttpConnectionManager(
const Json::Object& json_http_connection_manager,
envoy::api::v2::filter::HttpConnectionManager& http_connection_manager) {
envoy::api::v2::filter::http::HttpConnectionManager& http_connection_manager) {
json_http_connection_manager.validateSchema(Json::Schema::HTTP_CONN_NETWORK_FILTER_SCHEMA);

envoy::api::v2::filter::HttpConnectionManager::CodecType codec_type{};
envoy::api::v2::filter::HttpConnectionManager::CodecType_Parse(
envoy::api::v2::filter::http::HttpConnectionManager::CodecType codec_type{};
envoy::api::v2::filter::http::HttpConnectionManager::CodecType_Parse(
StringUtil::toUpper(json_http_connection_manager.getString("codec_type")), &codec_type);
http_connection_manager.set_codec_type(codec_type);

Expand Down Expand Up @@ -155,8 +156,8 @@ void FilterJson::translateHttpConnectionManager(
const auto json_tracing = json_http_connection_manager.getObject("tracing");
auto* tracing = http_connection_manager.mutable_tracing();

envoy::api::v2::filter::HttpConnectionManager::Tracing::OperationName operation_name{};
envoy::api::v2::filter::HttpConnectionManager::Tracing::OperationName_Parse(
envoy::api::v2::filter::http::HttpConnectionManager::Tracing::OperationName operation_name{};
envoy::api::v2::filter::http::HttpConnectionManager::Tracing::OperationName_Parse(
StringUtil::toUpper(json_tracing->getString("operation_name")), &operation_name);
tracing->set_operation_name(operation_name);

Expand Down Expand Up @@ -192,8 +193,8 @@ void FilterJson::translateHttpConnectionManager(
JSON_UTIL_SET_BOOL(json_http_connection_manager, http_connection_manager, use_remote_address);
JSON_UTIL_SET_BOOL(json_http_connection_manager, http_connection_manager, generate_request_id);

envoy::api::v2::filter::HttpConnectionManager::ForwardClientCertDetails fcc_details{};
envoy::api::v2::filter::HttpConnectionManager::ForwardClientCertDetails_Parse(
envoy::api::v2::filter::http::HttpConnectionManager::ForwardClientCertDetails fcc_details{};
envoy::api::v2::filter::http::HttpConnectionManager::ForwardClientCertDetails_Parse(
StringUtil::toUpper(
json_http_connection_manager.getString("forward_client_cert", "sanitize")),
&fcc_details);
Expand Down
25 changes: 14 additions & 11 deletions source/common/config/filter_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,41 @@

#include "envoy/json/json_object.h"

#include "api/filter/http_connection_manager.pb.h"
#include "api/filter/http/http_connection_manager.pb.h"

namespace Envoy {
namespace Config {

class FilterJson {
public:
/**
* Translate a v1 JSON access log filter object to v2 envoy::api::v2::filter::AccessLogFilter.
* Translate a v1 JSON access log filter object to v2
* envoy::api::v2::filter::http::AccessLogFilter.
* @param json_access_log_filter source v1 JSON access log object.
* @param access_log_filter destination v2 envoy::api::v2::filter::AccessLog.
* @param access_log_filter destination v2 envoy::api::v2::filter::http::AccessLog.
*/
static void translateAccessLogFilter(const Json::Object& json_access_log_filter,
envoy::api::v2::filter::AccessLogFilter& access_log_filter);
static void
translateAccessLogFilter(const Json::Object& json_access_log_filter,
envoy::api::v2::filter::http::AccessLogFilter& access_log_filter);

/**
* Translate a v1 JSON access log object to v2 envoy::api::v2::filter::AccessLog.
* Translate a v1 JSON access log object to v2 envoy::api::v2::filter::http::AccessLog.
* @param json_access_log source v1 JSON access log object.
* @param access_log destination v2 envoy::api::v2::filter::AccessLog.
* @param access_log destination v2 envoy::api::v2::filter::http::AccessLog.
*/
static void translateAccessLog(const Json::Object& json_access_log,
envoy::api::v2::filter::AccessLog& access_log);
envoy::api::v2::filter::http::AccessLog& access_log);

/**
* Translate a v1 JSON HTTP connection manager object to v2
* envoy::api::v2::filter::HttpConnectionManager.
* envoy::api::v2::filter::http::HttpConnectionManager.
* @param json_http_connection_manager source v1 JSON HTTP connection manager object.
* @param http_connection_manager destination v2 envoy::api::v2::filter::HttpConnectionManager.
* @param http_connection_manager destination v2
* envoy::api::v2::filter::http::HttpConnectionManager.
*/
static void translateHttpConnectionManager(
const Json::Object& json_http_connection_manager,
envoy::api::v2::filter::HttpConnectionManager& http_connection_manager);
envoy::api::v2::filter::http::HttpConnectionManager& http_connection_manager);
};

} // namespace Config
Expand Down
3 changes: 2 additions & 1 deletion source/common/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void Utility::translateCdsConfig(const Json::Object& json_config,
*cds_config.mutable_api_config_source());
}

void Utility::translateRdsConfig(const Json::Object& json_rds, envoy::api::v2::filter::Rds& rds) {
void Utility::translateRdsConfig(const Json::Object& json_rds,
envoy::api::v2::filter::http::Rds& rds) {
json_rds.validateSchema(Json::Schema::RDS_CONFIGURATION_SCHEMA);

const std::string name = json_rds.getString("route_config_name", "");
Expand Down
9 changes: 5 additions & 4 deletions source/common/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "api/base.pb.h"
#include "api/cds.pb.h"
#include "api/eds.pb.h"
#include "api/filter/http_connection_manager.pb.h"
#include "api/filter/http/http_connection_manager.pb.h"
#include "api/lds.pb.h"
#include "api/rds.pb.h"

Expand Down Expand Up @@ -134,11 +134,12 @@ class Utility {
envoy::api::v2::ConfigSource& cds_config);

/**
* Convert a v1 RDS JSON config to v2 RDS envoy::api::v2::filter::Rds.
* Convert a v1 RDS JSON config to v2 RDS envoy::api::v2::filter::http::Rds.
* @param json_rds source v1 RDS JSON config.
* @param rds destination v2 RDS envoy::api::v2::filter::Rds.
* @param rds destination v2 RDS envoy::api::v2::filter::http::Rds.
*/
static void translateRdsConfig(const Json::Object& json_rds, envoy::api::v2::filter::Rds& rds);
static void translateRdsConfig(const Json::Object& json_rds,
envoy::api::v2::filter::http::Rds& rds);

/**
* Convert a v1 LDS JSON config to v2 LDS envoy::api::v2::ConfigSource.
Expand Down
33 changes: 17 additions & 16 deletions source/common/http/access_log/access_log_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Envoy {
namespace Http {
namespace AccessLog {

ComparisonFilter::ComparisonFilter(const envoy::api::v2::filter::ComparisonFilter& config,
ComparisonFilter::ComparisonFilter(const envoy::api::v2::filter::http::ComparisonFilter& config,
Runtime::Loader& runtime)
: config_(config), runtime_(runtime) {}

Expand All @@ -34,31 +34,31 @@ bool ComparisonFilter::compareAgainstValue(uint64_t lhs) {
}

switch (config_.op()) {
case envoy::api::v2::filter::ComparisonFilter::GE:
case envoy::api::v2::filter::http::ComparisonFilter::GE:
return lhs >= value;
case envoy::api::v2::filter::ComparisonFilter::EQ:
case envoy::api::v2::filter::http::ComparisonFilter::EQ:
return lhs == value;
default:
NOT_REACHED;
}
}

FilterPtr FilterFactory::fromProto(const envoy::api::v2::filter::AccessLogFilter& config,
FilterPtr FilterFactory::fromProto(const envoy::api::v2::filter::http::AccessLogFilter& config,
Runtime::Loader& runtime) {
switch (config.filter_specifier_case()) {
case envoy::api::v2::filter::AccessLogFilter::kStatusCodeFilter:
case envoy::api::v2::filter::http::AccessLogFilter::kStatusCodeFilter:
return FilterPtr{new StatusCodeFilter(config.status_code_filter(), runtime)};
case envoy::api::v2::filter::AccessLogFilter::kDurationFilter:
case envoy::api::v2::filter::http::AccessLogFilter::kDurationFilter:
return FilterPtr{new DurationFilter(config.duration_filter(), runtime)};
case envoy::api::v2::filter::AccessLogFilter::kNotHealthCheckFilter:
case envoy::api::v2::filter::http::AccessLogFilter::kNotHealthCheckFilter:
return FilterPtr{new NotHealthCheckFilter()};
case envoy::api::v2::filter::AccessLogFilter::kTraceableFilter:
case envoy::api::v2::filter::http::AccessLogFilter::kTraceableFilter:
return FilterPtr{new TraceableRequestFilter()};
case envoy::api::v2::filter::AccessLogFilter::kRuntimeFilter:
case envoy::api::v2::filter::http::AccessLogFilter::kRuntimeFilter:
return FilterPtr{new RuntimeFilter(config.runtime_filter(), runtime)};
case envoy::api::v2::filter::AccessLogFilter::kAndFilter:
case envoy::api::v2::filter::http::AccessLogFilter::kAndFilter:
return FilterPtr{new AndFilter(config.and_filter(), runtime)};
case envoy::api::v2::filter::AccessLogFilter::kOrFilter:
case envoy::api::v2::filter::http::AccessLogFilter::kOrFilter:
return FilterPtr{new OrFilter(config.or_filter(), runtime)};
default:
NOT_REACHED;
Expand All @@ -84,7 +84,7 @@ bool DurationFilter::evaluate(const RequestInfo& info, const HeaderMap&) {
std::chrono::duration_cast<std::chrono::milliseconds>(info.duration()).count());
}

RuntimeFilter::RuntimeFilter(const envoy::api::v2::filter::RuntimeFilter& config,
RuntimeFilter::RuntimeFilter(const envoy::api::v2::filter::http::RuntimeFilter& config,
Runtime::Loader& runtime)
: runtime_(runtime), runtime_key_(config.runtime_key()) {}

Expand All @@ -102,17 +102,18 @@ bool RuntimeFilter::evaluate(const RequestInfo&, const HeaderMap& request_header
}

OperatorFilter::OperatorFilter(
const Protobuf::RepeatedPtrField<envoy::api::v2::filter::AccessLogFilter>& configs,
const Protobuf::RepeatedPtrField<envoy::api::v2::filter::http::AccessLogFilter>& configs,
Runtime::Loader& runtime) {
for (const auto& config : configs) {
filters_.emplace_back(FilterFactory::fromProto(config, runtime));
}
}

OrFilter::OrFilter(const envoy::api::v2::filter::OrFilter& config, Runtime::Loader& runtime)
OrFilter::OrFilter(const envoy::api::v2::filter::http::OrFilter& config, Runtime::Loader& runtime)
: OperatorFilter(config.filters(), runtime) {}

AndFilter::AndFilter(const envoy::api::v2::filter::AndFilter& config, Runtime::Loader& runtime)
AndFilter::AndFilter(const envoy::api::v2::filter::http::AndFilter& config,
Runtime::Loader& runtime)
: OperatorFilter(config.filters(), runtime) {}

bool OrFilter::evaluate(const RequestInfo& info, const HeaderMap& request_headers) {
Expand Down Expand Up @@ -145,7 +146,7 @@ bool NotHealthCheckFilter::evaluate(const RequestInfo& info, const HeaderMap&) {
return !info.healthCheck();
}

InstanceSharedPtr AccessLogFactory::fromProto(const envoy::api::v2::filter::AccessLog& config,
InstanceSharedPtr AccessLogFactory::fromProto(const envoy::api::v2::filter::http::AccessLog& config,
Server::Configuration::FactoryContext& context) {
FilterPtr filter;
if (config.has_filter()) {
Expand Down
Loading

0 comments on commit 747fe8d

Please sign in to comment.