过滤无价值日志并实现最近24小时倒序分页查询
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-09 01:06:45 +08:00
1 parent 161bc3a345
commit bb4ac4d5f5
20 files changed
+765 -132

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
package logstore
import (
"encoding/json"
"strings"
"git.pcux.cn/xuans/Smail/utils/logpolicy"
)
// emptyEntry 只丢弃没有事件、对象、结果或有效载荷的空记录。
// 已知业务动作(包括无字段变化的配置审计)、失败和未知结果均不去重或省略。
func emptyEntry(entry Entry) bool {
if !logpolicy.EmptyMessage(entry.Action) || strings.TrimSpace(entry.ActorID) != "" || strings.TrimSpace(entry.Section) != "" || strings.TrimSpace(entry.Result) != "" {
return false
}
var payload any
if json.Unmarshal(entry.Payload, &payload) != nil {
return false
}
switch value := payload.(type) {
case nil:
return true
case string:
return logpolicy.EmptyMessage(value)
case []any:
return len(value) == 0
case map[string]any:
if len(value) == 0 {
return true
}
// 只理解单一消息字段,其他键即使值为空也可能是状态证据。
if len(value) == 1 {
message, ok := value["message"].(string)
return ok && logpolicy.EmptyMessage(message)
}
}
return false
}
+3
View File
@@ -106,6 +106,9 @@ func (s *Store) Write(ctx context.Context, entry Entry) error {
if entry.CreatedAt.Before(logpolicy.Cutoff(s.now())) {
return nil
}
if emptyEntry(entry) {
return nil
}
if entry.ID == "" {
var token [16]byte
if _, err := rand.Read(token[:]); err != nil {