From ab3d7b06a2f23b2c7aae1fde638aebfa64fff656 Mon Sep 17 00:00:00 2001 From: "data-plane-api(Azure Pipelines)" Date: Wed, 22 Jun 2022 16:43:05 +0000 Subject: [PATCH] regex: add regex engine factory and config option (#21633) Add support for injecting regex engine with its options on startup in a bootstrap option. These are some API, runtime and implementation changes. * google_re2 in safe_regex will be deprecated and no longer be required. Regex::parseRegex will choose the registered regex engine to parse expressions into matchers. * A new bootstrap option default_regex_engine will be introduced for regex engine selection. * For compatibility, GoogleRE2 will be chosen as default regex engine if no regex engine is designated. Signed-off-by: Xie Zhihao Mirrored from https://github.com/envoyproxy/envoy @ 0a92cc86e7f8b88d5af0eb2e27b5c7ef64719e56 --- BUILD | 1 + envoy/config/bootstrap/v3/bootstrap.proto | 6 ++++- envoy/extensions/regex_engines/v3/BUILD | 9 ++++++++ .../regex_engines/v3/google_re2.proto | 23 +++++++++++++++++++ envoy/type/matcher/v3/regex.proto | 8 ++++--- versioning/BUILD | 1 + 6 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 envoy/extensions/regex_engines/v3/BUILD create mode 100644 envoy/extensions/regex_engines/v3/google_re2.proto diff --git a/BUILD b/BUILD index dd9edbb6..6452534f 100644 --- a/BUILD +++ b/BUILD @@ -243,6 +243,7 @@ proto_library( "//envoy/extensions/quic/proof_source/v3:pkg", "//envoy/extensions/rate_limit_descriptors/expr/v3:pkg", "//envoy/extensions/rbac/matchers/upstream_ip_port/v3:pkg", + "//envoy/extensions/regex_engines/v3:pkg", "//envoy/extensions/request_id/uuid/v3:pkg", "//envoy/extensions/resource_monitors/fixed_heap/v3:pkg", "//envoy/extensions/resource_monitors/injected_resource/v3:pkg", diff --git a/envoy/config/bootstrap/v3/bootstrap.proto b/envoy/config/bootstrap/v3/bootstrap.proto index bde4d5c3..991b0899 100644 --- a/envoy/config/bootstrap/v3/bootstrap.proto +++ b/envoy/config/bootstrap/v3/bootstrap.proto @@ -41,7 +41,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE; // ` for more detail. // Bootstrap :ref:`configuration overview `. -// [#next-free-field: 34] +// [#next-free-field: 35] message Bootstrap { option (udpa.annotations.versioning).previous_message_type = "envoy.config.bootstrap.v2.Bootstrap"; @@ -330,6 +330,10 @@ message Bootstrap { // Optional path to a file with performance tracing data created by "Perfetto" SDK in binary // ProtoBuf format. The default value is "envoy.pftrace". string perf_tracing_file_path = 33; + + // Optional overriding of default regex engine. + // If the value is not specified, Google RE2 will be used by default. + core.v3.TypedExtensionConfig default_regex_engine = 34; } // Administration interface :ref:`operations documentation diff --git a/envoy/extensions/regex_engines/v3/BUILD b/envoy/extensions/regex_engines/v3/BUILD new file mode 100644 index 00000000..ee92fb65 --- /dev/null +++ b/envoy/extensions/regex_engines/v3/BUILD @@ -0,0 +1,9 @@ +# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. + +load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") + +licenses(["notice"]) # Apache 2 + +api_proto_package( + deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], +) diff --git a/envoy/extensions/regex_engines/v3/google_re2.proto b/envoy/extensions/regex_engines/v3/google_re2.proto new file mode 100644 index 00000000..8c1e3138 --- /dev/null +++ b/envoy/extensions/regex_engines/v3/google_re2.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +package envoy.extensions.regex_engines.v3; + +import "udpa/annotations/status.proto"; + +option java_package = "io.envoyproxy.envoy.extensions.regex_engines.v3"; +option java_outer_classname = "GoogleRe2Proto"; +option java_multiple_files = true; +option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/regex_engines/v3;regex_enginesv3"; +option (udpa.annotations.file_status).package_version_status = ACTIVE; + +// [#protodoc-title: Google RE2] + +// Google's `RE2 `_ regex engine. The regex string must adhere to +// the documented `syntax `_. The engine is designed +// to complete execution in linear time as well as limit the amount of memory used. +// +// Envoy emits two stats for tracking the program size of regexes: the histogram `re2.program_size`, +// which records the program size, and the counter `re2.exceeded_warn_level`, which is incremented +// each time the program size exceeds the warn level threshold. +message GoogleRE2 { +} diff --git a/envoy/type/matcher/v3/regex.proto b/envoy/type/matcher/v3/regex.proto index f18bd03e..1aee9b6a 100644 --- a/envoy/type/matcher/v3/regex.proto +++ b/envoy/type/matcher/v3/regex.proto @@ -56,10 +56,12 @@ message RegexMatcher { } oneof engine_type { - option (validate.required) = true; - // Google's RE2 regex engine. - GoogleRE2 google_re2 = 1 [(validate.rules).message = {required: true}]; + GoogleRE2 google_re2 = 1 [ + deprecated = true, + (validate.rules).message = {required: true}, + (envoy.annotations.deprecated_at_minor_version) = "3.0" + ]; } // The regex match string. The string must be supported by the configured engine. The regex is matched diff --git a/versioning/BUILD b/versioning/BUILD index ef9aaa54..770f535d 100644 --- a/versioning/BUILD +++ b/versioning/BUILD @@ -184,6 +184,7 @@ proto_library( "//envoy/extensions/quic/proof_source/v3:pkg", "//envoy/extensions/rate_limit_descriptors/expr/v3:pkg", "//envoy/extensions/rbac/matchers/upstream_ip_port/v3:pkg", + "//envoy/extensions/regex_engines/v3:pkg", "//envoy/extensions/request_id/uuid/v3:pkg", "//envoy/extensions/resource_monitors/fixed_heap/v3:pkg", "//envoy/extensions/resource_monitors/injected_resource/v3:pkg",