Repository navigation
Description
- Proposal Issue: 5418
- PR: perf(log-request-response): marshal log strings directly #5434
这里把现有 PR 的改法和验证安排整理到一起,接着 Proposal #5418 和 SPEC-5418001 继续复核。
Proposal 已获批。实现和下述实验均早于本 Design;本次补齐记录,不将其写成事前批准。
Current Implementation Locations
插件目录:plugins/wasm-go/extensions/log-request-response。
main.go:setPropertyWithMarshal:唯一生产修改位置。property_encoding_test.go:辅助函数字节回归,以及经过请求回调的 Go/Wasm 双模式回归。
原版基线为 c4c537f37175befc375e65ba059e8df477dc52a4,当前修复为 eed7b42f7cc67986f10a1904669c8dc915fae7c1。
Impact Scope
只简化字符串写入 filter state 前的编码过程。property 名称、日志开关、正文截取、采集时机、SSE 转发及访问日志格式保持原样。
这属于中间处理和分配的优化,不把已有日志声明为功能错误,也不引入新配置。
Candidate Plans
可以继续保留临时 map 与 gjson 查询,但这里只有一个字符串需要转义。直接使用 json.Marshal(value) 更简单;手写转义容易遗漏无效 UTF-8、HTML 或 Unicode 行分隔符,因此继续交给标准库编码。
Decisions
- 对字符串直接调用
json.Marshal,检查错误与长度,再去掉标准 JSON 字符串的外层引号。 - 将中间字节切片传给原有
SetProperty,保留写入失败日志。 - 各测试 case 使用独立 key。顺序为
plain→empty:先成功写入普通字符串,再测试空字符串;两个用例使用不同的 key。 - 空字符串沿用 SDK 对空 property 写入的处理;不人为写入新值,也不据此改变业务响应。
- 回归期望使用固定转义字节。双模式测试经过真实请求头/正文回调,让编译后的 Wasm 执行插件处理,不能仅在测试闭包中调用原生辅助函数就声称覆盖 guest 代码。
Verification Plan
以下给出确定的复核入口。已有结果发生在本 Design 建立前;Design 获批后按授权 TASK 关联这些记录,若维护者要求重跑或相关源码/依赖变化,则重新执行并另存结果。
Go 与 Wasm
使用 Go 1.24.4,从上述插件模块运行:
GOTOOLCHAIN=local GOWORK=off go test -mod=readonly -run '/go$' -count=1 -timeout=2m ./...
GOTOOLCHAIN=local GOWORK=off go test -mod=readonly -run '^Test(PropertyStringEncoding|RequestBodyStringEncoding)$' -count=1 -v
GOTOOLCHAIN=local GOWORK=off GOOS=wasip1 GOARCH=wasm go build -mod=readonly -buildvcs=false -trimpath -buildmode=c-shared -o /tmp/log-request-response-review.wasm .
git diff --check断言中文、引号、反斜杠、换行、控制字符、HTML、无效 UTF-8、U+2028/U+2029 的编码兼容;空串不依赖前一用例。
当前 Go/宿主套件与新增 Go/Wasm 回归均已通过。源码提交后重建模块与受测模块逐字节相同。
真实 Gateway
固定镜像:higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/gateway@sha256:a82de493902012ce6b555ecb2244156f3c73824474d67549144a7efa334d0299。macOS/amd64,Envoy V8,单 worker、1 CPU、768 MiB、fail_open=false;本地固定 HTTP 上游,不调用真实模型。
在独立验证包目录运行,build.py 会按完整源码 SHA 拉取两份源码、构建并校验模块;每次复跑使用新 label:
python3 build.py
python3 verify.py logging baseline recheck-baseline
python3 verify.py logging fixed recheck-fixed每版 4 KiB/64 KiB 中文 × 插件/旁路路由 × 30 次,即原版 120 + 修复 120 = 240 次。要求全部 HTTP 200、客户端正文逐字节匹配上游;插件路由的直接文件日志 JSON 解码后匹配预期,旁路不生成该 property。Wasm crash/rebuild/fail-open skip 为 0。
11 月 30 日已按此配置完成 240 次对照。stdout 与文件使用相同 formatter:文件输出全部匹配;Docker json-file 控制台采集在两版分别出现 4/12 条损坏。独立 cat 控制实验无需运行 Higress 即可复现跨 16 KiB 边界的 UTF-8 替换字符,输入与原始捕获一并保留。这里证明的是插件 property 编码兼容,不承诺所有外部日志采集链路无损。
证据与清理
验证记录含完整配置、固定输入、客户端正文、文件和控制台日志、命令、指标、逐项结果及 SHA256SUMS,并提供独立压缩包与哈希。
- 原版 Wasm:
6889dab64d5d4849babcfa0842188ed32eba84105ba37dcb67a992bda442e9ea - 修复 Wasm:
ba45713d70f8abbafce8e98431943f04e369334de4a91e43a99a869ff3aca5ef
复跑须在 finally 中保存日志、删除本轮容器、停止固定上游并确认端口和线程关闭。已有记录的 cleanup 均通过,不清理其他服务。
#5418 的旧辅助函数 benchmark 仅为探索测量;这 240 次是功能兼容验证,不用它推算生产 QPS、CPU 或成本收益。
TASK 安排
本 Design 确认后登记两个 TASK:实现记录关联上述修复提交和 SPEC;验证记录关联准确命令、结果、源码/Wasm 哈希及清理证明。此前已做的实现和实验注明真实时间,不倒填审批;需要增补验证时另行记录。
@CH3CHO 按您在 #5418 的说明补上这份设计和验证安排,麻烦确认,谢谢!
- Proposal Issue: 5418
- PR: perf(log-request-response): marshal log strings directly #5434
The modifications and verification arrangements for existing PRs are put together here, and then Proposal #5418 and SPEC-5418001 will continue to be reviewed.
Proposal has been approved. The implementation and the following experiments are earlier than this Design; this time the records are completed and will not be written as prior approval.
Current Implementation Locations
Plugin directory: plugins/wasm-go/extensions/log-request-response.
main.go:setPropertyWithMarshal: the only production modification location.property_encoding_test.go: Helper function byte regression, and Go/Wasm dual-mode regression via request callbacks.
The original baseline was c4c537f37175befc375e65ba059e8df477dc52a4 and the current fix is eed7b42f7cc67986f10a1904669c8dc915fae7c1.
Impact Scope
Only simplify the encoding process before writing the string into the filter state. The property name, log switch, text interception, collection timing, SSE forwarding and access log format remain unchanged.
This is an optimization of intermediate processing and distribution. It does not declare existing logs as functional errors or introduce new configurations.
Candidate Plans
You can continue to keep the temporary map and gjson query, but here there is only one string that needs to be escaped. It's simpler to use json.Marshal(value) directly; hand-written escaping tends to miss invalid UTF-8, HTML or Unicode line separators, so continue to be encoded by the standard library.
Decisions
- Call
json.Marshaldirectly on the string, check the error and length, and then remove the outer quotes of the standard JSON string. - Pass the intermediate byte slice to the original
SetPropertyand keep the write failure log. - Each test case uses an independent key. The order is
plain→empty: first successfully write a normal string, and then test the empty string; the two use cases use different keys. - Empty strings follow the SDK's handling of empty property writing; no new values are manually written, nor are business responses changed accordingly.
- Regression expected to use fixed escape bytes. Dual-mode testing allows compiled Wasm to perform plug-in processing through real request header/body callbacks. You cannot claim to cover guest code just by calling native helper functions in the test closure.
Verification Plan
The following is a definite review entry. The existing results occurred before this Design was created; after the Design is approved, these records are associated according to the authorized TASK. If the maintainer requires re-running or related source code/dependency changes, re-execute and save the results.
Go and Wasm
Using Go 1.24.4, run from the above plugin module:
GOTOOLCHAIN=local GOWORK=off go test -mod=readonly -run '/go$' -count=1 -timeout=2m ./...
GOTOOLCHAIN=local GOWORK=off go test -mod=readonly -run '^Test(PropertyStringEncoding|RequestBodyStringEncoding)$' -count=1 -v
GOTOOLCHAIN=local GOWORK=off GOOS=wasip1 GOARCH=wasm go build -mod=readonly -buildvcs=false -trimpath -buildmode=c-shared -o /tmp/log-request-response-review.wasm .
git diff --check Asserts encoding compatibility for Chinese, quotes, backslashes, newlines, control characters, HTML, invalid UTF-8, U+2028/U+2029; empty string does not depend on the previous use case.
Current Go/host packages and new Go/Wasm regressions have passed. After the source code is submitted, the reconstructed module is byte-for-byte identical to the module under test.
Real Gateway
Fixed mirror: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/gateway@sha256:a82de493902012ce6b555ecb2244156f3c73824474d67549144a7efa334d0299. macOS/amd64, Envoy V8, single worker, 1 CPU, 768 MiB, fail_open=false; local fixed HTTP upstream, no real model call.
Run in the Independent Verification Package directory, build.py will be based on the complete source code SHA Pull two copies of the source code, build and verify the module; use a new label for each rerun:
python3 build.py
python3 verify.py logging baseline recheck-baseline
python3 verify.py logging fixed recheck-fixed Each version 4 KiB/64 KiB Chinese × plug-in/bypass routing × 30 times, that is, original 120 + repair 120 = 240 times. It is required that all HTTP 200 and client body match the upstream byte by byte; the direct file log JSON of the plug-in route matches the expectation after decoding, and the bypass does not generate this property. Wasm crash/rebuild/fail-open skip is 0.
On November 30, 240 comparisons were completed with this configuration. stdout uses the same formatter as the file: the file output all matches; Docker json-file console collection has 4/12 corruptions in the two versions. A standalone cat control experiment reproduces UTF-8 replacement characters across 16 KiB boundaries without running Higress, and the input is preserved with the original capture. What is proved here is that the plug-in property encoding is compatible, and there is no guarantee that all external log collection links will be lossless.
Evidence and Cleanup
Verification record contains complete configuration, fixed input, client text, file and console logs, commands, indicators, itemized results and SHA256SUMS, and provides independent compression packages and hashes.
- Original Wasm:
6889dab64d5d4849babcfa0842188ed32eba84105ba37dcb67a992bda442e9ea - Fix Wasm:
ba45713d70f8abbafce8e98431943f04e369334de4a91e43a99a869ff3aca5ef
To rerun, you must save the log in finally, delete the current round of containers, stop the fixed upstream and confirm that the port and thread are closed. All recorded cleanups are passed and other services are not cleaned.
#5418's old helper function benchmark was for exploratory measurements only; these 240 times are functional compatibility verification, and it is not used to infer production QPS, CPU, or cost benefits.
TASK Arrangement
After this Design is confirmed, two TASKs are registered: the implementation record is associated with the above repair submission and SPEC; the verification record is associated with accurate commands, results, source code/Wasm hashes and cleanup certificates. The actual time of the implementation and experiments that have been done before will not be filled in for approval; if additional verification is needed, it will be recorded separately.
@CH3CHO Complete the design and verification arrangements according to your instructions in #5418, please confirm, thank you!
Activity
[-]Design: log-request-response 字符串日志直接编码与兼容验证[/-][+]Design: log-request-response 字符串日志直接编码与兼容验证 || Design: log-request-response string log direct encoding and compatibility verification[/+]BenRobinson-hub commentedon Dec 1, 2026
Independent review of Design #5473 (non-maintainer; not an approval):
One bilingual consistency correction before maintainer review:
Please align the English sentence with the Chinese wording (for example, “the empty-string case is placed after a preceding successful case”) so the test-order rationale and acceptance record are unambiguous.
This is a documentation correction only. It does not change the technical review result, grant Design approval, or authorize TASK execution. The record that implementation and existing verification predate this Design should remain explicit; the pre-implementation approval checkbox must not be treated as satisfied.
zhihao-yuan commentedon Dec 1, 2026
@BenRobinson-hub 谢谢提醒,我已修正英文:空字符串用例放在 plain 用例之后,断言使用独立 key,与中文说明和实际测试顺序一致。
@BenRobinson-hub Thanks for the reminder. I have corrected the English: the empty string use case is placed after the plain use case, and the assertion uses an independent key, which is consistent with the Chinese instructions and the actual test order.