Hyperscan
Hyperscan 是一個高效能的多重正規表示式匹配函式庫,它使用混合自動機技術,允許同時匹配大量的正規表示式,並在資料串流中匹配正規表示式。Hyperscan 支援 PCRE 使用的 模式語法。
Hyperscan 僅在 contrib 映像檔 中有效。
Hyperscan 可以作為 通用匹配 的匹配器使用,或者作為全域正規表示式引擎啟用。
作為通用匹配的匹配器
通用匹配已在 Envoy 中的幾個元件和擴充功能中實作,包括 篩選器鏈匹配器、 路由匹配器 和 RBAC 匹配器。Hyperscan 匹配器可以在通用匹配器中作為自訂匹配器使用,其結構如下
1 custom_match:
2 name: hyperscan
3 typed_config:
4 "@type": type.googleapis.com/envoy.extensions.matching.input_matchers.hyperscan.v3alpha.Hyperscan
5 regexes:
6 - regex: allowed.*path
可以設定 Hyperscan 匹配器中正規表示式匹配的行為,請參閱 API 參考。
Hyperscan 匹配器也支援多重模式匹配,允許同時報告多個模式的匹配。可以在以下結構中開啟多重模式匹配
1 custom_match:
2 name: hyperscan
3 typed_config:
4 "@type": type.googleapis.com/envoy.extensions.matching.input_matchers.hyperscan.v3alpha.Hyperscan
5 # The following multiple patterns match input including allowed.*path and excluding
6 # den(y|ied). E.g., the path /allowed/path will be matched, while the path
7 # /allowed/denied/path will not be matched.
8 regexes:
9 - regex: allowed.*path
10 id: 1
11 quiet: true
12 - regex: den(y|ied)
13 id: 2
14 quiet: true
15 - regex: 1 & !2
16 combination: true
作為正規表示式引擎
Hyperscan 正規表示式引擎的行為與預設的正規表示式引擎 Google RE2 類似,例如它預設會開啟 UTF-8 支援。Hyperscan 正規表示式引擎可以使用以下設定輕鬆設定。
1default_regex_engine:
2 name: envoy.regex_engines.hyperscan
3 typed_config:
4 "@type": type.googleapis.com/envoy.extensions.regex_engines.hyperscan.v3alpha.Hyperscan