Skip to content

config: remove redundant checks and add schema tests#715

Merged
mattklein123 merged 14 commits intomasterfrom
schema-redundant-cleanup
Apr 18, 2017
Merged

config: remove redundant checks and add schema tests#715
mattklein123 merged 14 commits intomasterfrom
schema-redundant-cleanup

Conversation

@danielhochman
Copy link
Copy Markdown
Contributor

@danielhochman danielhochman commented Apr 6, 2017

JSON Schema validation obviates the need for many of the configuration checks we were previously doing in code.

Fixes #454

TODO:

  • replace deleted tests with schema tests for same condition

@mattklein123
Copy link
Copy Markdown
Member

@ccaraman can do the review, but 2 high level comments:

  1. I'm not sure I would delete the tests. They still provide schema coverage, even if it's not explicit.
  2. You probably already did this, but make sure you take a look at the coverage build to see if there is anything missing that should also be removed or tested.

throw EnvoyException(fmt::format("unknown rate limit service type '{}'", type));
}
ASSERT(type == "grpc_service");
ratelimit_client_factory_.reset(new RateLimit::GrpcFactoryImpl(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You'll most likely get the unused param for type. add UNREFERENCED_PARAMETER

ASSERT(type == "grpc_service");
ratelimit_client_factory_.reset(new RateLimit::GrpcFactoryImpl(
*rate_limit_service_config->getObject("config"), *cluster_manager_));

Copy link
Copy Markdown
Contributor

@ccaraman ccaraman Apr 7, 2017

Choose a reason for hiding this comment

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

nit:no new line

}
} else {
throw EnvoyException(fmt::format("Filter list cannot be empty in OperatorFilter"));
for (Json::ObjectPtr& filter : filters) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_));
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.

you also need to fix line "throw EnvoyException(fmt::format("unsupported driver type: '{}'", type));" down below.

@RomanDzhabarov
Copy link
Copy Markdown
Member

RomanDzhabarov commented Apr 10, 2017

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
if not we need to clean up

const Json::ObjectPtr config_delay = json_config.getObject("delay", true);

if (abort->empty() && delay->empty()) {
if (config_abort->empty() && config_delay->empty()) {
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.

i think, we can get rid of this condition if we say oneOf for "abort" or "delay" in the json schema.

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.

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");
     }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@danielhochman
Copy link
Copy Markdown
Contributor Author

danielhochman commented Apr 10, 2017

@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

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

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'],
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.

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
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.

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() {
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.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

if (json->getBoolean("throws", false)) {
EXPECT_THROW(json->getObject("data")->validateSchema(schema), Exception);
} else {
json->getObject("data")->validateSchema(schema);
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.

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.

@danielhochman danielhochman changed the title remove redundant configuration checks config: remove redundant checks and add schema tests Apr 18, 2017
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

this is awesome, thanks. 2 small nits.

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)) {
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.

const std::string&

@@ -0,0 +1,24 @@

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.

extra new line

@mattklein123 mattklein123 merged commit 523f091 into master Apr 18, 2017
@mattklein123 mattklein123 deleted the schema-redundant-cleanup branch April 18, 2017 22:33
rshriram pushed a commit to rshriram/envoy that referenced this pull request Oct 30, 2018
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
```
jpsim pushed a commit that referenced this pull request Nov 28, 2022
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>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants