@@ -79,16 +79,17 @@ func GetCurrentDbConnErr() (string, int64) {
7979// OngoingSyncStartMilli is to be updated by the main() function.
8080var OngoingSyncStartMilli int64
8181
82- // LastSuccessfulSync is to be updated by the main() function.
83- var LastSuccessfulSync atomic.Pointer [SuccessfulSync ]
84-
8582var boolToStr = map [bool ]string {false : "0" , true : "1" }
8683var startTime = time .Now ().UnixMilli ()
8784
8885// StartHeartbeat periodically writes heartbeats to Redis for being monitored by Icinga 2.
86+ // It returns an atomic pointer to SuccessfulSync,
87+ // which contains synchronisation statistics that the caller should update.
8988func StartHeartbeat (
9089 ctx context.Context , client * redis.Client , logger * logging.Logger , ha ha , heartbeat * icingaredis.Heartbeat ,
91- ) {
90+ ) * atomic.Pointer [SuccessfulSync ] {
91+ var syncStats atomic.Pointer [SuccessfulSync ]
92+ syncStats .Store (& SuccessfulSync {})
9293 goMetrics := NewGoMetrics ()
9394
9495 const interval = time .Second
@@ -100,7 +101,7 @@ func StartHeartbeat(
100101 heartbeat := heartbeat .LastReceived ()
101102 responsibleTsMilli , responsible , otherResponsible := ha .State ()
102103 ongoingSyncStart := atomic .LoadInt64 (& OngoingSyncStartMilli )
103- lastSync := LastSuccessfulSync .Load ()
104+ lastSync := syncStats .Load ()
104105 dbConnErr , dbConnErrSinceMilli := GetCurrentDbConnErr ()
105106 now := time .Now ()
106107
@@ -144,6 +145,8 @@ func StartHeartbeat(
144145 silenceUntil = time.Time {}
145146 }
146147 })
148+
149+ return & syncStats
147150}
148151
149152type goMetrics struct {
0 commit comments