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

Add PartiallyFailed phase for restores #1389

Merged
merged 3 commits into from
Apr 25, 2019
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
8 changes: 6 additions & 2 deletions pkg/apis/velero/v1/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ const (
// RestorePhaseInProgress means the restore is currently executing.
RestorePhaseInProgress RestorePhase = "InProgress"

// RestorePhaseCompleted means the restore has finished executing.
// Any relevant warnings or errors will be captured in the Status.
// RestorePhaseCompleted means the restore has run successfully
// without errors.
RestorePhaseCompleted RestorePhase = "Completed"

// RestorePhasePartiallyFailed means the restore has run to completion
// but encountered 1+ errors restoring individual items.
RestorePhasePartiallyFailed RestorePhase = "PartiallyFailed"

// RestorePhaseFailed means the restore was unable to execute.
// The failing error is recorded in status.FailureReason.
RestorePhaseFailed RestorePhase = "Failed"
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/cli/restore/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func NewLogsCommand(f client.Factory) *cobra.Command {
cmd.Exit("Error checking for restore %q: %v", restoreName, err)
}

if restore.Status.Phase != v1.RestorePhaseCompleted && restore.Status.Phase != v1.RestorePhaseFailed {
switch restore.Status.Phase {
case v1.RestorePhaseCompleted, v1.RestorePhaseFailed, v1.RestorePhasePartiallyFailed:
// terminal phases, don't exit.
default:
cmd.Exit("Logs for restore %q are not available until it's finished processing. Please wait "+
"until the restore has a phase of Completed or Failed and try again.", restoreName)
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/cmd/util/output/restore_describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package output
import (
"bytes"
"encoding/json"
"fmt"
"sort"
"strings"

Expand All @@ -35,7 +36,17 @@ func DescribeRestore(restore *v1.Restore, podVolumeRestores []v1.PodVolumeRestor
d.DescribeMetadata(restore.ObjectMeta)

d.Println()
d.Printf("Phase:\t%s\n", restore.Status.Phase)
phase := restore.Status.Phase
if phase == "" {
phase = v1.RestorePhaseNew
}

resultsNote := ""
if phase == v1.RestorePhaseFailed || phase == v1.RestorePhasePartiallyFailed {
resultsNote = fmt.Sprintf(" (run 'velero restore logs %s' for more information)", restore.Name)
}

d.Printf("Phase:\t%s%s\n", restore.Status.Phase, resultsNote)

if len(restore.Status.ValidationErrors) > 0 {
d.Println()
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/restore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ func (c *restoreController) processRestore(restore *api.Restore) error {
restore.Status.Phase = api.RestorePhaseFailed
restore.Status.FailureReason = err.Error()
c.metrics.RegisterRestoreFailed(backupScheduleName)
} else if restore.Status.Errors > 0 {
c.logger.Debug("Restore partially failed")
restore.Status.Phase = api.RestorePhasePartiallyFailed
c.metrics.RegisterRestorePartialFailure(backupScheduleName)
} else {
c.logger.Debug("Restore completed")
restore.Status.Phase = api.RestorePhaseCompleted
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/restore_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func TestProcessQueueItem(t *testing.T) {
restorerError: errors.New("blarg"),
expectedErr: false,
expectedPhase: string(api.RestorePhaseInProgress),
expectedFinalPhase: string(api.RestorePhasePartiallyFailed),
expectedRestoreErrors: 1,
expectedRestorerCall: NewRestore("foo", "bar", "backup-1", "ns-1", "", api.RestorePhaseInProgress).Restore,
},
Expand Down Expand Up @@ -595,7 +596,7 @@ func TestProcessQueueItem(t *testing.T) {
if test.expectedFinalPhase != "" {
expected = Patch{
Status: StatusPatch{
Phase: api.RestorePhaseCompleted,
Phase: api.RestorePhase(test.expectedFinalPhase),
Errors: test.expectedRestoreErrors,
},
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
restoreAttemptTotal = "restore_attempt_total"
restoreValidationFailedTotal = "restore_validation_failed_total"
restoreSuccessTotal = "restore_success_total"
restorePartialFailureTotal = "restore_partial_failure_total"
restoreFailedTotal = "restore_failed_total"
volumeSnapshotAttemptTotal = "volume_snapshot_attempt_total"
volumeSnapshotSuccessTotal = "volume_snapshot_success_total"
Expand Down Expand Up @@ -162,6 +163,14 @@ func NewServerMetrics() *ServerMetrics {
},
[]string{scheduleLabel},
),
restorePartialFailureTotal: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Name: restorePartialFailureTotal,
Help: "Total number of partially failed restores",
},
[]string{scheduleLabel},
),
restoreFailedTotal: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Expand Down Expand Up @@ -236,6 +245,9 @@ func (m *ServerMetrics) InitSchedule(scheduleName string) {
if c, ok := m.metrics[restoreAttemptTotal].(*prometheus.CounterVec); ok {
c.WithLabelValues(scheduleName).Set(0)
}
if c, ok := m.metrics[restorePartialFailureTotal].(*prometheus.CounterVec); ok {
c.WithLabelValues(scheduleName).Set(0)
}
if c, ok := m.metrics[restoreFailedTotal].(*prometheus.CounterVec); ok {
c.WithLabelValues(scheduleName).Set(0)
}
Expand Down Expand Up @@ -346,6 +358,13 @@ func (m *ServerMetrics) RegisterRestoreSuccess(backupSchedule string) {
}
}

// RegisterRestorePartialFailure records a restore that partially failed.
func (m *ServerMetrics) RegisterRestorePartialFailure(backupSchedule string) {
if c, ok := m.metrics[restorePartialFailureTotal].(*prometheus.CounterVec); ok {
c.WithLabelValues(backupSchedule).Inc()
}
}

// RegisterRestoreFailed records a restore that failed.
func (m *ServerMetrics) RegisterRestoreFailed(backupSchedule string) {
if c, ok := m.metrics[restoreFailedTotal].(*prometheus.CounterVec); ok {
Expand Down