-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extension mechanism for custom logs and span attributes #1451
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1451 +/- ##
==========================================
+ Coverage 35.91% 43.54% +7.63%
==========================================
Files 69 76 +7
Lines 11576 12325 +749
==========================================
+ Hits 4157 5367 +1210
+ Misses 7104 6624 -480
- Partials 315 334 +19 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看没看完,先标注这些
customLog := map[string]interface{}{} | ||
if string(preMarshaledJsonLogStr) != "" { | ||
// e.g. {"feild1":"value1","feild2":"value2"} | ||
preJsonLogStr := UnmarshalStr(fmt.Sprintf(`"%s"`, string(preMarshaledJsonLogStr))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不太能理解为什么前面 marshal 的时候把首尾的引号去掉,这里又加上。如果之前就没去掉,现在是不是也不用单独加上了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
日志的format里面每个字段都会有一个"",所以当某个字段是一个序列化的json字符串的时候,把首位的""去掉让打印到控制台的日志格式是一个合法的json。所以实际上filter_state里面保存的不是一个完整的序列化后的json字符串,在使用json.Unmarshal
进行反序列化时需要再把""加上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以ctx下增加一个 addAccessLogField 的函数,支持用户将自定义日志字段存到 ctx 里,然后在 onDone 阶段统一通过 setProperty 设置进去。这样用户使用简单,整体性能也是最优的。
验证了下,onStreamDone里面setProperty不生效 |
eb417bf
to
53718c5
Compare
53718c5
to
51f18e7
Compare
96e91d2
to
750621e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://higress.cn/docs/ebook/wasm16/#3-envoy-%E5%B1%9E%E6%80%A7attributes
需要同步更新一下sdk文档,另外 attribute 可能跟 envoy 的 attribute 混淆,叫 userAttribute 可能好一些
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
扩展SDK,支持在插件中向access_log中增加自定义的扩展字段,字段值为
custom_log
,可以跨插件调用接口对访问日志进行扩展,附加使用demo。