Skip to content

Commit c633f76

Browse files
Correct Lint Errors and Add Documentation on Pre-Commit (flyteorg#19)
* README update * Fix lint errors
1 parent 91a82e1 commit c633f76

File tree

6 files changed

+59
-38
lines changed

6 files changed

+59
-38
lines changed

README.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,21 @@ administering workflow executions. Flyteadmin implements the
66
`AdminService <https://github.com/lyft/flyteidl/blob/master/protos/flyteidl/service/admin.proto>`_ which
77
defines a stateless REST/gRPC service for interacting with registered Flyte entities and executions.
88
Flyteadmin uses a relational style Metadata Store abstracted by `GORM <http://gorm.io/>`_ ORM library.
9+
10+
Before Check-In
11+
~~~~~~~~~~~~~~~
12+
13+
Flyte Admin has a few useful make targets for linting and testing. Please use these before checking in to help suss out
14+
minor bugs and linting errors.
15+
16+
.. code-block:: console
17+
18+
make goimports
19+
20+
.. code-block:: console
21+
22+
make test_unit
23+
24+
.. code-block:: console
25+
26+
make lint

pkg/manager/impl/execution_manager.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ func (m *ExecutionManager) offloadInputs(ctx context.Context, literalMap *core.L
159159
if literalMap == nil {
160160
literalMap = &core.LiteralMap{}
161161
}
162-
inputsUri, err := m.storageClient.ConstructReference(ctx, m.storageClient.GetBaseContainerFQN(ctx), shared.Metadata, identifier.Project, identifier.Domain, identifier.Name, key)
162+
inputsURI, err := m.storageClient.ConstructReference(ctx, m.storageClient.GetBaseContainerFQN(ctx), shared.Metadata, identifier.Project, identifier.Domain, identifier.Name, key)
163163
if err != nil {
164164
return "", err
165165
}
166-
if err := m.storageClient.WriteProtobuf(ctx, inputsUri, storage.Options{}, literalMap); err != nil {
166+
if err := m.storageClient.WriteProtobuf(ctx, inputsURI, storage.Options{}, literalMap); err != nil {
167167
return "", err
168168
}
169-
return inputsUri, nil
169+
return inputsURI, nil
170170
}
171171

172172
func (m *ExecutionManager) launchExecutionAndPrepareModel(
@@ -231,11 +231,11 @@ func (m *ExecutionManager) launchExecutionAndPrepareModel(
231231
// Dynamically assign execution queues.
232232
m.populateExecutionQueue(ctx, *workflow.Id, workflow.Closure.CompiledWorkflow)
233233

234-
inputsUri, err := m.offloadInputs(ctx, executionInputs, &workflowExecutionID, shared.Inputs)
234+
inputsURI, err := m.offloadInputs(ctx, executionInputs, &workflowExecutionID, shared.Inputs)
235235
if err != nil {
236236
return nil, err
237237
}
238-
userInputsUri, err := m.offloadInputs(ctx, request.Inputs, &workflowExecutionID, shared.UserInputs)
238+
userInputsURI, err := m.offloadInputs(ctx, request.Inputs, &workflowExecutionID, shared.UserInputs)
239239
if err != nil {
240240
return nil, err
241241
}
@@ -289,8 +289,8 @@ func (m *ExecutionManager) launchExecutionAndPrepareModel(
289289
WorkflowIdentifier: workflow.Id,
290290
ParentNodeExecutionID: parentNodeExecutionID,
291291
Cluster: execInfo.Cluster,
292-
InputsUri: inputsUri,
293-
UserInputsUri: userInputsUri,
292+
InputsURI: inputsURI,
293+
UserInputsURI: userInputsURI,
294294
})
295295
if err != nil {
296296
logger.Infof(ctx, "Failed to create execution model in transformer for id: [%+v] with err: %v",
@@ -359,9 +359,9 @@ func (m *ExecutionManager) RelaunchExecution(
359359
executionSpec.Metadata = &admin.ExecutionMetadata{}
360360
}
361361
var inputs *core.LiteralMap
362-
if len(existingExecutionModel.UserInputsUri) > 0 {
362+
if len(existingExecutionModel.UserInputsURI) > 0 {
363363
inputs = &core.LiteralMap{}
364-
if err := m.storageClient.ReadProtobuf(ctx, existingExecutionModel.UserInputsUri, inputs); err != nil {
364+
if err := m.storageClient.ReadProtobuf(ctx, existingExecutionModel.UserInputsURI, inputs); err != nil {
365365
return nil, err
366366
}
367367
} else {
@@ -428,9 +428,9 @@ func (m *ExecutionManager) emitScheduledWorkflowMetrics(
428428
}
429429

430430
var inputs core.LiteralMap
431-
err = m.storageClient.ReadProtobuf(ctx, storage.DataReference(executionModel.InputsUri), &inputs)
431+
err = m.storageClient.ReadProtobuf(ctx, executionModel.InputsURI, &inputs)
432432
if err != nil {
433-
logger.Errorf(ctx, "Failed to find inputs for emitting schedule delay event from uri: [%v]", executionModel.InputsUri)
433+
logger.Errorf(ctx, "Failed to find inputs for emitting schedule delay event from uri: [%v]", executionModel.InputsURI)
434434
return
435435
}
436436
scheduledKickoffTimeProto := inputs.Literals[launchPlan.Spec.EntityMetadata.Schedule.KickoffTimeInputArg]
@@ -633,16 +633,16 @@ func (m *ExecutionManager) GetExecution(
633633
// TO BE DELETED
634634
// TODO: Remove the publishing to deprecated fields (Inputs) after a smooth migration has been completed of our existing users
635635
// For now, publish to deprecated fields thus ensuring old clients don't break when calling GetExecution
636-
if len(executionModel.InputsUri) > 0 {
636+
if len(executionModel.InputsURI) > 0 {
637637
var inputs core.LiteralMap
638-
if err := m.storageClient.ReadProtobuf(ctx, executionModel.InputsUri, &inputs); err != nil {
638+
if err := m.storageClient.ReadProtobuf(ctx, executionModel.InputsURI, &inputs); err != nil {
639639
return nil, err
640640
}
641641
execution.Closure.ComputedInputs = &inputs
642642
}
643-
if len(executionModel.UserInputsUri) > 0 {
643+
if len(executionModel.UserInputsURI) > 0 {
644644
var userInputs core.LiteralMap
645-
if err := m.storageClient.ReadProtobuf(ctx, executionModel.UserInputsUri, &userInputs); err != nil {
645+
if err := m.storageClient.ReadProtobuf(ctx, executionModel.UserInputsURI, &userInputs); err != nil {
646646
return nil, err
647647
}
648648
execution.Spec.Inputs = &userInputs
@@ -672,29 +672,29 @@ func (m *ExecutionManager) GetExecutionData(
672672
}
673673
}
674674
// Prior to flyteidl v0.15.0, Inputs were held in ExecutionClosure and were not offloaded. Ensure we can return the inputs as expected.
675-
if len(executionModel.InputsUri) == 0 {
675+
if len(executionModel.InputsURI) == 0 {
676676
closure := &admin.ExecutionClosure{}
677677
// We must not use the FromExecutionModel method because it empties deprecated fields.
678678
if err := proto.Unmarshal(executionModel.Closure, closure); err != nil {
679679
return nil, err
680680
}
681-
newInputsUri, err := m.offloadInputs(ctx, closure.ComputedInputs, request.Id, shared.Inputs)
681+
newInputsURI, err := m.offloadInputs(ctx, closure.ComputedInputs, request.Id, shared.Inputs)
682682
if err != nil {
683683
return nil, err
684684
}
685685
// Update model so as not to offload again.
686-
executionModel.InputsUri = newInputsUri
686+
executionModel.InputsURI = newInputsURI
687687
if err := m.db.ExecutionRepo().UpdateExecution(ctx, *executionModel); err != nil {
688688
return nil, err
689689
}
690690
}
691-
inputsUrlBlob, err := m.urlData.Get(ctx, executionModel.InputsUri.String())
691+
inputsURLBlob, err := m.urlData.Get(ctx, executionModel.InputsURI.String())
692692
if err != nil {
693693
return nil, err
694694
}
695695
return &admin.WorkflowExecutionGetDataResponse{
696696
Outputs: &signedOutputsURLBlob,
697-
Inputs: &inputsUrlBlob,
697+
Inputs: &inputsURLBlob,
698698
}, nil
699699
}
700700

pkg/manager/impl/execution_manager_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var mockPublisher notificationMocks.MockPublisher
6060
var mockExecutionRemoteURL = dataMocks.NewMockRemoteURL()
6161
var requestedAt = time.Now()
6262
var testCluster = "C1"
63+
var outputURI = "output uri"
6364

6465
func getLegacySpec() *admin.ExecutionSpec {
6566
executionRequest := testutils.GetExecutionRequest()
@@ -150,7 +151,7 @@ func getMockStorageForExecTest(ctx context.Context) *storage.DataStore {
150151
_ = proto.Unmarshal(val, msg)
151152
return nil
152153
}
153-
return errors.New(fmt.Sprintf("Could not find value in storage [%v]\n", reference.String()))
154+
return fmt.Errorf("could not find value in storage [%v]", reference.String())
154155
}
155156
mockStorage.ComposedProtobufStore.(*commonMocks.TestDataStore).WriteProtobufCb = func(
156157
ctx context.Context, reference storage.DataReference, opts storage.Options, msg proto.Message) error {
@@ -162,7 +163,9 @@ func getMockStorageForExecTest(ctx context.Context) *storage.DataStore {
162163
return nil
163164
}
164165
workflowClosure := testutils.GetWorkflowClosure()
165-
mockStorage.WriteProtobuf(ctx, storage.DataReference(remoteClosureIdentifier), defaultStorageOptions, workflowClosure)
166+
if err := mockStorage.WriteProtobuf(ctx, storage.DataReference(remoteClosureIdentifier), defaultStorageOptions, workflowClosure); err != nil {
167+
return nil
168+
}
166169
return mockStorage
167170
}
168171

@@ -475,10 +478,10 @@ func TestCreateExecutionVerifyDbModel(t *testing.T) {
475478
assert.Nil(t, closureValue.ComputedInputs)
476479

477480
var userInputs, inputs core.LiteralMap
478-
if err := storageClient.ReadProtobuf(ctx, storage.DataReference(input.UserInputsUri), &userInputs); err != nil {
481+
if err := storageClient.ReadProtobuf(ctx, input.UserInputsURI, &userInputs); err != nil {
479482
return err
480483
}
481-
if err := storageClient.ReadProtobuf(ctx, storage.DataReference(input.InputsUri), &inputs); err != nil {
484+
if err := storageClient.ReadProtobuf(ctx, input.InputsURI, &inputs); err != nil {
482485
return err
483486
}
484487
fooValue := utils.MustMakeLiteral("foo-value-1")
@@ -1884,7 +1887,7 @@ func TestGetExecutionData(t *testing.T) {
18841887
OutputResult: &admin.ExecutionClosure_Outputs{
18851888
Outputs: &admin.LiteralMapBlob{
18861889
Data: &admin.LiteralMapBlob_Uri{
1887-
Uri: "output uri",
1890+
Uri: outputURI,
18881891
},
18891892
},
18901893
},
@@ -1904,13 +1907,13 @@ func TestGetExecutionData(t *testing.T) {
19041907
LaunchPlanID: uint(1),
19051908
WorkflowID: uint(2),
19061909
StartedAt: &startedAt,
1907-
InputsUri: shared.Inputs,
1910+
InputsURI: shared.Inputs,
19081911
}, nil
19091912
}
19101913
mockExecutionRemoteURL := dataMocks.NewMockRemoteURL()
19111914
mockExecutionRemoteURL.(*dataMocks.MockRemoteURL).GetCallback = func(
19121915
ctx context.Context, uri string) (admin.UrlBlob, error) {
1913-
if uri == "output uri" {
1916+
if uri == outputURI {
19141917
return admin.UrlBlob{
19151918
Url: "outputs",
19161919
Bytes: 200,
@@ -2042,8 +2045,8 @@ func TestGetExecution_LegacyClient_OffloadedData(t *testing.T) {
20422045
LaunchPlanID: uint(1),
20432046
WorkflowID: uint(2),
20442047
StartedAt: &startedAt,
2045-
UserInputsUri: shared.UserInputs,
2046-
InputsUri: shared.Inputs,
2048+
UserInputsURI: shared.UserInputs,
2049+
InputsURI: shared.Inputs,
20472050
}, nil
20482051
}
20492052
repository.ExecutionRepo().(*repositoryMocks.MockExecutionRepo).SetGetCallback(executionGetFunc)
@@ -2069,7 +2072,7 @@ func TestGetExecutionData_LegacyModel(t *testing.T) {
20692072
closure.OutputResult = &admin.ExecutionClosure_Outputs{
20702073
Outputs: &admin.LiteralMapBlob{
20712074
Data: &admin.LiteralMapBlob_Uri{
2072-
Uri: "output uri",
2075+
Uri: outputURI,
20732076
},
20742077
},
20752078
}
@@ -2093,7 +2096,7 @@ func TestGetExecutionData_LegacyModel(t *testing.T) {
20932096
mockExecutionRemoteURL := dataMocks.NewMockRemoteURL()
20942097
mockExecutionRemoteURL.(*dataMocks.MockRemoteURL).GetCallback = func(
20952098
ctx context.Context, uri string) (admin.UrlBlob, error) {
2096-
if uri == "output uri" {
2099+
if uri == outputURI {
20972100
return admin.UrlBlob{
20982101
Url: "outputs",
20992102
Bytes: 200,

pkg/repositories/config/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ var Migrations = []*gormigrate.Migration{
136136
return tx.AutoMigrate(&models.Execution{}).Error
137137
},
138138
Rollback: func(tx *gorm.DB) error {
139-
return tx.Exec("ALTER TABLE executions DROP COLUMN IF EXISTS InputsUri, DROP COLUMN IF EXISTS UserInputsUri").Error
139+
return tx.Exec("ALTER TABLE executions DROP COLUMN IF EXISTS InputsURI, DROP COLUMN IF EXISTS UserInputsURI").Error
140140
},
141141
},
142142
}

pkg/repositories/models/execution.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Execution struct {
4848
// Cluster where execution was triggered
4949
Cluster string
5050
// Offloaded location of inputs LiteralMap. These are the inputs evaluated and contain applied defaults.
51-
InputsUri storage.DataReference
51+
InputsURI storage.DataReference
5252
// User specified inputs. This map might be incomplete and not include defaults applied
53-
UserInputsUri storage.DataReference
53+
UserInputsURI storage.DataReference
5454
}

pkg/repositories/transformers/execution.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type CreateExecutionModelInput struct {
2828
WorkflowIdentifier *core.Identifier
2929
ParentNodeExecutionID uint
3030
Cluster string
31-
InputsUri storage.DataReference
32-
UserInputsUri storage.DataReference
31+
InputsURI storage.DataReference
32+
UserInputsURI storage.DataReference
3333
}
3434

3535
// Transforms a ExecutionCreateRequest to a Execution model
@@ -74,8 +74,8 @@ func CreateExecutionModel(input CreateExecutionModelInput) (*models.Execution, e
7474
ExecutionUpdatedAt: &input.CreatedAt,
7575
ParentNodeExecutionID: input.ParentNodeExecutionID,
7676
Cluster: input.Cluster,
77-
InputsUri: input.InputsUri,
78-
UserInputsUri: input.UserInputsUri,
77+
InputsURI: input.InputsURI,
78+
UserInputsURI: input.UserInputsURI,
7979
}
8080
if input.RequestSpec.Metadata != nil {
8181
executionModel.Mode = int32(input.RequestSpec.Metadata.Mode)

0 commit comments

Comments
 (0)