handle error conditions
This commit is contained in:
parent
78347af93e
commit
492c02e758
@ -32,7 +32,6 @@ const (
|
|||||||
RepoConnect = "Repo Connect"
|
RepoConnect = "Repo Connect"
|
||||||
BackupEnd = "Backup End"
|
BackupEnd = "Backup End"
|
||||||
RestoreEnd = "Restore End"
|
RestoreEnd = "Restore End"
|
||||||
CorsoError = "Corso Error"
|
|
||||||
ExportEnd = "Export End"
|
ExportEnd = "Export End"
|
||||||
MaintenanceEnd = "Maintenance End"
|
MaintenanceEnd = "Maintenance End"
|
||||||
|
|
||||||
@ -53,6 +52,7 @@ const (
|
|||||||
StartTime = "start_time"
|
StartTime = "start_time"
|
||||||
Status = "status"
|
Status = "status"
|
||||||
Command = "command"
|
Command = "command"
|
||||||
|
ErrorMessage = "error"
|
||||||
|
|
||||||
// default values for keys
|
// default values for keys
|
||||||
RepoIDNotFound = "not_found"
|
RepoIDNotFound = "not_found"
|
||||||
|
|||||||
@ -248,34 +248,25 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) {
|
|||||||
"disable_assist_backup", op.disableAssistBackup)
|
"disable_assist_backup", op.disableAssistBackup)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
data := map[string]any{
|
||||||
|
events.BackupID: op.Results.BackupID,
|
||||||
|
events.DataStored: op.Results.BytesUploaded,
|
||||||
|
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
||||||
|
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
||||||
|
events.Resources: op.Results.ResourceOwners,
|
||||||
|
events.Service: op.Selectors.PathService().String(),
|
||||||
|
events.StartTime: dttm.Format(op.Results.StartedAt),
|
||||||
|
events.Status: op.Status.String(),
|
||||||
|
}
|
||||||
|
|
||||||
if op.Errors.Failure() != nil {
|
if op.Errors.Failure() != nil {
|
||||||
op.bus.Event(
|
data[events.ErrorMessage] = op.Errors.Errors().Failure.Msg
|
||||||
ctx,
|
|
||||||
events.CorsoError,
|
|
||||||
map[string]any{
|
|
||||||
events.Resources: op.ResourceOwner.ID(),
|
|
||||||
events.ResourcesName: op.ResourceOwner.Name(),
|
|
||||||
events.Service: op.Selectors.PathService().String(),
|
|
||||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
|
||||||
events.Status: op.Status.String(),
|
|
||||||
events.BackupID: op.Results.BackupID,
|
|
||||||
events.Command: "Backup",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
op.bus.Event(
|
op.bus.Event(
|
||||||
ctx,
|
ctx,
|
||||||
events.BackupEnd,
|
events.BackupEnd,
|
||||||
map[string]any{
|
data)
|
||||||
events.BackupID: op.Results.BackupID,
|
|
||||||
events.DataStored: op.Results.BytesUploaded,
|
|
||||||
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
|
||||||
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
|
||||||
events.Resources: op.Results.ResourceOwners,
|
|
||||||
events.Service: op.Selectors.PathService().String(),
|
|
||||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
|
||||||
events.Status: op.Status.String(),
|
|
||||||
})
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// -----
|
// -----
|
||||||
|
|||||||
@ -144,35 +144,28 @@ func (op *ExportOperation) Run(ctx context.Context) (
|
|||||||
"service", op.Selectors.Service)
|
"service", op.Selectors.Service)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
data := map[string]any{
|
||||||
|
events.BackupID: op.BackupID,
|
||||||
|
events.DataRetrieved: op.Results.BytesRead,
|
||||||
|
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
||||||
|
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
||||||
|
events.ItemsRead: op.Results.ItemsRead,
|
||||||
|
events.ItemsWritten: op.Results.ItemsWritten,
|
||||||
|
events.Resources: op.Results.ResourceOwners,
|
||||||
|
events.ExportID: opStats.exportID,
|
||||||
|
events.Service: op.Selectors.Service.String(),
|
||||||
|
events.StartTime: dttm.Format(op.Results.StartedAt),
|
||||||
|
events.Status: op.Status.String(),
|
||||||
|
}
|
||||||
|
|
||||||
if op.Errors.Failure() != nil {
|
if op.Errors.Failure() != nil {
|
||||||
op.bus.Event(
|
data[events.ErrorMessage] = op.Errors.Errors()
|
||||||
ctx,
|
|
||||||
events.CorsoError,
|
|
||||||
map[string]any{
|
|
||||||
events.Service: op.Selectors.PathService().String(),
|
|
||||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
|
||||||
events.Status: op.Status.String(),
|
|
||||||
events.BackupID: op.BackupID,
|
|
||||||
events.Command: "Export",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
op.bus.Event(
|
op.bus.Event(
|
||||||
ctx,
|
ctx,
|
||||||
events.ExportEnd,
|
events.ExportEnd,
|
||||||
map[string]any{
|
data)
|
||||||
events.BackupID: op.BackupID,
|
|
||||||
events.DataRetrieved: op.Results.BytesRead,
|
|
||||||
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
|
||||||
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
|
||||||
events.ItemsRead: op.Results.ItemsRead,
|
|
||||||
events.ItemsWritten: op.Results.ItemsWritten,
|
|
||||||
events.Resources: op.Results.ResourceOwners,
|
|
||||||
events.ExportID: opStats.exportID,
|
|
||||||
events.Service: op.Selectors.Service.String(),
|
|
||||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
|
||||||
events.Status: op.Status.String(),
|
|
||||||
})
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// -----
|
// -----
|
||||||
|
|||||||
@ -58,28 +58,22 @@ func (op *MaintenanceOperation) Run(ctx context.Context) (err error) {
|
|||||||
op.Results.StartedAt = time.Now()
|
op.Results.StartedAt = time.Now()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
data := map[string]any{
|
||||||
|
events.StartTime: op.Results.StartedAt,
|
||||||
|
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
||||||
|
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
||||||
|
events.Status: op.Status.String(),
|
||||||
|
events.Resources: op.mOpts.Type.String(),
|
||||||
|
}
|
||||||
|
|
||||||
if op.Errors.Failure() != nil {
|
if op.Errors.Failure() != nil {
|
||||||
op.bus.Event(
|
data[events.ErrorMessage] = op.Errors.Errors()
|
||||||
ctx,
|
|
||||||
events.CorsoError,
|
|
||||||
map[string]any{
|
|
||||||
events.Resources: op.mOpts.Type.String(),
|
|
||||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
|
||||||
events.Status: op.Status.String(),
|
|
||||||
events.Command: "Maintenance",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
op.bus.Event(
|
op.bus.Event(
|
||||||
ctx,
|
ctx,
|
||||||
events.MaintenanceEnd,
|
events.MaintenanceEnd,
|
||||||
map[string]any{
|
data)
|
||||||
events.StartTime: op.Results.StartedAt,
|
|
||||||
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
|
||||||
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
|
||||||
events.Status: op.Status.String(),
|
|
||||||
events.Resources: op.mOpts.Type.String(),
|
|
||||||
})
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return op.do(ctx)
|
return op.do(ctx)
|
||||||
|
|||||||
@ -146,35 +146,28 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De
|
|||||||
"destination_container", clues.Hide(op.RestoreCfg.Location))
|
"destination_container", clues.Hide(op.RestoreCfg.Location))
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
data := map[string]any{
|
||||||
|
events.BackupID: op.BackupID,
|
||||||
|
events.DataRetrieved: op.Results.BytesRead,
|
||||||
|
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
||||||
|
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
||||||
|
events.ItemsRead: op.Results.ItemsRead,
|
||||||
|
events.ItemsWritten: op.Results.ItemsWritten,
|
||||||
|
events.Resources: op.Results.ResourceOwners,
|
||||||
|
events.RestoreID: opStats.restoreID,
|
||||||
|
events.Service: op.Selectors.Service.String(),
|
||||||
|
events.StartTime: dttm.Format(op.Results.StartedAt),
|
||||||
|
events.Status: op.Status.String(),
|
||||||
|
}
|
||||||
|
|
||||||
if op.Errors.Failure() != nil {
|
if op.Errors.Failure() != nil {
|
||||||
op.bus.Event(
|
data[events.ErrorMessage] = op.Errors.Errors()
|
||||||
ctx,
|
|
||||||
events.CorsoError,
|
|
||||||
map[string]any{
|
|
||||||
events.Service: op.Selectors.PathService().String(),
|
|
||||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
|
||||||
events.Status: op.Status.String(),
|
|
||||||
events.BackupID: op.BackupID,
|
|
||||||
events.Command: "Restore",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
op.bus.Event(
|
op.bus.Event(
|
||||||
ctx,
|
ctx,
|
||||||
events.RestoreEnd,
|
events.RestoreEnd,
|
||||||
map[string]any{
|
data)
|
||||||
events.BackupID: op.BackupID,
|
|
||||||
events.DataRetrieved: op.Results.BytesRead,
|
|
||||||
events.Duration: op.Results.CompletedAt.Sub(op.Results.StartedAt),
|
|
||||||
events.EndTime: dttm.Format(op.Results.CompletedAt),
|
|
||||||
events.ItemsRead: op.Results.ItemsRead,
|
|
||||||
events.ItemsWritten: op.Results.ItemsWritten,
|
|
||||||
events.Resources: op.Results.ResourceOwners,
|
|
||||||
events.RestoreID: opStats.restoreID,
|
|
||||||
events.Service: op.Selectors.Service.String(),
|
|
||||||
events.StartTime: dttm.Format(op.Results.StartedAt),
|
|
||||||
events.Status: op.Status.String(),
|
|
||||||
})
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// -----
|
// -----
|
||||||
|
|||||||
@ -366,6 +366,5 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run_errorNoBackup() {
|
|||||||
require.Nil(t, ds, "restoreOp.Run() should not produce details")
|
require.Nil(t, ds, "restoreOp.Run() should not produce details")
|
||||||
assert.Zero(t, ro.Results.ResourceOwners, "resource owners")
|
assert.Zero(t, ro.Results.ResourceOwners, "resource owners")
|
||||||
assert.Zero(t, ro.Results.BytesRead, "bytes read")
|
assert.Zero(t, ro.Results.BytesRead, "bytes read")
|
||||||
assert.Equal(t, 1, mb.TimesCalled[events.CorsoError], "corso-error events")
|
|
||||||
assert.Equal(t, 1, mb.TimesCalled[events.RestoreEnd], "restore-end events")
|
assert.Equal(t, 1, mb.TimesCalled[events.RestoreEnd], "restore-end events")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -226,7 +226,6 @@ func (suite *ExchangeBackupIntgSuite) TestBackup_Run_exchange() {
|
|||||||
assert.Equal(t, bo.Results.ResourceOwners, incBO.Results.ResourceOwners, "incremental backup resource owner")
|
assert.Equal(t, bo.Results.ResourceOwners, incBO.Results.ResourceOwners, "incremental backup resource owner")
|
||||||
assert.NoError(t, incBO.Errors.Failure(), "incremental non-recoverable error", clues.ToCore(bo.Errors.Failure()))
|
assert.NoError(t, incBO.Errors.Failure(), "incremental non-recoverable error", clues.ToCore(bo.Errors.Failure()))
|
||||||
assert.Empty(t, incBO.Errors.Recovered(), "count incremental recoverable/iteration errors")
|
assert.Empty(t, incBO.Errors.Recovered(), "count incremental recoverable/iteration errors")
|
||||||
assert.Equal(t, 0, incMB.TimesCalled[events.CorsoError], "corso error events")
|
|
||||||
assert.Equal(t, 1, incMB.TimesCalled[events.BackupEnd], "incremental backup-end events")
|
assert.Equal(t, 1, incMB.TimesCalled[events.BackupEnd], "incremental backup-end events")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user