Skip to content

Commit d35b9e6

Browse files
authored
matchers: add CEL matcher, input (cncf#31)
* matchers: add CEL matcher, input Signed-off-by: Sergii Tkachenko <[email protected]> * Update HttpCelMatchInput per review - Remove Attributes from HttpCelMatchInput - Rename to HttpAttributesMatchInput Signed-off-by: Sergii Tkachenko <[email protected]> * Use rst reference instead. Signed-off-by: Sergii Tkachenko <[email protected]> * CelExpression WIP Signed-off-by: Sergii Tkachenko <[email protected]> * HttpAttributesCelMatchInput WIP Signed-off-by: Sergii Tkachenko <[email protected]> * Reset xds/type/matcher/v3/BUILD Signed-off-by: Sergii Tkachenko <[email protected]> * Finish HttpAttributesCelMatchInput - address skip_if_error Signed-off-by: Sergii Tkachenko <[email protected]> * Revert to cel-as-matcher approach Signed-off-by: Sergii Tkachenko <[email protected]> * Fixes per review: CEL matcher name, CelExtractString package Signed-off-by: Sergii Tkachenko <[email protected]> * Build fix, except //test/build:go_build_test Signed-off-by: Sergii Tkachenko <[email protected]> * Address //test/build:go_build_test build error Signed-off-by: Sergii Tkachenko <[email protected]> * Generate protobuf for the new files Signed-off-by: Sergii Tkachenko <[email protected]>
1 parent 42e9329 commit d35b9e6

12 files changed

+1265
-11
lines changed

bazel/api_build_system.bzl

+35-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ load("@com_google_protobuf//:protobuf.bzl", _py_proto_library = "py_proto_librar
33
load("@io_bazel_rules_go//go:def.bzl", "go_test")
44
load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library")
55
load("@rules_proto//proto:defs.bzl", "proto_library")
6+
load(
7+
"//bazel:external_proto_deps.bzl",
8+
"EXTERNAL_PROTO_CC_BAZEL_DEP_MAP",
9+
"EXTERNAL_PROTO_GO_BAZEL_DEP_MAP",
10+
"EXTERNAL_PROTO_PY_BAZEL_DEP_MAP",
11+
)
612

713
_PY_PROTO_SUFFIX = "_py_proto"
814
_CC_PROTO_SUFFIX = "_cc_proto"
@@ -24,18 +30,21 @@ _COMMON_PROTO_DEPS = [
2430
"@com_envoyproxy_protoc_gen_validate//validate:validate_proto",
2531
]
2632

27-
def _proto_mapping(dep, proto_suffix):
28-
prefix = "@" + Label(dep).workspace_name if not dep.startswith("//") else ""
29-
return prefix + "//" + Label(dep).package + ":" + Label(dep).name + proto_suffix
33+
def _proto_mapping(dep, proto_dep_map, proto_suffix):
34+
mapped = proto_dep_map.get(dep)
35+
if mapped == None:
36+
prefix = "@" + Label(dep).workspace_name if not dep.startswith("//") else ""
37+
return prefix + "//" + Label(dep).package + ":" + Label(dep).name + proto_suffix
38+
return mapped
3039

3140
def _go_proto_mapping(dep):
32-
return _proto_mapping(dep, _GO_PROTO_SUFFIX)
41+
return _proto_mapping(dep, EXTERNAL_PROTO_GO_BAZEL_DEP_MAP, _GO_PROTO_SUFFIX)
3342

3443
def _cc_proto_mapping(dep):
35-
return _proto_mapping(dep, _CC_PROTO_SUFFIX)
44+
return _proto_mapping(dep, EXTERNAL_PROTO_CC_BAZEL_DEP_MAP, _CC_PROTO_SUFFIX)
3645

3746
def _py_proto_mapping(dep):
38-
return _proto_mapping(dep, _PY_PROTO_SUFFIX)
47+
return _proto_mapping(dep, EXTERNAL_PROTO_PY_BAZEL_DEP_MAP, _PY_PROTO_SUFFIX)
3948

4049
# TODO(htuch): Convert this to native py_proto_library once
4150
# https://github.com/bazelbuild/bazel/issues/3935 and/or
@@ -58,7 +67,7 @@ def _xds_py_proto_library(name, srcs = [], deps = []):
5867

5968
# This defines googleapis py_proto_library. The repository does not provide its definition and requires
6069
# overriding it in the consuming project (see https://github.com/grpc/grpc/issues/19255 for more details).
61-
def py_proto_library(name, deps = []):
70+
def py_proto_library(name, deps = [], plugin = None):
6271
srcs = [dep[:-6] + ".proto" if dep.endswith("_proto") else dep for dep in deps]
6372
proto_deps = []
6473

@@ -67,6 +76,14 @@ def py_proto_library(name, deps = []):
6776
# As a workaround, manually specify the proto dependencies for the imported python rules.
6877
if name == "annotations_py_proto":
6978
proto_deps = proto_deps + [":http_py_proto"]
79+
80+
# checked.proto depends on syntax.proto, we have to add this dependency manually as well.
81+
if name == "checked_py_proto":
82+
proto_deps = proto_deps + [":syntax_py_proto"]
83+
84+
# py_proto_library does not support plugin as an argument yet at gRPC v1.25.0:
85+
# https://github.com/grpc/grpc/blob/v1.25.0/bazel/python_rules.bzl#L72.
86+
# plugin should also be passed in here when gRPC version is greater than v1.25.x.
7087
_py_proto_library(
7188
name = name,
7289
srcs = srcs,
@@ -110,7 +127,12 @@ def _xds_cc_py_proto_library(
110127
# TODO: neither C++ or Python service generation is supported today, follow the Envoy example to implementthis.
111128
pass
112129

113-
def xds_proto_package(srcs = [], deps = [], has_services = False, visibility = ["//visibility:public"]):
130+
def xds_proto_package(
131+
name = "pkg",
132+
srcs = [],
133+
deps = [],
134+
has_services = False,
135+
visibility = ["//visibility:public"]):
114136
if srcs == []:
115137
srcs = native.glob(["*.proto"])
116138

@@ -127,13 +149,16 @@ def xds_proto_package(srcs = [], deps = [], has_services = False, visibility = [
127149
if has_services:
128150
compilers = ["@io_bazel_rules_go//proto:go_grpc", "//bazel:pgv_plugin_go"]
129151

152+
# Because RBAC proro depends on googleapis syntax.proto and checked.proto,
153+
# which share the same go proto library, it causes duplicative dependencies.
154+
# Thus, we use depset().to_list() to remove duplicated depenencies.
130155
go_proto_library(
131156
name = name + _GO_PROTO_SUFFIX,
132157
compilers = compilers,
133158
importpath = _GO_IMPORTPATH_PREFIX + native.package_name(),
134159
proto = name,
135160
visibility = ["//visibility:public"],
136-
deps = [_go_proto_mapping(dep) for dep in deps] + [
161+
deps = depset([_go_proto_mapping(dep) for dep in deps] + [
137162
"@com_envoyproxy_protoc_gen_validate//validate:go_default_library",
138163
"@com_github_golang_protobuf//ptypes:go_default_library_gen",
139164
"@go_googleapis//google/api:annotations_go_proto",
@@ -143,7 +168,7 @@ def xds_proto_package(srcs = [], deps = [], has_services = False, visibility = [
143168
"@io_bazel_rules_go//proto/wkt:struct_go_proto",
144169
"@io_bazel_rules_go//proto/wkt:timestamp_go_proto",
145170
"@io_bazel_rules_go//proto/wkt:wrappers_go_proto",
146-
],
171+
]).to_list(),
147172
)
148173

149174
def xds_cc_test(name, **kwargs):

bazel/external_proto_deps.bzl

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Any external dependency imported in the xds/ .protos requires entries in
2+
# the maps below, to allow the Bazel proto and language specific bindings to be
3+
# inferred from the import directives.
4+
#
5+
# This file needs to be interpreted as both Python 3 and Starlark, so only the
6+
# common subset of Python should be used.
7+
8+
# This maps from .proto import directive path to the Bazel dependency path for
9+
# external dependencies. Since BUILD files are generated, this is the canonical
10+
# place to define this mapping.
11+
EXTERNAL_PROTO_IMPORT_BAZEL_DEP_MAP = {
12+
"google/api/expr/v1alpha1/checked.proto": "@com_google_googleapis//google/api/expr/v1alpha1:checked_proto",
13+
"google/api/expr/v1alpha1/syntax.proto": "@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto",
14+
}
15+
16+
# This maps from the Bazel proto_library target to the Go language binding target for external dependencies.
17+
EXTERNAL_PROTO_GO_BAZEL_DEP_MAP = {
18+
# Note @com_google_googleapis are point to @go_googleapis.
19+
# This is done to address //test/build:go_build_test build error:
20+
#
21+
# link: package conflict error:
22+
# google.golang.org/genproto/googleapis/api/annotations: multiple copies of package passed to linker:
23+
#
24+
# @go_googleapis//google/api:annotations_go_proto
25+
# @com_google_googleapis//google/api:annotations_go_proto
26+
#
27+
# TODO(https://github.com/bazelbuild/rules_go/issues/1986): update to
28+
# @com_google_googleapis when the bug is resolved. Also see the note to
29+
# go_googleapis in https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#overriding-dependencies
30+
"@com_google_googleapis//google/api/expr/v1alpha1:checked_proto": "@go_googleapis//google/api/expr/v1alpha1:expr_go_proto",
31+
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@go_googleapis//google/api/expr/v1alpha1:expr_go_proto",
32+
}
33+
34+
# This maps from the Bazel proto_library target to the C++ language binding target for external dependencies.
35+
EXTERNAL_PROTO_CC_BAZEL_DEP_MAP = {
36+
"@com_google_googleapis//google/api/expr/v1alpha1:checked_proto": "@com_google_googleapis//google/api/expr/v1alpha1:checked_cc_proto",
37+
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto",
38+
}
39+
40+
# This maps from the Bazel proto_library target to the Python language binding target for external dependencies.
41+
EXTERNAL_PROTO_PY_BAZEL_DEP_MAP = {
42+
"@com_google_googleapis//google/api/expr/v1alpha1:checked_proto": "@com_google_googleapis//google/api/expr/v1alpha1:checked_py_proto",
43+
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:syntax_py_proto",
44+
}

go/xds/type/matcher/v3/cel.pb.go

+167
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)