Skip to content

Commit

Permalink
fix overwrite cache bug in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ysysys3074 committed Mar 12, 2024
1 parent 1d2e305 commit 473d03b
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
18 changes: 18 additions & 0 deletions flyteadmin/pkg/manager/impl/execution_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,24 @@ func (m *ExecutionManager) GetExecution(
return nil, transformerErr
}

// replace OverwriteCache data in execution spec with data from launch plan spec, this will help to correct overwrite cache label in UI
executionSpec := execution.Spec
launchPlanModel, err := util.GetLaunchPlanModel(ctx, m.db, *executionSpec.LaunchPlan)
if err != nil {
logger.Debugf(ctx, "Failed to get launch plan model for execution %+v with err %v", execution, err)
return nil, err
}
launchPlan, err := transformers.FromLaunchPlanModel(launchPlanModel)
if err != nil {
logger.Debugf(ctx, "Failed to transform launch plan model %+v with err %v", launchPlanModel, err)
return nil, err
}
logger.Infof(ctx, "Before update: launchPlan %v, launchPlan.Spec %v, launchPlan.Spec.GetOverwriteCache() %v", launchPlan, launchPlan.Spec, launchPlan.Spec.GetOverwriteCache())
if !executionSpec.GetOverwriteCache() && launchPlan.Spec.GetOverwriteCache() {
executionSpec.OverwriteCache = launchPlan.Spec.GetOverwriteCache()
}
logger.Infof(ctx, "After update executionSpec %v, executionSpec.OverwriteCache %v", executionSpec, executionSpec.OverwriteCache)

return execution, nil
}

Expand Down
63 changes: 63 additions & 0 deletions flyteadmin/pkg/manager/impl/execution_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,69 @@ func TestGetExecution(t *testing.T) {
assert.True(t, proto.Equal(&closure, execution.Closure))
}

func TestGetExecutionOverwriteCache(t *testing.T) {
repository := repositoryMocks.NewMockRepository()
startedAt := time.Date(2018, 8, 30, 0, 0, 0, 0, time.UTC)
executionGetFunc := func(ctx context.Context, input interfaces.Identifier) (models.Execution, error) {
assert.Equal(t, "project", input.Project)
assert.Equal(t, "domain", input.Domain)
assert.Equal(t, "name", input.Name)
return models.Execution{
BaseModel: models.BaseModel{
CreatedAt: testutils.MockCreatedAtValue,
},
ExecutionKey: models.ExecutionKey{
Project: "project",
Domain: "domain",
Name: "name",
},
Spec: getExpectedSpecBytes(),
Phase: phase,
Closure: closureBytes,
LaunchPlanID: uint(1),
WorkflowID: uint(2),
StartedAt: &startedAt,
// TODO: Input uri
}, nil
}

lpSpec := testutils.GetSampleLpSpecForTest()
lpSpec.OverwriteCache = true
lpSpecBytes, _ := proto.Marshal(&lpSpec)
lpClosure := admin.LaunchPlanClosure{
ExpectedInputs: lpSpec.DefaultInputs,
}
lpClosureBytes, _ := proto.Marshal(&lpClosure)
lpGetFunc := func(input interfaces.Identifier) (models.LaunchPlan, error) {
lpModel := models.LaunchPlan{
LaunchPlanKey: models.LaunchPlanKey{
Project: input.Project,
Domain: input.Domain,
Name: input.Name,
Version: input.Version,
},
BaseModel: models.BaseModel{
ID: uint(100),
},
Spec: lpSpecBytes,
Closure: lpClosureBytes,
}
return lpModel, nil
}

repository.ExecutionRepo().(*repositoryMocks.MockExecutionRepo).SetGetCallback(executionGetFunc)
repository.LaunchPlanRepo().(*repositoryMocks.MockLaunchPlanRepo).SetGetCallback(lpGetFunc)
r := plugins.NewRegistry()
r.RegisterDefault(plugins.PluginIDWorkflowExecutor, &defaultTestExecutor)
execManager := NewExecutionManager(repository, r, getMockExecutionsConfigProvider(), getMockStorageForExecTest(context.Background()), mockScope.NewTestScope(), mockScope.NewTestScope(), &mockPublisher, mockExecutionRemoteURL, nil, nil, nil, nil, &eventWriterMocks.WorkflowExecutionEventWriter{})
execution, err := execManager.GetExecution(context.Background(), admin.WorkflowExecutionGetRequest{
Id: &executionIdentifier,
})
assert.NoError(t, err)
assert.True(t, proto.Equal(&executionIdentifier, execution.Id))
assert.Equal(t, execution.Spec.OverwriteCache, true)
}

func TestGetExecution_DatabaseError(t *testing.T) {
repository := repositoryMocks.NewMockRepository()
expectedErr := errors.New("expected error")
Expand Down

0 comments on commit 473d03b

Please sign in to comment.