mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-11-05 00:50:21 +00:00
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:
1 parent
9881c47f0c
commit
8721a15b12
22 files changed
+2242
-20
No files matched your search
+12
-1
@@ -202,7 +202,15 @@ func (s *NezhaHandler) ReportSystemState(stream pb.NezhaService_ReportSystemStat
|
||||
return errors.New("server not found")
|
||||
}
|
||||
lease := server.AttachStateStream(stream)
|
||||
defer lease.Clear()
|
||||
defer func() {
|
||||
// Persist while owning the lease; a replaced stream must never close a
|
||||
// newer stream's session between Clear and RecordOffline.
|
||||
lease.ClearWithSideEffect(func() {
|
||||
if singleton.OnlineHistoryShared != nil {
|
||||
singleton.OnlineHistoryShared.RecordOffline(clientID, time.Now())
|
||||
}
|
||||
})
|
||||
}()
|
||||
var state *pb.State
|
||||
var stateCount uint64
|
||||
for {
|
||||
@@ -253,6 +261,9 @@ func (s *NezhaHandler) ReportSystemState(stream pb.NezhaService_ReportSystemStat
|
||||
log.Printf("NEZHA>> Failed to write server metrics to TSDB: %v", err)
|
||||
}
|
||||
}
|
||||
if singleton.OnlineHistoryShared != nil {
|
||||
singleton.OnlineHistoryShared.RecordOnline(clientID, lastActive)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if !accepted {
|
||||
|
||||
Reference in new issue
Block a user