Skip to content

Commit

Permalink
Fix snapshot metrics initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyas Rao <[email protected]>
  • Loading branch information
shreyas-s-rao authored and Swapnil Mhamane committed May 14, 2020
1 parent e6bdadb commit 87e13fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/server/backuprestoreserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (b *BackupRestoreServer) runEtcdProbeLoopWithSnapshotter(ctx context.Contex
gcStopCh := make(chan struct{})
go ssr.RunGarbageCollector(gcStopCh)
b.logger.Infof("Starting snapshotter...")
startWithFullSnapshot := !(initialDeltaSnapshotTaken && time.Since(ssr.PrevFullSnapshot.CreatedOn).Hours() <= recentFullSnapshotPeriodInHours)
startWithFullSnapshot := ssr.PrevFullSnapshot == nil || !(initialDeltaSnapshotTaken && time.Since(ssr.PrevFullSnapshot.CreatedOn).Hours() <= recentFullSnapshotPeriodInHours)
if err := ssr.Run(ssrStopCh, startWithFullSnapshot); err != nil {
if etcdErr, ok := err.(*errors.EtcdError); ok == true {
b.logger.Errorf("Snapshotter failed with etcd error: %v", etcdErr)
Expand Down
19 changes: 12 additions & 7 deletions pkg/snapshot/snapshotter/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,22 @@ func NewSnapshotter(logger *logrus.Entry, config *Config, store snapstore.SnapSt
return nil, fmt.Errorf("invalid schedule provied %s : %v", config.FullSnapshotSchedule, err)
}

// Create dummy previous snapshot
var prevSnapshot *snapstore.Snapshot
fullSnap, deltaSnapList, err := miscellaneous.GetLatestFullSnapshotAndDeltaSnapList(store)
if err != nil || fullSnap == nil {
prevSnapshot = snapstore.NewSnapshot(snapstore.SnapshotKindFull, 0, 0)
} else if len(deltaSnapList) == 0 {
if err != nil {
return nil, err
} else if fullSnap != nil && len(deltaSnapList) == 0 {
prevSnapshot = fullSnap
metrics.LatestSnapshotTimestamp.With(prometheus.Labels{metrics.LabelKind: prevSnapshot.Kind}).Set(float64(prevSnapshot.CreatedOn.Unix()))
} else {
// setting timestamps of both full and delta to prev full snapshot's timestamp
metrics.LatestSnapshotTimestamp.With(prometheus.Labels{metrics.LabelKind: snapstore.SnapshotKindFull}).Set(float64(prevSnapshot.CreatedOn.Unix()))
metrics.LatestSnapshotTimestamp.With(prometheus.Labels{metrics.LabelKind: snapstore.SnapshotKindDelta}).Set(float64(prevSnapshot.CreatedOn.Unix()))
} else if fullSnap != nil && len(deltaSnapList) != 0 {
prevSnapshot = deltaSnapList[len(deltaSnapList)-1]
metrics.LatestSnapshotTimestamp.With(prometheus.Labels{metrics.LabelKind: prevSnapshot.Kind}).Set(float64(prevSnapshot.CreatedOn.Unix()))
metrics.LatestSnapshotTimestamp.With(prometheus.Labels{metrics.LabelKind: snapstore.SnapshotKindFull}).Set(float64(fullSnap.CreatedOn.Unix()))
metrics.LatestSnapshotTimestamp.With(prometheus.Labels{metrics.LabelKind: snapstore.SnapshotKindDelta}).Set(float64(prevSnapshot.CreatedOn.Unix()))
} else {
// creating dummy previous snapshot since fullSnap == nil
prevSnapshot = snapstore.NewSnapshot(snapstore.SnapshotKindFull, 0, 0)
}

metrics.LatestSnapshotRevision.With(prometheus.Labels{metrics.LabelKind: prevSnapshot.Kind}).Set(float64(prevSnapshot.LastRevision))
Expand Down

0 comments on commit 87e13fb

Please sign in to comment.