config: remove redundant checks and add schema tests#715
config: remove redundant checks and add schema tests#715mattklein123 merged 14 commits intomasterfrom
Conversation
|
@ccaraman can do the review, but 2 high level comments:
|
| throw EnvoyException(fmt::format("unknown rate limit service type '{}'", type)); | ||
| } | ||
| ASSERT(type == "grpc_service"); | ||
| ratelimit_client_factory_.reset(new RateLimit::GrpcFactoryImpl( |
There was a problem hiding this comment.
You'll most likely get the unused param for type. add UNREFERENCED_PARAMETER
source/server/configuration_impl.cc
Outdated
| ASSERT(type == "grpc_service"); | ||
| ratelimit_client_factory_.reset(new RateLimit::GrpcFactoryImpl( | ||
| *rate_limit_service_config->getObject("config"), *cluster_manager_)); | ||
|
|
| } | ||
| } else { | ||
| throw EnvoyException(fmt::format("Filter list cannot be empty in OperatorFilter")); | ||
| for (Json::ObjectPtr& filter : filters) { |
There was a problem hiding this comment.
nit: this can be done in one line with getObjectArray
| } | ||
| ASSERT(type == "grpc_service"); | ||
| ratelimit_client_factory_.reset(new RateLimit::GrpcFactoryImpl( | ||
| *rate_limit_service_config->getObject("config"), *cluster_manager_)); |
There was a problem hiding this comment.
you also need to fix line "throw EnvoyException(fmt::format("unsupported driver type: '{}'", type));" down below.
|
With the schema introduction and ipv4/ipv6 format, is this still possible? https://github.com/lyft/envoy/blob/cec2bdfbe86870f654ac8697d0042a120e827e3e/source/common/network/utility.cc#L18 |
| const Json::ObjectPtr config_delay = json_config.getObject("delay", true); | ||
|
|
||
| if (abort->empty() && delay->empty()) { | ||
| if (config_abort->empty() && config_delay->empty()) { |
There was a problem hiding this comment.
i think, we can get rid of this condition if we say oneOf for "abort" or "delay" in the json schema.
There was a problem hiding this comment.
potentially same thing with the route rules, where it's either prefix or path needs to be supplied:
bool has_prefix = route->hasObject("prefix");
bool has_path = route->hasObject("path");
if (!(has_prefix ^ has_path)) {
throw EnvoyException("routes must specify either prefix or path");
}
There was a problem hiding this comment.
yeah, that should work for abort or delay case. don't think that it will work for the route rules since there are two xor keys among a lot of other keys.
There was a problem hiding this comment.
actually there are other keys on the same level for abort and delay as well. so i don't think we can use the schema to validate this condition.
|
@RomanDzhabarov i looked at the ipv4 validator previously and from what i can tell it won't understand the mask portion, just dot-quad got it, thanks for checking |
mattklein123
left a comment
There was a problem hiding this comment.
very cool. Mainly comments around docs and maintainability.
|
|
||
| def write_test_file(name, schema, data, throws): | ||
| test_filename = os.path.join( | ||
| os.environ['TEST_TMPDIR'], |
There was a problem hiding this comment.
To avoid clashing in the coverage test, can we use a subdir of TEST_TMPDIR. E.g., ${TEST_TMPDIR}/json_schema_test.
| @@ -0,0 +1,339 @@ | |||
| #!/usr/bin/env python | |||
There was a problem hiding this comment.
This file is going to get huge and hard to maintain. At minimum, can we add comments for folks on best practices on adding a new schema test (best would be comments in here and some type of README.me). Better I think would be to break this program into multiple Python files.
|
|
||
| namespace Json { | ||
|
|
||
| std::vector<std::string> generateTestInputs() { |
There was a problem hiding this comment.
This is basically the same code that is used in example_config_tests. It might be worth it to factor it out so that we can use it in both places (basically func to return a list of JSON that can be fed into TEST_P).
| if (json->getBoolean("throws", false)) { | ||
| EXPECT_THROW(json->getObject("data")->validateSchema(schema), Exception); | ||
| } else { | ||
| json->getObject("data")->validateSchema(schema); |
There was a problem hiding this comment.
I might try/catch here, catch exception, fail, and then print some info about what failed (which test file, etc.), since I think it's going to be almost impossible to figure it out if something starts failing.
mattklein123
left a comment
There was a problem hiding this comment.
this is awesome, thanks. 2 small nits.
test/config_test/config_test.cc
Outdated
| Logger::Registry::getLog(Logger::Id::testing).info("testing config: {}", file_name); | ||
| ConfigTest config(file_name); | ||
| uint32_t num_tested = 0; | ||
| for (std::string filename : TestUtility::listFiles(directory, true)) { |
| @@ -0,0 +1,24 @@ | |||
|
|
|||
Automatic merge from submit-queue. [DO NOT MERGE] Auto PR to update dependencies of proxy This PR will be merged automatically once checks are successful. ```release-note none ```
Description: updates envoy ref to include #10137. Exposes client builder function to add dns failure refresh rate. Risk Level: low, new configuration option Testing: local apps, CI Docs Changes: created #715 to create a section in the docs for all the builder options. Fixes #673 Signed-off-by: JP Simard <jp@jpsim.com>
Description: updates envoy ref to include #10137. Exposes client builder function to add dns failure refresh rate. Risk Level: low, new configuration option Testing: local apps, CI Docs Changes: created #715 to create a section in the docs for all the builder options. Fixes #673 Signed-off-by: JP Simard <jp@jpsim.com>
JSON Schema validation obviates the need for many of the configuration checks we were previously doing in code.
Fixes #454
TODO: