From f15f2b95b37aa5ea2111d597c7285ec10e4fcb02 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Mon, 4 Dec 2023 13:41:50 -0500 Subject: [PATCH] Count Snapshot upgrades --- snapshot/store.go | 4 ++++ snapshot/upgrader.go | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/snapshot/store.go b/snapshot/store.go index 1d597110..d6a0705e 100644 --- a/snapshot/store.go +++ b/snapshot/store.go @@ -21,6 +21,8 @@ import ( const ( persistSize = "latest_persist_size" persistDuration = "latest_persist_duration" + upgradeOk = "upgrade_ok" + upgradeFail = "upgrade_fail" ) const ( @@ -41,6 +43,8 @@ func ResetStats() { stats.Init() stats.Add(persistSize, 0) stats.Add(persistDuration, 0) + stats.Add(upgradeOk, 0) + stats.Add(upgradeFail, 0) } // LockingSink is a wrapper around a SnapshotSink that ensures that the diff --git a/snapshot/upgrader.go b/snapshot/upgrader.go index ae85d2a5..154210a6 100644 --- a/snapshot/upgrader.go +++ b/snapshot/upgrader.go @@ -21,7 +21,12 @@ const ( // Upgrade writes a copy of the 7.x-format Snapshot dircectory at 'old' to a // new Snapshot directory at 'new'. If the upgrade is successful, the // 'old' directory is removed before the function returns. -func Upgrade(old, new string, logger *log.Logger) error { +func Upgrade(old, new string, logger *log.Logger) (retErr error) { + defer func() { + if retErr != nil { + stats.Add(upgradeFail, 1) + } + }() newTmpDir := tmpName(new) // If a temporary version of the new snapshot exists, remove it. This implies a @@ -138,6 +143,7 @@ func Upgrade(old, new string, logger *log.Logger) error { return fmt.Errorf("failed to remove old snapshot directory %s: %s", old, err) } logger.Printf("upgraded snapshot directory %s to %s", old, new) + stats.Add(upgradeOk, 1) return nil }