feat: 支持 filter 插件动态字段过滤 (#220)#314
Draft
ljluestc wants to merge 1 commit into
Draft
Conversation
…cap#220) Add an optional FilterPluginDriver interface and execute it in the to-server send path so plugins can dynamically add/remove fields or drop events without changing core field list config. - add optional filter interface in plugin driver package - add default pass-through Filter implementation in PluginDriverInterface - invoke filter hook before write operations in sendToServer - add unit tests for pass-through, field mutation, drop-event, and error cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: 支持 filter 插件动态字段过滤 (#220)
关联 Issue
Closes #220
背景
当前 ToServer 流程仅支持通过 FieldList 做静态字段保留,以及 FilterUpdate/FilterQuery 等固定策略。这导致插件无法在同步前按业务规则动态增删字段,也无法在插件内决定直接丢弃某条事件。
为满足 issue #220,需要在不破坏现有插件兼容性的前提下,增加可选的 filter 插件钩子能力。
改动概览
本次改动在 sendToServer 流程中增加"可选 filter 钩子":
1. 新增可选过滤接口
新增文件:
plugin/driver/filter_interface.go新增接口:
语义约定:
keep=false:丢弃当前事件(视为成功跳过)keep=true:继续同步keep=true时newData必须非空2. 保持兼容:提供默认透传实现
修改文件:
plugin/driver/driver_interface.go在
PluginDriverInterface增加默认Filter方法,默认返回(data, true, nil)。效果:
FilterPluginDriver的插件才会启用动态过滤逻辑3. 在发送链路接入过滤钩子
修改文件:
server/to_server_consume.go新增方法:
applyPluginFilter(conn, data, retry)处理逻辑:
FilterPluginDriver:直接透传Filter返回错误:向上返回错误,沿用现有重试/错误处理链路keep=false:跳过该事件并返回成功(推进位点)keep=true && newData==nil:返回错误,防止空数据进入下游使用示例
示例:实现一个动态过滤插件
测试
新增文件:
server/to_server_consume_filter_test.go新增 5 个测试场景:
keep=false丢弃事件keep=true但返回 nil data 报错执行结果
go test ./server -run TestToServerApplyPluginFilter -count=1通过。
go test ./plugin/driver -count=1通过。
兼容性与风险
keep=true && newData=nil做显式保护变更文件
plugin/driver/filter_interface.goplugin/driver/driver_interface.goserver/to_server_consume.goserver/to_server_consume_filter_test.goSummary
Change Type
Scope
Linked Issues
Testing
go test ./server -run TestToServerApplyPluginFilterpassesgo test ./plugin/driverpassesSecurity Impact
Compatibility