Skip to content

pgv: validation support for Bootstrap/xDS/filters.#2146

Merged
htuch merged 9 commits intoenvoyproxy:masterfrom
htuch:pgv-bootstrap-xds
Dec 4, 2017
Merged

pgv: validation support for Bootstrap/xDS/filters.#2146
htuch merged 9 commits intoenvoyproxy:masterfrom
htuch:pgv-bootstrap-xds

Conversation

@htuch
Copy link
Member

@htuch htuch commented Dec 1, 2017

This patch lands checking via https://github.com/lyft/protoc-gen-validate in Envoy for bootstrap, xDS ingestion and during filter instantiation.

Risk Level: Medium (things might start blowing up on config ingestion that were slipping through before).
Testing: Mostly negative tests for bootstrap/xDS/filters, since the happy path is already validated through the existing test suite.

Signed-off-by: Harvey Tuch htuch@google.com

@htuch
Copy link
Member Author

htuch commented Dec 1, 2017

@akonradi @mattklein123 (also @rodaine FYI) if we can agree on this approach, I can flesh out the PR.

@mattklein123
Copy link
Member

I really wish there was a way to generically call Validate() on the base class. It would be so much cleaner. Barring that, I think this is the best we can do. LGTM.

@akonradi
Copy link
Contributor

akonradi commented Dec 1, 2017

I'm okay with the general approach here but I'll defer to @mattklein123 and others' stylistic preferences.

@htuch
Copy link
Member Author

htuch commented Dec 1, 2017

@mattklein123 I will bring this up when we meet with the protobuf team. For 1.5, this is the way it has to be I believe.

Copy link
Member

Choose a reason for hiding this comment

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

looks like this leaked in

* Bootstrap and xDS APIs implemented with negative tests. There is a known issue with recursive
  validation of repeated messages in PGV that needs to be fixed before we can enable ValidateFail in
  rds_impl_test. Positive tests not required, since this is exercised by all tests that aren't
  failing.

* Added validation support of filters and negative tests (where applicable).

Signed-off-by: Harvey Tuch <htuch@google.com>
@htuch htuch force-pushed the pgv-bootstrap-xds branch from a399eb7 to c01919e Compare December 1, 2017 22:56
@htuch htuch changed the title [RFC] pgv: validation support for Bootstrap/xDS/filters. pgv: validation support for Bootstrap/xDS/filters. Dec 1, 2017
@htuch
Copy link
Member Author

htuch commented Dec 1, 2017

This is ready for review.

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

Sweet. Few random comments and needs merge.

try {
validate(message);
} catch (const EnvoyException&) {
message.Clear();
Copy link
Member

Choose a reason for hiding this comment

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

what's the reasoning behind clearing here? We don't do it in the other functions where we validate. Just because we also loaded here so we own the whole thing? Maybe comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it had to do with some later code that depended on this being clear on failure in server init. TBH, that's an anti-pattern, I will fix that code instead.

Json::ObjectSharedPtr config = Json::Factory::loadFromString(config_json);
envoy::api::v2::filter::network::Rds rds;
Envoy::Config::Utility::translateRdsConfig(*config, rds);
// Negative test for protoc-gen-validate constraints.
Copy link
Member

Choose a reason for hiding this comment

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

Worth leaving this code for now? Or just delete and add TODO up above? I'm fine either way. Maybe also link to issue tracking this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Coverage is broken until some recent PGV fixups make their way across to data-plane-api. Need to merge https://github.com/lyft/protoc-gen-validate/pull/40 first though. So, will wait until that all happens, then this test should work for real.

Protobuf::RepeatedPtrField<envoy::api::v2::Cluster> clusters;
clusters.Add();

EXPECT_THROW(dynamic_cast<CdsApiImpl*>(cds_.get())->onConfigUpdate(clusters),
Copy link
Member

Choose a reason for hiding this comment

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

EXPECT_THROW_WITH_MESSAGE? Maybe not convenient because exception contains entire debug string? Same elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will get a bit fragile, since the current errors thrown by PGV are not very pretty, so will probably be evolved. This is why I added ProtoValidationException in this PR, so we can at least sure that these are PGV errors.

Copy link
Member

Choose a reason for hiding this comment

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

OK sounds good.

htuch added 7 commits December 4, 2017 15:02
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
Signed-off-by: Harvey Tuch <htuch@google.com>
@htuch
Copy link
Member Author

htuch commented Dec 4, 2017

@mattklein123 @akonradi ready for final review, PGV works really well (thanks @akonradi @rodaine!).

Copy link
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 super amazing!!! Thanks @htuch @akonradi @rodaine! One small nit.

const Protobuf::Message& message)
: EnvoyException(fmt::format("Proto constraint validation failed ({}): {}", validation_error,
message.DebugString())) {
ENVOY_LOG_MISC(debug, "Throwing {}", what());
Copy link
Member

Choose a reason for hiding this comment

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

nit: kind of a strange debug message: "Proto validation error. Throwing ..." ?

Signed-off-by: Harvey Tuch <htuch@google.com>
@htuch htuch merged commit 9ed6292 into envoyproxy:master Dec 4, 2017
@htuch htuch deleted the pgv-bootstrap-xds branch December 4, 2017 23:24
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
* API sha for proxy

* API sha for proxy
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Updates to the latest version of Envoy upstream

Fixes a flaky stats test that got worse with the bump
Forces the registration of the new client channel factory extension that is part of core
Implements a new method for the synthetic address

Signed-off-by: Snow Pettersen <snowp@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Updates to the latest version of Envoy upstream

Fixes a flaky stats test that got worse with the bump
Forces the registration of the new client channel factory extension that is part of core
Implements a new method for the synthetic address

Signed-off-by: Snow Pettersen <snowp@lyft.com>
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