[MM-62897] Compliance export backwards compatibility (#30120)

* add backwards compatibility for <10.5

* test: backwards compatibility for <10.5

* spelling
This commit is contained in:
Christopher Poile 2025-02-05 16:20:28 -05:00 committed by GitHub
parent 1ce29f8466
commit 8b65771a31
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 66 additions and 0 deletions

View File

@ -327,6 +327,12 @@ func (w *MessageExportWorker) initJobData(logger mlog.LoggerIFace, job *model.Jo
if previousJob.Data == nil { if previousJob.Data == nil {
previousJob.Data = make(map[string]string) previousJob.Data = make(map[string]string)
} }
// Backwards compatibility for <10.5:
if batchStartTimestamp, prevExists := previousJob.Data["batch_start_timestamp"]; prevExists {
previousJob.Data[shared.JobDataBatchStartTime] = batchStartTimestamp
}
if _, prevExists := previousJob.Data[shared.JobDataBatchStartTime]; !prevExists { if _, prevExists := previousJob.Data[shared.JobDataBatchStartTime]; !prevExists {
exportFromTimestamp := strconv.FormatInt(*w.jobServer.Config().MessageExportSettings.ExportFromTimestamp, 10) exportFromTimestamp := strconv.FormatInt(*w.jobServer.Config().MessageExportSettings.ExportFromTimestamp, 10)
logger.Info("Worker: Previously successful job lacks job data, falling back to configured MessageExportSettings.ExportFromTimestamp", mlog.String("export_from_timestamp", exportFromTimestamp)) logger.Info("Worker: Previously successful job lacks job data, falling back to configured MessageExportSettings.ExportFromTimestamp", mlog.String("export_from_timestamp", exportFromTimestamp))

View File

@ -188,6 +188,66 @@ func TestInitJobDataPreviousJobWithJobData(t *testing.T) {
assert.Equal(t, expectedDir, job.Data[shared.JobDataExportDir]) assert.Equal(t, expectedDir, job.Data[shared.JobDataExportDir])
} }
func TestInitJobDataPreviousJobWithJobDataPre105(t *testing.T) {
logger := mlog.CreateConsoleTestLogger(t)
mockStore := &storetest.Store{}
defer mockStore.AssertExpectations(t)
previousJob := &model.Job{
Id: st.NewTestID(),
CreateAt: model.GetMillis(),
Status: model.JobStatusSuccess,
Type: model.JobTypeMessageExport,
StartAt: model.GetMillis() - 1000,
LastActivityAt: model.GetMillis() - 1000,
Data: map[string]string{"batch_start_timestamp": "123"},
}
job := &model.Job{
Id: st.NewTestID(),
CreateAt: model.GetMillis(),
Status: model.JobStatusPending,
Type: model.JobTypeMessageExport,
Data: map[string]string{shared.JobDataExportDir: "this-is-the-export-dir"},
}
// mock job store returns a previously successful job that has the config that we're looking for, so we use it
mockStore.JobStore.On("GetNewestJobByStatusesAndType", []string{model.JobStatusWarning, model.JobStatusSuccess}, model.JobTypeMessageExport).Return(previousJob, nil)
worker := &MessageExportWorker{
jobServer: &jobs.JobServer{
Store: mockStore,
ConfigService: &testutils.StaticConfigService{
Cfg: &model.Config{
// mock config
MessageExportSettings: model.MessageExportSettings{
EnableExport: model.NewPointer(true),
ExportFormat: model.NewPointer(model.ComplianceExportTypeActiance),
DailyRunTime: model.NewPointer("01:00"),
ExportFromTimestamp: model.NewPointer(int64(0)),
BatchSize: model.NewPointer(10000),
ChannelBatchSize: model.NewPointer(100),
ChannelHistoryBatchSize: model.NewPointer(100),
},
},
},
},
logger: logger,
}
now := time.Now()
worker.initJobData(logger, job, now)
assert.Equal(t, model.ComplianceExportTypeActiance, job.Data[shared.JobDataExportType])
assert.Equal(t, strconv.Itoa(*worker.jobServer.Config().MessageExportSettings.BatchSize), job.Data[shared.JobDataBatchSize])
// Assert the new job picks up the <10.5 job start time:
assert.Equal(t, previousJob.Data[shared.JobDataBatchStartTime], job.Data[shared.JobDataBatchStartTime])
expectedDir := "this-is-the-export-dir"
assert.Equal(t, expectedDir, job.Data[shared.JobDataExportDir])
}
func TestDoJobNoPostsToExport(t *testing.T) { func TestDoJobNoPostsToExport(t *testing.T) {
logger := mlog.CreateConsoleTestLogger(t) logger := mlog.CreateConsoleTestLogger(t)