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 <zhihao.xie@intel.com>

Mirrored from https://github.com/envoyproxy/envoy @ 0a92cc86e7f8b88d5af0eb2e27b5c7ef64719e56
pull/626/head
data-plane-api(Azure Pipelines) 3 years ago
parent 73fdc08d54
commit ab3d7b06a2
  1. 1
      BUILD
  2. 6
      envoy/config/bootstrap/v3/bootstrap.proto
  3. 9
      envoy/extensions/regex_engines/v3/BUILD
  4. 23
      envoy/extensions/regex_engines/v3/google_re2.proto
  5. 8
      envoy/type/matcher/v3/regex.proto
  6. 1
      versioning/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",

@ -41,7 +41,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// <config_overview_bootstrap>` for more detail.
// Bootstrap :ref:`configuration overview <config_overview_bootstrap>`.
// [#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

@ -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"],
)

@ -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 <https://github.com/google/re2>`_ regex engine. The regex string must adhere to
// the documented `syntax <https://github.com/google/re2/wiki/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 {
}

@ -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

@ -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",

Loading…
Cancel
Save