Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snapshot metrics initialization #223

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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