insert restoreEnd event into deferred func (#3400)
move the end-of-op notification event to a defer within backup/restore.Do(). This ensures we'll get the end event data even in case of failure. --- #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🐛 Bugfix - [x] 🤖 Supportability/Tests #### Issue(s) * #3388 #### Test Plan
This commit is contained in:
parent
5995e7aff6
commit
695f8060da
@ -170,6 +170,22 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) {
|
|||||||
events.BackupID: op.Results.BackupID,
|
events.BackupID: op.Results.BackupID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
op.bus.Event(
|
||||||
|
ctx,
|
||||||
|
events.BackupEnd,
|
||||||
|
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(),
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
// -----
|
// -----
|
||||||
// Execution
|
// Execution
|
||||||
// -----
|
// -----
|
||||||
@ -871,19 +887,5 @@ func (op *BackupOperation) createBackupModels(
|
|||||||
return clues.Wrap(err, "creating backup model").WithClues(ctx)
|
return clues.Wrap(err, "creating backup model").WithClues(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
op.bus.Event(
|
|
||||||
ctx,
|
|
||||||
events.BackupEnd,
|
|
||||||
map[string]any{
|
|
||||||
events.BackupID: b.ID,
|
|
||||||
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(),
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -140,6 +140,25 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De
|
|||||||
"service", op.Selectors.Service,
|
"service", op.Selectors.Service,
|
||||||
"destination_container", clues.Hide(op.Destination.ContainerName))
|
"destination_container", clues.Hide(op.Destination.ContainerName))
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
op.bus.Event(
|
||||||
|
ctx,
|
||||||
|
events.RestoreEnd,
|
||||||
|
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(),
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
// -----
|
// -----
|
||||||
// Execution
|
// Execution
|
||||||
// -----
|
// -----
|
||||||
@ -283,24 +302,6 @@ func (op *RestoreOperation) persistResults(
|
|||||||
|
|
||||||
op.Results.ItemsWritten = opStats.gc.Successes
|
op.Results.ItemsWritten = opStats.gc.Successes
|
||||||
|
|
||||||
op.bus.Event(
|
|
||||||
ctx,
|
|
||||||
events.RestoreEnd,
|
|
||||||
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(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return op.Errors.Failure()
|
return op.Errors.Failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -458,7 +458,7 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RestoreOpIntegrationSuite) TestRestore_Run_errorNoResults() {
|
func (suite *RestoreOpIntegrationSuite) TestRestore_Run_errorNoBackup() {
|
||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
@ -495,6 +495,7 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run_errorNoResults() {
|
|||||||
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.Zero(t, mb.TimesCalled[events.RestoreStart], "restore-start events")
|
// no restore start, because we'd need to find the backup first.
|
||||||
assert.Zero(t, mb.TimesCalled[events.RestoreEnd], "restore-end events")
|
assert.Equal(t, 0, mb.TimesCalled[events.RestoreStart], "restore-start events")
|
||||||
|
assert.Equal(t, 1, mb.TimesCalled[events.RestoreEnd], "restore-end events")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user