mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-06 23:56:37 +08:00
fix(logs): flush small access-log batches within two seconds
Default MinBatchSize of 50 left quiet admin traffic in memory forever because MaxFlushWait was unset. Force a timed flush so the logs page can show recent authenticated requests.
This commit is contained in:
@@ -13,8 +13,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fallbackLogEngine 是日志库状态不可得时对外暴露的引擎标识。
|
const (
|
||||||
const fallbackLogEngine = "sqlite"
|
// fallbackLogEngine 是日志库状态不可得时对外暴露的引擎标识。
|
||||||
|
fallbackLogEngine = "sqlite"
|
||||||
|
// accessLogMaxFlushWait 强制把不足 MinBatchSize 的访问日志刷盘,避免管理台低频访问永远看不到记录。
|
||||||
|
accessLogMaxFlushWait = 2 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logWriterMu sync.RWMutex
|
logWriterMu sync.RWMutex
|
||||||
@@ -30,6 +34,7 @@ func InitLogWriter(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg := batchwriter.DefaultConfig()
|
cfg := batchwriter.DefaultConfig()
|
||||||
|
cfg.MaxFlushWait = accessLogMaxFlushWait
|
||||||
writer, err := batchwriter.New[*logstore.UserAccessLog](cfg, writeAccessLogBatch,
|
writer, err := batchwriter.New[*logstore.UserAccessLog](cfg, writeAccessLogBatch,
|
||||||
batchwriter.WithDropHandler[*logstore.UserAccessLog](func(item *logstore.UserAccessLog) {
|
batchwriter.WithDropHandler[*logstore.UserAccessLog](func(item *logstore.UserAccessLog) {
|
||||||
path := ""
|
path := ""
|
||||||
|
|||||||
Reference in New Issue
Block a user