feat(server): online session history with configurable stats window (#1243)

Add persisted online sessions, configurable retention and online history statistics with lifecycle, recovery, timezone and concurrency regression coverage.

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
Sam5440andnaiba/CloudCode authored and GitHub committed 2026-10-16 19:25:13 +08:00
1 parent 9881c47f0c
commit 8721a15b12
22 files changed
+2242 -20

No files matched your search

+13 -6
View File
@@ -12,7 +12,6 @@ import (
"os"
"runtime/debug"
"strings"
"time"
_ "time/tzdata"
"github.com/gin-gonic/gin"
@@ -78,6 +77,16 @@ func initSystem(bus chan<- *model.Service) error {
return err
}
// 在线会话兜底清扫:状态流异常断开(失联)时由这里关闭进行中的会话
if _, err := singleton.CronShared.AddFunc("@every 30s", singleton.SweepOnlineSessions); err != nil {
return err
}
// 在线会话保留清理:超出后台设置的统计窗口后删除
if _, err := singleton.CronShared.AddFunc("0 30 4 * * *", singleton.PruneOnlineSessions); err != nil {
return err
}
if err := singleton.StartJWTSessionGC(); err != nil {
return err
}
@@ -172,10 +181,8 @@ func main() {
wireNATDashboardCredentialGate()
muxHandler := newHTTPandGRPCMux(httpHandler, grpcHandler)
muxServerHTTP := &http.Server{
Handler: muxHandler,
ReadHeaderTimeout: time.Second * 5,
}
muxServerHTTP := newDashboardHTTPServer(muxHandler)
muxServerHTTP.Protocols = new(http.Protocols)
muxServerHTTP.Protocols.SetHTTP1(true)
muxServerHTTP.Protocols.SetUnencryptedHTTP2(true)
@@ -183,9 +190,9 @@ func main() {
var muxServerHTTPS *http.Server
if singleton.Conf.HTTPS.ListenPort != 0 {
muxServerHTTPS = &http.Server{
ReadHeaderTimeout: dashboardReadHeaderTimeout,
Addr: fmt.Sprintf("%s:%d", singleton.Conf.ListenHost, singleton.Conf.HTTPS.ListenPort),
Handler: muxHandler,
ReadHeaderTimeout: time.Second * 5,
TLSConfig: &tls.Config{
InsecureSkipVerify: singleton.Conf.HTTPS.InsecureTLS,
},