Skip to content

Allow http route and cluster metadata to contain typed metadata in An…#16107

Merged
yanavlasov merged 22 commits intoenvoyproxy:mainfrom
yanjunxiang-google:metadata_proto
May 18, 2021
Merged

Allow http route and cluster metadata to contain typed metadata in An…#16107
yanavlasov merged 22 commits intoenvoyproxy:mainfrom
yanjunxiang-google:metadata_proto

Conversation

@yanjunxiang-google
Copy link
Copy Markdown
Contributor

@yanjunxiang-google yanjunxiang-google commented Apr 21, 2021

Problem Description:
This PR is to address issue #13986: Allow http route and cluster metadata to contain typed metadata in Any in addition to Struct format.

Solution:

  1. Add google.protobuf.Any field in metadata proto.
  2. Put google.protobuf.Struct field in metadata proto as deprecated.
  3. Add a pure virtual parse() method for Any data in TypedMetadataFactory.
  4. Override the pure parse() method for Any in config_impl_test.cc and upstream_impl_test.cc.
  5. Modify populateFrom() method in TypedMetadataImpl() class to parse both Struct and Any data. The logic is:
    search and parse Any data first for that factory for a metadata. If Any data doesn't exist or Any parse() return nullptr, fallback to search and parse Struct data. Note if there are both Struct and Any data in a metadata but with different factory, both will be parsed and pouplated.
  6. Below unit test code to test the populateFrom() logic are added in metadata_test.cc:
    Created three different factories for testing above code change, and testing below cases
    6.1) no data in metadata
    6.2) only Struct in metadata
    6.3) only Any in in metadata
    6.4) both Struct and Any in metadata in the same factory
    6.5) both Struct and Any in metadata in the different factory
    6.6) both Struct and Any in metadata in the same factory but parse() method for Any just return nullptr.

and some other unit test to test data update, delete, and exception handling.

Testing:
The code change passed bazel test.

Release Notes:
N/A

Issues: Allow http route and cluster metadata to contain typed metadata in Any in addition to Struct format #13986

Fix #13986

Signed-off-by: Yanjun Xiang yanjunxiang@google.com

For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md

Commit Message:
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]
[Optional API Considerations:]

…y in addition to Struct format envoyproxy#13986.

Also adding GTEST code for the new field.

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to api/envoy/.
envoyproxy/api-shepherds assignee is @lizan
CC @envoyproxy/api-watchers: FYI only for changes made to api/envoy/.

🐱

Caused by: #16107 was opened by yanjunxiang-google.

see: more, trace.

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/assign @yanavlasov @adisuissa

Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, I've left a few comments.
Please also update the PR's main commit message fields.

// Key is the reverse DNS filter name, e.g. com.acme.widget. The envoy.*
// namespace is reserved for Envoy's built-in filters.
map<string, google.protobuf.Struct> filter_metadata = 1;

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.

Please add some comments here.
You might also want to update the comment for the Metadata message to describe the differences between the typed and non-typed filter metadata fields.
In addition, can the same key be in both filter_metadata and typed_filter_metadata. If so, what happens in this case?

BTW: if there should only be either filter_metadata or typed_filter_metadata but not both, then consider using oneof here.

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.

The question here is shall we deprecate filter_metadata? When we changed filter configs from Struct to Any we deprecated Struct because Any can have Struct in it.

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.

let's mark it as deprecated.

I think Oneof will make it harder to migrate.
For now we need both to have a smooth migration: let the metadata impl first look at typed_filter_metadata and fallback to typed_metadata when it's not populated. This way we can decouple dataplane with control plane.

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.

Yeah don't make it oneof, it breaks the compatibility on generated codes and violates our API policy.

Copy link
Copy Markdown
Contributor

@AdiJohn AdiJohn Apr 23, 2021

Choose a reason for hiding this comment

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

Using Oneof is infeasible here. For Oneof fields, "You can add fields of any type, except map fields and repeated fields." See https://developers.google.com/protocol-buffers/docs/proto3#oneof

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.

The main present issue with transitioning to using Struct-inside-of-Any is that the Metadata utility class has static methods only. It will be inefficient to use with the Struct-inside-of-Any as there is no way to cache parsed Struct. The Metadata utility class is used heavily within Envoy and also by proprietary filters, so changing its API will be challenging.
One potential way forward is to make current implementation of the Metadata class inefficient with respect to Struct-inside-of-Any and mark it as deprecated to prevent further use. And then add a new class that can cache parsed Struct from Any.

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.

Yeah, I think a TypedMetadata class would make sense.

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.

Thanks for the comments. Based on the discussion, I put Struct as deprecated, and added Any. Please take a look the latest code change and let me know whether this look good to you.

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.

With Struct field being deprecated, this pre_submit check scripts: " ci/run_envoy_docker.sh 'ci/do_ci.sh bazel.compile_time_options' ", is complaining below and failed the check constantly:

2021-05-07T23:34:58.2181735Z C++ exception with description "type envoy.config.core.v3.Metadata Using deprecated option 'envoy.config.core.v3.Metadata.filter_metadata' from file base.proto. This configuration will be removed from Envoy soon. Please see https://www.envoyproxy.io/docs/envoy/latest/version_history/version_history for details. If continued use of this field is absolutely necessary, see https://www.envoyproxy.io/docs/envoy/latest/configuration/operations/runtime#using-runtime-overrides-for-deprecated-features for how to apply a temporary and highly discouraged override." thrown in the test body.
2021-05-07T23:34:58.2184225Z [ FAILED ] OmitHostsRetryPredicateTest.PredicateTest (22 ms)

This happend on a lot of test cases, and one scripts run only report some of them. Once some test cases are failed as above, I just use DEPRECATED_FEATURE_TEST() to guard them. Another scripts run will report new ones. I have below questions:

  1. Should I continue this catch and patch style to mark all those test cases which exercising Metadata:Struct with DEPRECATED_FEATURE_TEST()?
  2. Is there a way to let the scripts run to the end and report all the test cases which exercising Metadata:Struct ? That way I can patch once for all.
  3. Is there a timing pressure to commit Any in the metadata proto? If there is, should we first commit the Any without flag Struct as deprecated? That way we deprecate Struct and fix all the text cases in a separate PR.

Please let me know your opinion.

Thanks!

Copy link
Copy Markdown
Contributor Author

@yanjunxiang-google yanjunxiang-google May 11, 2021

Choose a reason for hiding this comment

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

There are a lot of test cases broken by deprecating Struct field. Fixing those test cases need time. Given the timing pressure for adding Any support in this protobuf, we decided to tackle Struct field deprecation and fixing the related test cases in a separate PR.

Please let me know whether this sound good to you.

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/assign @htuch @stevenzzzz

Copy link
Copy Markdown
Contributor

@stevenzzzz stevenzzzz left a comment

Choose a reason for hiding this comment

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

I think we should have some consideration around the default impl of "parse(const ProtobufWkt::Any& data)" and the "fallback" behavior in populateFrom

// Key is the reverse DNS filter name, e.g. com.acme.widget. The envoy.*
// namespace is reserved for Envoy's built-in filters.
map<string, google.protobuf.Struct> filter_metadata = 1;

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.

let's mark it as deprecated.

I think Oneof will make it harder to migrate.
For now we need both to have a smooth migration: let the metadata impl first look at typed_filter_metadata and fallback to typed_metadata when it's not populated. This way we can decouple dataplane with control plane.

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/assign @AdiJohn

@yanavlasov
Copy link
Copy Markdown
Contributor

This PR needs tests in the TypedMetadataTest suite. It needs a factory that supports decoding from both Any and Struct as well as factory that only decodes from Struct. And then tests that go through various fallback cases that you've added. I.e.

  1. there is both Struct and Any but factory can only decode Struct
  2. there is both Struct and Any but factory can decode Any
  3. only Struct and factory can decode both Any and Struct
  4. not sure if there are any other cases

@yanavlasov
Copy link
Copy Markdown
Contributor

/wait

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

Thanks for working on this, I've left a few comments.
Please also update the PR's main commit message fields.

Thanks for the great comments! Done. please take a look!

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

This PR needs tests in the TypedMetadataTest suite. It needs a factory that supports decoding from both Any and Struct as well as factory that only decodes from Struct. And then tests that go through various fallback cases that you've added. I.e.

  1. there is both Struct and Any but factory can only decode Struct
  2. there is both Struct and Any but factory can decode Any
  3. only Struct and factory can decode both Any and Struct
  4. not sure if there are any other cases

Thanks for the good comments. I had modified the change to cover them. Please take a look the new unit test code and let me know if something is missing and need to be added.

@yanavlasov
Copy link
Copy Markdown
Contributor

code changes are good, but it looks like proto format picked up a lot more changes than warranted for this PR. I think this needs to have its proto format results cleaned-up.

Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks for working on this.
I've left a few comments.

@yanavlasov
Copy link
Copy Markdown
Contributor

/wait

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
…ata_proto

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

Waiting for #16434 commit, which is to fix the flaky testing issue.

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16107 (comment) was created by @yanjunxiang-google.

see: more, trace.

…ata_proto

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16107 (comment) was created by @yanjunxiang-google.

see: more, trace.

yanavlasov
yanavlasov previously approved these changes May 13, 2021
@yanavlasov
Copy link
Copy Markdown
Contributor

It will need another main merge after the problem with tooling is fixed

…ata_proto

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanavlasov
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

…ata_proto

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16107 (comment) was created by @yanjunxiang-google.

see: more, trace.

@KBaichoo
Copy link
Copy Markdown
Contributor

@envoyproxy/api-shepherds PTAL

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16107 (comment) was created by @yanjunxiang-google.

see: more, trace.

Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM API modulo format nit.

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google yanjunxiang-google dismissed stale reviews from yanavlasov and stevenzzzz via 4767834 May 17, 2021 16:08
…ata_proto

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

/lgtm api

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16107 (comment) was created by @yanjunxiang-google.

see: more, trace.

@yanavlasov yanavlasov merged commit 178c088 into envoyproxy:main May 18, 2021
ntgsx92 pushed a commit to ntgsx92/envoy that referenced this pull request May 18, 2021
envoyproxy#16107)

Allow http route and cluster metadata to contain typed metadata in Any in addition to Struct format 
envoyproxy#13986.

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>

Signed-off-by: Sixiang Gu <sgu@twitter.com>
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
envoyproxy#16107)

Allow http route and cluster metadata to contain typed metadata in Any in addition to Struct format 
envoyproxy#13986.

Signed-off-by: Yanjun Xiang <yanjunxiang@google.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.

Allow http route and cluster metadata to contain typed metadata in Any in addition to Struct format

8 participants