From 7cf54c1b252e31f2764c0dc2f7c4a794e660c131 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 24 Oct 2024 10:37:04 +0200 Subject: [PATCH] `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. --- cmd/icingadb/main.go | 3 ++- pkg/icingaredis/telemetry/heartbeat.go | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/icingadb/main.go b/cmd/icingadb/main.go index bd94686d7..dc0098aba 100644 --- a/cmd/icingadb/main.go +++ b/cmd/icingadb/main.go @@ -116,6 +116,7 @@ func run() int { ha = icingadb.NewHA(ctx, db, heartbeat, logs.GetChildLogger("high-availability")) telemetryLogger := logs.GetChildLogger("telemetry") + telemetry.LastSuccessfulSync.Store(&telemetry.SuccessfulSync{}) telemetry.StartHeartbeat(ctx, rc, telemetryLogger, ha, heartbeat) telemetry.WriteStats(ctx, rc, telemetryLogger) } @@ -250,7 +251,7 @@ func run() int { logger := logs.GetChildLogger("config-sync") if synctx.Err() == nil { - telemetry.LastSuccessfulSync.Store(telemetry.SuccessfulSync{ + telemetry.LastSuccessfulSync.Store(&telemetry.SuccessfulSync{ FinishMilli: syncEnd.UnixMilli(), DurationMilli: elapsed.Milliseconds(), }) diff --git a/pkg/icingaredis/telemetry/heartbeat.go b/pkg/icingaredis/telemetry/heartbeat.go index 041a696d0..61bf44ad0 100644 --- a/pkg/icingaredis/telemetry/heartbeat.go +++ b/pkg/icingaredis/telemetry/heartbeat.go @@ -3,7 +3,6 @@ package telemetry import ( "context" "fmt" - "github.com/icinga/icinga-go-library/com" "github.com/icinga/icinga-go-library/logging" "github.com/icinga/icinga-go-library/periodic" "github.com/icinga/icinga-go-library/redis" @@ -81,7 +80,7 @@ func GetCurrentDbConnErr() (string, int64) { var OngoingSyncStartMilli int64 // LastSuccessfulSync is to be updated by the main() function. -var LastSuccessfulSync com.Atomic[SuccessfulSync] +var LastSuccessfulSync atomic.Pointer[SuccessfulSync] var boolToStr = map[bool]string{false: "0", true: "1"} var startTime = time.Now().UnixMilli() @@ -101,7 +100,7 @@ func StartHeartbeat( heartbeat := heartbeat.LastReceived() responsibleTsMilli, responsible, otherResponsible := ha.State() ongoingSyncStart := atomic.LoadInt64(&OngoingSyncStartMilli) - sync, _ := LastSuccessfulSync.Load() + lastSync := LastSuccessfulSync.Load() dbConnErr, dbConnErrSinceMilli := GetCurrentDbConnErr() now := time.Now() @@ -117,8 +116,8 @@ func StartHeartbeat( "ha-responsible-ts": strconv.FormatInt(responsibleTsMilli, 10), "ha-other-responsible": boolToStr[otherResponsible], "sync-ongoing-since": strconv.FormatInt(ongoingSyncStart, 10), - "sync-success-finish": strconv.FormatInt(sync.FinishMilli, 10), - "sync-success-duration": strconv.FormatInt(sync.DurationMilli, 10), + "sync-success-finish": strconv.FormatInt(lastSync.FinishMilli, 10), + "sync-success-duration": strconv.FormatInt(lastSync.DurationMilli, 10), } ctx, cancel := context.WithDeadline(ctx, tick.Time.Add(interval))