Skip to content

Move envoy.api.v2 core protos to envoy.api.v2.core and organize filters#452

Merged
htuch merged 26 commits intoenvoyproxy:masterfrom
kyessenov:control_plane
Feb 2, 2018
Merged

Move envoy.api.v2 core protos to envoy.api.v2.core and organize filters#452
htuch merged 26 commits intoenvoyproxy:masterfrom
kyessenov:control_plane

Conversation

@kyessenov
Copy link
Copy Markdown
Contributor

@kyessenov kyessenov commented Jan 31, 2018

There are several main changes in this PR:

  1. Create envoy.api.v2.core packages to break circular dependencies from xDS on to subpackages on to base protos.
  2. Create individual packages for each filter and add independent versioning to each filter.
  3. Add visibility constraints to prevent formation of dependency cycles.
  4. Add gogoproto annotations to improve go code generation.

After moving xDS service definitions and top-level resource protos back to envoy.core.api.v2, cycles were created, since the second-level definitions depend on base protobuf definitions, and are in turn included from xDS; however xDS and base definitions are in the same package.

The solution is to split the base protos into another package, envoy.api.v2.core. That eliminates dependency cycles (validated using go-control-plane).

Added a few gogoproto annotations to improve golang code generation.

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
@kyessenov
Copy link
Copy Markdown
Contributor Author

cc @htuch

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.

This seems reasonable (although a bit more verbose). What guarantee do we have that this will fix all our dependency cycle problems for good? Churn == bad :)

@kyessenov
Copy link
Copy Markdown
Contributor Author

We need to enforce that only the following dependencies are allowed:

  • envoy/service -> envoy/api
  • envoy/config -> envoy/api
  • envoy/api/v2 -> envoy/api/v2/*
  • envoy/api/v2/auth -> envoy/api/v2/core
  • envoy/api/v2/[endpoint,cluster,route,listener] -> envoy/api/v2/[core,auth]

@htuch
Copy link
Copy Markdown
Member

htuch commented Jan 31, 2018

Do you know if it there's a cheap way to write a shell script test using Bazel query to validate this (or something like that)? Or even a simple Go equivalent of https://github.com/envoyproxy/data-plane-api/blob/master/test/build/build_test.cc?

@kyessenov
Copy link
Copy Markdown
Contributor Author

I've tried to add proto_library to sort of enforce that, but the problem is that dependencies do not transfer to them. E.g. once you depend on base.proto, the dependency on base.proto package does not show up in bazel.

@kyessenov
Copy link
Copy Markdown
Contributor Author

cc @lizan @douglas-reid for bazel expertise. Maybe you have some ideas?

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
@lizan
Copy link
Copy Markdown
Member

lizan commented Jan 31, 2018

Use visibility?

@kyessenov
Copy link
Copy Markdown
Contributor Author

kyessenov commented Jan 31, 2018

@htuch for visibility to work, we would need to change deps to use proto packages instead of individual protos. Is there a reason why the current approach of listing individual protos was chosen?

@htuch
Copy link
Copy Markdown
Member

htuch commented Jan 31, 2018

@kyessenov Seems fair enough. I would still think a Go litmus test would be nice, but not if it's too much overhead.

@kyessenov
Copy link
Copy Markdown
Contributor Author

I think we should improve the current go rules (cc @misterwilliam). If only we place protos into packages with these rules, we can automatically enforce package boundaries.

Signed-off-by: Kuat Yessenov <kuat@google.com>
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.

A couple of comments (And thanks for taking this on and keeping it moving; the APIs will be much better positioned as a result).

// Headers can be specified using *response_headers_to_add* in
// :ref:`envoy_api_msg_RouteConfiguration`.
DataSource body = 2;
core.DataSource body = 2;
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.

Should we fully qualify everywhere to avoid breakage if there is future movement (which hopefully won't happen, but ¯\_(ツ)_/¯).

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.

My heuristic was to qualify names outside of core packages and subpackages. I'm thinking that if we create "v3" then we might want to copy over all subpackages of "v2" to start from, and the relative names there would help. Filters I'm still planning to move away, and I tried to use fully qualified names to enable that.

Comment thread envoy/api/v2/core/BUILD
deps = [
":base",
":grpc_service",
],
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.

Are you still planning on adding visibility restrictions? I'd like us to do something to reduce the likelihood of future churn happening again; it can be visibility, a Go build test or even some good local build validation that we can add to the PR that can assure us we won't churn further.

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.

I can add visibility, but that requires that dependencies must be proto packages, not individual protos. Go rules is harder to achieve, that amounts to writing all go rules again, and that was hard before and is still (given that @misterwilliam did only partial subset of protos).

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.

PTAL, added "friends" package groups for visibility constraints.

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Comment thread envoy/api/v2/auth/BUILD Outdated
name = "friends",
packages = [
"-//envoy/api/v2/core",
"//envoy/...",
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.

Does it need to be this wide? Would prefer narrower scoping.

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.

Restricted it to //docs as much as possible.

Comment thread envoy/api/v2/cluster/BUILD Outdated
api_proto_library(
name = "circuit_breaker",
srcs = ["circuit_breaker.proto"],
visibility = ["//envoy/api/v2:friends"],
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 wonder if we can make some of these scopes narrowed.

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.

These two got further restricted to just //envoy/api/v2

@htuch
Copy link
Copy Markdown
Member

htuch commented Feb 1, 2018

package_group is nice; wondering if we can lock down visibility further than what is currently there, it doesn't seem to fully capture the restrictions discussed at a quick glance (should we write them down somewhere?).

Comment thread envoy/api/v2/listener/listener.proto Outdated
Metadata metadata = 5;
core.Metadata metadata = 5;

// [#not-implemented-hide:] See base.TransportSocket description.
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.

Can you update the doc to match what Cluster has? Also remove not-implement-hide. Thanks!

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 PTAL

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 don't see this is updated.

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.

Oh, I thought you are referring to Metadata.

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.

Can you give more details what needs to go 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.

Just like clusters

See :ref:`base.TransportSocket<envoy_api_msg_core.TransportSocket>` description.

Is good, no longer need [#not-implemented-hide:]

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

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
@kyessenov
Copy link
Copy Markdown
Contributor Author

kyessenov commented Feb 1, 2018

@htuch I tried to restrict visibility further. Let me know if this is OK. The main idea is to prevent cycles within core, as well as prevent dependencies of core on other things. Both are accomplished with visibility.

I also took a stab at organizing filters into their own packages together with versions.

@kyessenov kyessenov changed the title Move envoy.api.v2 core protos to envoy.api.v2.core Move envoy.api.v2 core protos to envoy.api.v2.core and organize filters Feb 2, 2018
Comment thread bazel/api_build_system.bzl Outdated
# TODO(htuch): Automatically generate go_proto_library and go_grpc_library
# from api_proto_library.
def api_proto_library(name, srcs = [], deps = [], has_services = 0, require_py = 1):
def api_proto_library(name, visibility, srcs = [], deps = [], has_services = 0, require_py = 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.

Should this default to "//visibility:public" for backward-compatibility?

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.

No strong opinion. I found it useful for myself to make sure I didn't miss any.

Signed-off-by: Kuat Yessenov <kuat@google.com>
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.

The new approach and layout looks good. Can you update the README.mds across the tree to express the visibility rules in plain English for readers? I'll need to take another pass after reading those and patching this into a local client so I can grep out the visibility rules.

@wora can you take another look?

Comment thread bazel/api_build_system.bzl Outdated
# TODO(htuch): Automatically generate go_proto_library and go_grpc_library
# from api_proto_library.
def api_proto_library(name, srcs = [], deps = [], has_services = 0, require_py = 1):
def api_proto_library(name, visibility, srcs = [], deps = [], has_services = 0, require_py = 1):
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.

@PiotrSikora as long as this works on the main Envoy repo I think it's OK. We clobber this during import, so it's not an issue inside Google.

api_proto_library(
name = "mongo_proxy",
srcs = ["mongo_proxy.proto"],
visibility = ["//envoy:friends"],
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.

Why does a network filter require such wide visibility?

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.

I changed it just //docs in the last update.

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
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.

LGTM. Big +1 for adding an "overview" section to STYLE.md on the overall layout, what goes where, the friend stuff, etc. Would love to try to land this today as I would like to play around with some further doc cleanups to make the v2 docs a bit easier to consume.

Comment thread .circleci/config.yml Outdated
test:
docker:
- image: envoyproxy/envoy-build:52f6880ffbf761c9b809fc3ac208900956ff16b4
- image: envoyproxy/envoy-build:61b38528d7e46ced9d749d278ba185332310ca95
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.

nit: Can you fix the Circle config to use the same ref semantics for the image as is done here: https://github.com/envoyproxy/envoy/blob/master/.circleci/config.yml#L1

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

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
@kyessenov
Copy link
Copy Markdown
Contributor Author

I added a brief explanation to STYLE about layering and visibility.

@kyessenov
Copy link
Copy Markdown
Contributor Author

@wora do you mind taking a look at this?

mattklein123
mattklein123 previously approved these changes Feb 2, 2018
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.

LGTM, thanks @kyessenov! @htuch can approve/merge from here.

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 modulo some very minor remaining comments. I've given this a full review, so when they are fixed, it's good to go. +1000 thanks.

Comment thread envoy/api/v2/README.md Outdated
`//envoy/api/v2:friends`.

Additionally, packages envoy.api.v2.core and envoy.api.v2.auth are also
consumed throughout the remaining core API packages, but not by each other.
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.

Nit: "core" here is a bit misleading given "envoy.api.v2.core".

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.

changed to "shared"

api_proto_library(
name = "rate_limit",
srcs = ["rate_limit.proto"],
visibility = ["//docs"],
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 make this less verbose by just always adding //doc in api_proto_library (it can't ever hurt), and making visibility optional and by default private.

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.

Cool idea! I made it private by default, and add //docs always (thereby switching from private to ["//docs"] since private is not combinable).

Comment thread envoy/api/v2/README.md Outdated
@@ -1 +1,9 @@
Protocol buffer definitions for core API messages.
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 we need to rename this use of "core" as well.

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.

It's basically a placeholder for old legacy stuff we can't move and acts just as a parent node otherwise.

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.

made it clear this is just old xDS + top-level resources

Signed-off-by: Kuat Yessenov <kuat@google.com>
Signed-off-by: Kuat Yessenov <kuat@google.com>
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.

Rad.

@htuch htuch merged commit 4e533f2 into envoyproxy:master Feb 2, 2018
@kyessenov kyessenov deleted the control_plane branch February 2, 2018 22:28
htuch pushed a commit to envoyproxy/envoy that referenced this pull request Feb 4, 2018
Risk Level: Low
Testing: bazel test.
Docs Changes: envoyproxy/data-plane-api#452

Signed-off-by: Kuat Yessenov <kuat@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.

6 participants