Skip to content

Commit 7cf54c1

Browse files
committed
telemetry: Use sync/atomic#Pointer instead of our own wrapper
Go 1.19 introduced `sync/atomic#Pointer` among other things, so we no longer need to use the Atomic wrapper from our Icinga Go library.
1 parent d28fa55 commit 7cf54c1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

cmd/icingadb/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func run() int {
116116
ha = icingadb.NewHA(ctx, db, heartbeat, logs.GetChildLogger("high-availability"))
117117

118118
telemetryLogger := logs.GetChildLogger("telemetry")
119+
telemetry.LastSuccessfulSync.Store(&telemetry.SuccessfulSync{})
119120
telemetry.StartHeartbeat(ctx, rc, telemetryLogger, ha, heartbeat)
120121
telemetry.WriteStats(ctx, rc, telemetryLogger)
121122
}
@@ -250,7 +251,7 @@ func run() int {
250251
logger := logs.GetChildLogger("config-sync")
251252

252253
if synctx.Err() == nil {
253-
telemetry.LastSuccessfulSync.Store(telemetry.SuccessfulSync{
254+
telemetry.LastSuccessfulSync.Store(&telemetry.SuccessfulSync{
254255
FinishMilli: syncEnd.UnixMilli(),
255256
DurationMilli: elapsed.Milliseconds(),
256257
})

pkg/icingaredis/telemetry/heartbeat.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package telemetry
33
import (
44
"context"
55
"fmt"
6-
"github.com/icinga/icinga-go-library/com"
76
"github.com/icinga/icinga-go-library/logging"
87
"github.com/icinga/icinga-go-library/periodic"
98
"github.com/icinga/icinga-go-library/redis"
@@ -81,7 +80,7 @@ func GetCurrentDbConnErr() (string, int64) {
8180
var OngoingSyncStartMilli int64
8281

8382
// LastSuccessfulSync is to be updated by the main() function.
84-
var LastSuccessfulSync com.Atomic[SuccessfulSync]
83+
var LastSuccessfulSync atomic.Pointer[SuccessfulSync]
8584

8685
var boolToStr = map[bool]string{false: "0", true: "1"}
8786
var startTime = time.Now().UnixMilli()
@@ -101,7 +100,7 @@ func StartHeartbeat(
101100
heartbeat := heartbeat.LastReceived()
102101
responsibleTsMilli, responsible, otherResponsible := ha.State()
103102
ongoingSyncStart := atomic.LoadInt64(&OngoingSyncStartMilli)
104-
sync, _ := LastSuccessfulSync.Load()
103+
lastSync := LastSuccessfulSync.Load()
105104
dbConnErr, dbConnErrSinceMilli := GetCurrentDbConnErr()
106105
now := time.Now()
107106

@@ -117,8 +116,8 @@ func StartHeartbeat(
117116
"ha-responsible-ts": strconv.FormatInt(responsibleTsMilli, 10),
118117
"ha-other-responsible": boolToStr[otherResponsible],
119118
"sync-ongoing-since": strconv.FormatInt(ongoingSyncStart, 10),
120-
"sync-success-finish": strconv.FormatInt(sync.FinishMilli, 10),
121-
"sync-success-duration": strconv.FormatInt(sync.DurationMilli, 10),
119+
"sync-success-finish": strconv.FormatInt(lastSync.FinishMilli, 10),
120+
"sync-success-duration": strconv.FormatInt(lastSync.DurationMilli, 10),
122121
}
123122

124123
ctx, cancel := context.WithDeadline(ctx, tick.Time.Add(interval))

0 commit comments

Comments
 (0)