Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate health check filter to v2 api #2047

Merged
merged 71 commits into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
d179e90
Allow non ws requests on WS route
Oct 2, 2017
6e84e55
More tests for WebSockets
Oct 3, 2017
2cedf44
Fix test for Non WS on WS route
Oct 3, 2017
84f2aab
Merge remote-tracking branch 'upstream/master'
Oct 3, 2017
37af80d
fix
Oct 3, 2017
1645eaf
connect timeout test
Oct 3, 2017
928272d
format
Oct 3, 2017
6ee6657
fix timeout test
Oct 3, 2017
d7a4188
Merge remote-tracking branch 'upstream/master'
Oct 3, 2017
8599956
formatting
Oct 3, 2017
d2a10c2
Merge remote-tracking branch 'upstream/master'
Oct 4, 2017
75ef074
fix auto host rewrite check
Oct 4, 2017
baf1ee1
compile fix
Oct 4, 2017
dd4b8aa
connectionfailure test
Oct 4, 2017
c9a9fa4
update docs
Oct 4, 2017
dce2ce1
Merge remote-tracking branch 'upstream/master'
Oct 13, 2017
cd70037
Merge remote-tracking branch 'upstream/master'
Oct 16, 2017
659e793
configurable cluster name length
Oct 16, 2017
b51a666
formatting
Oct 16, 2017
9d0366e
Merge remote-tracking branch 'upstream/master'
Oct 16, 2017
a724473
Merge remote-tracking branch 'upstream/master'
Oct 16, 2017
c5d6e8f
remove CLI option
Oct 17, 2017
644b05c
Merge remote-tracking branch 'upstream/master'
Oct 17, 2017
d6caed2
fix
Oct 17, 2017
3092c06
rds/lds/cds tests
Oct 17, 2017
0fd0ba7
Merge remote-tracking branch 'upstream/master'
Oct 17, 2017
03c9b31
rename var
Oct 17, 2017
7a9e602
format
Oct 17, 2017
9ae3160
change CLI option name
Oct 17, 2017
98518c0
Merge remote-tracking branch 'upstream/master'
Oct 17, 2017
503eecf
feedback
Oct 17, 2017
aad79de
sweeping renames
Oct 17, 2017
2925163
fix
Oct 17, 2017
4507c10
test fix
Oct 17, 2017
2527ed1
Merge remote-tracking branch 'upstream/master'
Oct 17, 2017
cae08f0
long string to fix hot_restart_test
Oct 17, 2017
5afd3ba
remove stray comment
Oct 17, 2017
d4de240
docs and nits
Oct 18, 2017
65debb2
max len limit for vhosts
Oct 18, 2017
fa2d91b
review comments
Oct 18, 2017
9ec016c
nits
Oct 18, 2017
e9b0dce
Merge remote-tracking branch 'upstream/master'
Oct 18, 2017
b534be9
Merge remote-tracking branch 'upstream/master'
Oct 18, 2017
d9f3814
Merge remote-tracking branch 'upstream/master'
Oct 25, 2017
f9fc5e1
Merge remote-tracking branch 'upstream/master'
Oct 26, 2017
4cd58b8
Merge remote-tracking branch 'upstream/master'
Oct 31, 2017
e09ea3e
Merge remote-tracking branch 'upstream/master'
Nov 1, 2017
9d27e97
Merge remote-tracking branch 'upstream/master'
Nov 2, 2017
59bdb58
Merge remote-tracking branch 'upstream/master'
Nov 3, 2017
13a8af5
Merge remote-tracking branch 'upstream/master'
Nov 3, 2017
3eab89f
Merge remote-tracking branch 'upstream/master'
Nov 7, 2017
de6e6f6
Merge branch 'master' of https://github.com/amalgam8/envoy
Nov 10, 2017
bc8cff2
Merge remote-tracking branch 'upstream/master'
Nov 10, 2017
7063364
buffer filter v2
Nov 10, 2017
247518f
format
Nov 10, 2017
df39693
includes
Nov 10, 2017
ef80354
compile fix
Nov 10, 2017
170140a
health check filter - v2
Nov 10, 2017
38fb9a6
nits
Nov 10, 2017
3e7ce47
Merge branch 'buffer_v2' into healthcheck_v2
Nov 10, 2017
4dcc0b9
compile fixes
Nov 10, 2017
a1b9ad0
duration cast
Nov 10, 2017
0cdf136
Merge branch 'buffer_v2' into healthcheck_v2
Nov 10, 2017
9dffdee
new utility macro
Nov 10, 2017
d4d248a
Merge branch 'buffer_v2' into healthcheck_v2
Nov 10, 2017
0dbda03
lint
Nov 10, 2017
5dddde7
compile fixes
Nov 10, 2017
e8de97c
really fix compiler errors
Nov 10, 2017
efc4453
Merge branch 'master' of https://github.com/lyft/envoy into healthche…
Nov 10, 2017
0f1e307
format fix
Nov 10, 2017
1ee768f
json_util_set_bool
Nov 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/common/config/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ envoy_cc_library(
"envoy_filter_http_http_connection_manager",
"envoy_filter_http_buffer",
"envoy_filter_http_fault",
"envoy_filter_http_health_check",
"envoy_filter_http_router",
"envoy_filter_network_mongo_proxy",
],
Expand Down
11 changes: 11 additions & 0 deletions source/common/config/filter_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ void FilterJson::translateFaultFilter(const Json::Object& json_fault,
}
}

void FilterJson::translateHealthCheckFilter(
const Json::Object& json_health_check,
envoy::api::v2::filter::http::HealthCheck& health_check) {
json_health_check.validateSchema(Json::Schema::HEALTH_CHECK_HTTP_FILTER_SCHEMA);

health_check.mutable_pass_through_mode()->set_value(
Copy link
Member

Choose a reason for hiding this comment

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

JSON_UTIL_SET_BOOL

json_health_check.getBoolean("pass_through_mode"));
JSON_UTIL_SET_DURATION(json_health_check, health_check, cache_time);
JSON_UTIL_SET_STRING(json_health_check, health_check, endpoint);
}

void FilterJson::translateRouter(const Json::Object& json_router,
envoy::api::v2::filter::http::Router& router) {
json_router.validateSchema(Json::Schema::ROUTER_HTTP_FILTER_SCHEMA);
Expand Down
10 changes: 10 additions & 0 deletions source/common/config/filter_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "api/filter/http/buffer.pb.h"
#include "api/filter/http/fault.pb.h"
#include "api/filter/http/health_check.pb.h"
#include "api/filter/http/http_connection_manager.pb.h"
#include "api/filter/http/router.pb.h"
#include "api/filter/network/mongo_proxy.pb.h"
Expand Down Expand Up @@ -59,6 +60,15 @@ class FilterJson {
static void translateFaultFilter(const Json::Object& json_fault,
envoy::api::v2::filter::http::HTTPFault& fault);

/**
* Translate a v1 JSON Health Check filter object to v2 envoy::api::v2::filter::http::HealthCheck.
* @param config source v1 JSON Health Check Filter object.
* @param health_check destination v2
* envoy::api::v2::filter::http::HealthCheck.
*/
static void translateHealthCheckFilter(const Json::Object& config,
envoy::api::v2::filter::http::HealthCheck& health_check);

/*
* Translate a v1 JSON Router object to v2 envoy::api::v2::filter::http::Router.
* @param json_router source v1 JSON HTTP router object.
Expand Down
6 changes: 4 additions & 2 deletions source/server/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ envoy_cc_library(
name = "health_check_lib",
srcs = ["health_check.cc"],
hdrs = ["health_check.h"],
external_deps = ["envoy_filter_http_health_check"],
deps = [
"//include/envoy/event:dispatcher_interface",
"//include/envoy/event:timer_interface",
Expand All @@ -60,12 +61,13 @@ envoy_cc_library(
"//include/envoy/http:header_map_interface",
"//source/common/common:assert_lib",
"//source/common/common:enum_to_int",
"//source/common/config:filter_json_lib",
"//source/common/config:well_known_names",
"//source/common/http:codes_lib",
"//source/common/http:header_map_lib",
"//source/common/http:headers_lib",
"//source/common/http:utility_lib",
"//source/common/json:config_schemas_lib",
"//source/common/json:json_loader_lib",
"//source/common/protobuf:utility_lib",
"//source/server/config/network:http_connection_manager_lib",
],
)
40 changes: 28 additions & 12 deletions source/server/http/health_check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,30 @@
#include "envoy/http/header_map.h"
#include "envoy/registry/registry.h"

#include "common/config/filter_json.h"
#include "common/common/assert.h"
#include "common/common/enum_to_int.h"
#include "common/http/codes.h"
#include "common/http/header_map_impl.h"
#include "common/http/headers.h"
#include "common/http/utility.h"
#include "common/json/config_schemas.h"
#include "common/json/json_loader.h"
#include "common/protobuf/utility.h"

#include "server/config/network/http_connection_manager.h"

namespace Envoy {
namespace Server {
namespace Configuration {

/**
* Config registration for the health check filter. @see NamedHttpFilterConfigFactory.
*/
HttpFilterFactoryCb HealthCheckFilterConfig::createFilterFactory(const Json::Object& config,
const std::string&,
FactoryContext& context) {
config.validateSchema(Json::Schema::HEALTH_CHECK_HTTP_FILTER_SCHEMA);
HttpFilterFactoryCb HealthCheckFilterConfig::createHealthCheckFilter(
const envoy::api::v2::filter::http::HealthCheck& health_check, const std::string&,
FactoryContext& context) {
ASSERT(health_check.has_pass_through_mode());
ASSERT(!health_check.endpoint().empty());

bool pass_through_mode = config.getBoolean("pass_through_mode");
int64_t cache_time_ms = config.getInteger("cache_time_ms", 0);
std::string hc_endpoint = config.getString("endpoint");
bool pass_through_mode = health_check.pass_through_mode().value();
Copy link
Member

Choose a reason for hiding this comment

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

sorry as long as you are in here can you make these all const?

Copy link
Member

Choose a reason for hiding this comment

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

That's fine we can just merge this and can fix in a follow up.

int64_t cache_time_ms = PROTOBUF_GET_MS_OR_DEFAULT(health_check, cache_time, 0);
std::string hc_endpoint = health_check.endpoint();

if (!pass_through_mode && cache_time_ms) {
throw EnvoyException("cache_time_ms must not be set when path_through_mode is disabled");
Expand All @@ -52,6 +50,24 @@ HttpFilterFactoryCb HealthCheckFilterConfig::createFilterFactory(const Json::Obj
};
}

/**
* Config registration for the health check filter. @see NamedHttpFilterConfigFactory.
*/
HttpFilterFactoryCb HealthCheckFilterConfig::createFilterFactory(const Json::Object& json_config,
const std::string& stats_prefix,
FactoryContext& context) {
envoy::api::v2::filter::http::HealthCheck health_check;
Config::FilterJson::translateHealthCheckFilter(json_config, health_check);
return createHealthCheckFilter(health_check, stats_prefix, context);
}

HttpFilterFactoryCb HealthCheckFilterConfig::createFilterFactoryFromProto(
const Protobuf::Message& config, const std::string& stats_prefix, FactoryContext& context) {
return createHealthCheckFilter(
dynamic_cast<const envoy::api::v2::filter::http::HealthCheck&>(config), stats_prefix,
context);
}

/**
* Static registration for the health check filter. @see RegisterFactory.
*/
Expand Down
19 changes: 18 additions & 1 deletion source/server/http/health_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "envoy/http/filter.h"
#include "envoy/server/filter_config.h"

#include "common/config/well_known_names.h"

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

namespace Envoy {
namespace Server {
namespace Configuration {
Expand All @@ -17,7 +21,20 @@ class HealthCheckFilterConfig : public NamedHttpFilterConfigFactory {
public:
HttpFilterFactoryCb createFilterFactory(const Json::Object& config, const std::string&,
FactoryContext& context) override;
std::string name() override { return "envoy.health_check"; }
HttpFilterFactoryCb createFilterFactoryFromProto(const Protobuf::Message& config,
const std::string& stats_prefix,
FactoryContext& context) override;

ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return ProtobufTypes::MessagePtr{new envoy::api::v2::filter::http::HealthCheck()};
}

std::string name() override { return Config::HttpFilterNames::get().HEALTH_CHECK; }

private:
HttpFilterFactoryCb
createHealthCheckFilter(const envoy::api::v2::filter::http::HealthCheck& health_check,
const std::string& stats_prefix, FactoryContext& context);
};

} // namespace Configuration
Expand Down
40 changes: 38 additions & 2 deletions test/server/http/health_check_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ TEST_F(HealthCheckFilterCachingTest, NotHcRequest) {
filter_->decodeHeaders(request_headers_no_hc_, true));
}

TEST(HealthCheckFilterConfig, failsWhenNotPassThroughButTimeoutSet) {
TEST(HealthCheckFilterConfig, failsWhenNotPassThroughButTimeoutSetJson) {
Server::Configuration::HealthCheckFilterConfig healthCheckFilterConfig;
Json::ObjectSharedPtr config = Json::Factory::loadFromString(
"{\"pass_through_mode\":false, \"cache_time_ms\":234, \"endpoint\":\"foo\"}");
Expand All @@ -218,12 +218,48 @@ TEST(HealthCheckFilterConfig, failsWhenNotPassThroughButTimeoutSet) {
EnvoyException);
}

TEST(HealthCheckFilterConfig, notFailingWhenNotPassThroughAndTimeoutNotSet) {
TEST(HealthCheckFilterConfig, notFailingWhenNotPassThroughAndTimeoutNotSetJson) {
Server::Configuration::HealthCheckFilterConfig healthCheckFilterConfig;
Json::ObjectSharedPtr config =
Json::Factory::loadFromString("{\"pass_through_mode\":false, \"endpoint\":\"foo\"}");
NiceMock<Server::Configuration::MockFactoryContext> context;

healthCheckFilterConfig.createFilterFactory(*config, "dummy_stats_prefix", context);
}

TEST(HealthCheckFilterConfig, failsWhenNotPassThroughButTimeoutSetProto) {
Server::Configuration::HealthCheckFilterConfig healthCheckFilterConfig;
envoy::api::v2::filter::http::HealthCheck config{};
NiceMock<Server::Configuration::MockFactoryContext> context;

config.mutable_pass_through_mode()->set_value(false);
config.set_endpoint("foo");
config.mutable_cache_time()->set_seconds(10);

EXPECT_THROW(
healthCheckFilterConfig.createFilterFactoryFromProto(config, "dummy_stats_prefix", context),
EnvoyException);
}

TEST(HealthCheckFilterConfig, notFailingWhenNotPassThroughAndTimeoutNotSetProto) {
Server::Configuration::HealthCheckFilterConfig healthCheckFilterConfig;
envoy::api::v2::filter::http::HealthCheck config{};
NiceMock<Server::Configuration::MockFactoryContext> context;

config.mutable_pass_through_mode()->set_value(false);
config.set_endpoint("foo");
healthCheckFilterConfig.createFilterFactoryFromProto(config, "dummy_stats_prefix", context);
}

TEST(HealthCheckFilterConfig, HealthCheckFilterWithEmptyProto) {
Server::Configuration::HealthCheckFilterConfig healthCheckFilterConfig;
NiceMock<Server::Configuration::MockFactoryContext> context;
envoy::api::v2::filter::http::HealthCheck config =
*dynamic_cast<envoy::api::v2::filter::http::HealthCheck*>(
healthCheckFilterConfig.createEmptyConfigProto().get());

config.mutable_pass_through_mode()->set_value(false);
config.set_endpoint("foo");
healthCheckFilterConfig.createFilterFactoryFromProto(config, "dummy_stats_prefix", context);
}
} // namespace Envoy