Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flyteadmin] add delete execution phase api #6267

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

taieeuu
Copy link
Contributor

@taieeuu taieeuu commented Feb 22, 2025

Tracking issue

Why are the changes needed?

This API provides users with a method to batch delete unnecessary execution records. It accepts the parameters project, domain, and phase, enabling the deletion of execution records that are no longer needed.

What changes were proposed in this pull request?

In the protobuf definition, define an RPC method called DeleteExecutionPhase that accepts project, domain, and phase parameters and uses the DELETE method for the deletion request. In both execution_manager and execution_repo, implement deletion logic that includes input validation and error handling. Unit tests are provided to ensure correct functionality under both successful and failure scenarios.

How was this patch tested?

"All tests passed successfully, and I have also added unit tests."

And you can also test with postman ... tools .

image

Labels

Please add one or more of the following labels to categorize your PR:

  • added: For new features.
  • changed: For changes in existing functionality.
  • deprecated: For soon-to-be-removed features.
  • removed: For features being removed.
  • fixed: For any bug fixed.
  • security: In case of vulnerabilities

This is important to improve the readability of release notes.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Summary by Bito

This PR implements a new API endpoint for batch deleting execution phases in Flyte, introducing protobuf message types with implementations in Go, TypeScript, and Rust. It updates execution manager and repository layers, improves encapsulation by replacing direct field access with getter methods, and switches from GET to DELETE methods with proper validation and error handling.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 5

@flyte-bot
Copy link
Collaborator

flyte-bot commented Feb 22, 2025

Code Review Agent Run #50b8fe

Actionable Suggestions - 8
  • flyteidl/gen/pb-go/flyteidl/admin/execution.pb.go - 1
  • flyteadmin/pkg/rpc/adminservice/execution.go - 1
    • Consider using specific metric for DeleteExecutionPhase · Line 160-161
  • flyteadmin/pkg/repositories/gormimpl/execution_repo.go - 1
    • Consider adding validation for execution phase · Line 175-179
  • flyteidl/clients/go/admin/mocks/AdminServiceClient.go - 1
  • flyteidl/protos/flyteidl/service/admin.proto - 1
  • flyteadmin/pkg/manager/impl/execution_manager.go - 1
  • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.pb.gw.go - 1
  • flyteidl/gen/pb-go/flyteidl/service/admin_grpc.pb.go - 1
Additional Suggestions - 5
  • flyteidl/gen/pb_python/flyteidl/service/admin_pb2_grpc.py - 1
  • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.pb.gw.go - 1
  • flyteidl/gen/pb-go/flyteidl/service/admin_grpc.pb.go - 2
    • Consider adding matching interface method definition · Line 79-79
    • Consider adding input parameter validation · Line 717-724
  • flyteidl/gen/pb-js/flyteidl.d.ts - 1
Review Details
  • Files reviewed - 25 · Commit Range: 48c547a..48c547a
    • flyteadmin/pkg/manager/impl/execution_manager.go
    • flyteadmin/pkg/manager/interfaces/execution.go
    • flyteadmin/pkg/repositories/gormimpl/execution_repo.go
    • flyteadmin/pkg/repositories/interfaces/execution_repo.go
    • flyteadmin/pkg/rpc/adminservice/execution.go
    • flyteidl/clients/go/admin/mocks/AdminServiceClient.go
    • flyteidl/clients/go/admin/mocks/AdminServiceServer.go
    • flyteidl/gen/pb-es/flyteidl/admin/execution_pb.ts
    • flyteidl/gen/pb-es/flyteidl/service/admin_connect.ts
    • flyteidl/gen/pb-go/flyteidl/admin/execution.pb.go
    • flyteidl/gen/pb-go/flyteidl/service/admin.pb.go
    • flyteidl/gen/pb-go/flyteidl/service/admin_grpc.pb.go
    • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.pb.gw.go
    • flyteidl/gen/pb-js/flyteidl.d.ts
    • flyteidl/gen/pb-js/flyteidl.js
    • flyteidl/gen/pb_python/flyteidl/admin/execution_pb2.py
    • flyteidl/gen/pb_python/flyteidl/admin/execution_pb2.pyi
    • flyteidl/gen/pb_python/flyteidl/service/admin_pb2.py
    • flyteidl/gen/pb_python/flyteidl/service/admin_pb2_grpc.py
    • flyteidl/gen/pb_rust/flyteidl.admin.rs
    • flyteidl/gen/pb_rust/flyteidl.service.tonic.rs
    • flyteidl/protos/flyteidl/admin/execution.proto
    • flyteidl/protos/flyteidl/service/admin.proto
    • go.mod
    • go.sum
  • Files skipped - 2
    • flyteidl/clients/go/assets/admin.swagger.json - Reason: Filter setting
    • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.swagger.json - Reason: Filter setting
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@taieeuu taieeuu changed the title [WPI] Feat: add batch delete execution_phase api [WIP] Feat: add batch delete execution_phase api Feb 22, 2025
@taieeuu taieeuu changed the title [WIP] Feat: add batch delete execution_phase api [WIP] [Feature] add batch delete execution_phase api Feb 22, 2025
Copy link

codecov bot commented Feb 22, 2025

Codecov Report

Attention: Patch coverage is 38.00000% with 31 lines in your changes missing coverage. Please review.

Project coverage is 58.47%. Comparing base (6e5aca7) to head (63aad12).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...eadmin/pkg/repositories/gormimpl/execution_repo.go 0.00% 11 Missing ⚠️
flyteadmin/pkg/rpc/adminservice/execution.go 0.00% 11 Missing ⚠️
flyteadmin/pkg/manager/impl/execution_manager.go 67.85% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6267      +/-   ##
==========================================
- Coverage   58.48%   58.47%   -0.01%     
==========================================
  Files         937      937              
  Lines       71088    71138      +50     
==========================================
+ Hits        41577    41601      +24     
- Misses      26359    26382      +23     
- Partials     3152     3155       +3     
Flag Coverage Δ
unittests-datacatalog 59.06% <ø> (ø)
unittests-flyteadmin 56.25% <38.00%> (-0.02%) ⬇️
unittests-flytecopilot 30.99% <ø> (ø)
unittests-flytectl 64.70% <ø> (ø)
unittests-flyteidl 76.12% <ø> (ø)
unittests-flyteplugins 61.00% <ø> (ø)
unittests-flytepropeller 54.79% <ø> (ø)
unittests-flytestdlib 64.02% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@flyte-bot
Copy link
Collaborator

flyte-bot commented Feb 22, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
New Feature - API Expansion and Integration

admin.pb.go - Updated RPC method descriptors to incorporate DeleteExecutionPhase with revised arguments and field mappings.

admin_grpc.pb.go - Introduced DeleteExecutionPhase RPC implementation including client stub, server handler, and interceptor wrappers.

admin.pb.gw.go - Added new DELETE endpoint and URL routing for DeleteExecutionPhase, adjusting HTTP handler logic accordingly.

flyteidl.d.ts - Appended new TypeScript definitions for ExecutionPhaseDeleteRequest and ExecutionPhaseDeleteResponse.

execution_manager.go - Adds DeleteExecutionPhase function with input validations and database deletion call.

execution.go - Introduces DeleteExecutionPhase interface definition to standardize API exposure.

execution_repo.go - Implements a Delete method that removes an execution based on project, domain, and phase criteria.

common.go - Updates import and adds ExecutionPhaseDeleteInput struct for encapsulating deletion parameters.

execution_repo.go - Adds Delete method signature to the repository interface.

execution.go - Implements the DeleteExecutionPhase RPC endpoint with adequate error handling and metric tracking.

AdminServiceClient.go - Introduces mock support for DeleteExecutionPhase in the admin service client.

AdminServiceServer.go - Provides server-side mocks to simulate DeleteExecutionPhase responses.

execution_pb.ts - Generates new protobuf message types for ExecutionPhaseDeleteRequest and ExecutionPhaseDeleteResponse.

admin_connect.ts - Updates service definition to include the new DeleteExecutionPhase RPC mapping.

flyteidl.js - Introduced new JavaScript implementations for ExecutionPhaseDeleteRequest/Response and added DeleteExecutionPhase method definitions in the AdminService.

execution_pb2.py - Updated protobuf descriptors with new serialized positions and added message definitions for execution phase deletion.

execution_pb2.pyi - Added Python type definitions for ExecutionPhaseDeleteRequest and ExecutionPhaseDeleteResponse to support the deletion API.

admin_pb2.py - Refactored DESCRIPTOR and updated serialized options to support DeleteExecutionPhase RPC.

admin_pb2_grpc.py - Integrated DeleteExecutionPhase method into gRPC stubs and service handlers.

flyteidl.admin.rs - Added protobuf message definitions for execution phase deletion in Rust.

flyteidl.service.tonic.rs - Implemented client and server support for DeleteExecutionPhase RPC in Rust.

execution.proto - Introduced new message definitions for ExecutionPhaseDeleteRequest and ExecutionPhaseDeleteResponse.

admin.proto - Added DeleteExecutionPhase RPC endpoint with HTTP DELETE mapping.

Testing - Comprehensive Test Coverage

execution_manager_test.go - Adds unit tests covering both successful and error scenarios for the DeleteExecutionPhase API.

execution_interface.go - Implements mock functions for DeleteExecutionPhase to facilitate isolated testing.

execution_repo.go - Introduces a mock delete callback to simulate repository deletion behavior during tests.

Other Improvements - Dependency Cleanup

go.mod - Removed unused/indirect dependencies improving module hygiene.

go.sum - Removed outdated dependency checksum entries aligning with updated dependency ecosystem.

sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields

ExecutionPhase string `protobuf:"bytes,1,opt,name=execution_phase,json=executionPhase,proto3" json:"execution_phase,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding execution phase validation

Consider adding validation for the execution_phase field in ExecutionPhaseDeleteRequest. The field appears to be used for deleting execution phases but lacks input validation to ensure valid phase values are provided. This could potentially lead to runtime errors if invalid phases are specified.

Code suggestion
Check the AI-generated fix before applying
Suggested change
ExecutionPhase string `protobuf:"bytes,1,opt,name=execution_phase,json=executionPhase,proto3" json:"execution_phase,omitempty"`
// +required The phase of execution to be deleted. Must be one of the valid execution phases.
ExecutionPhase string `protobuf:"bytes,1,opt,name=execution_phase,json=executionPhase,proto3" json:"execution_phase,omitempty" validate:"required,oneof=QUEUED RUNNING SUCCEEDED FAILED ABORTED"`

Code Review Run #50b8fe


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines +160 to +161
m.Metrics.executionEndpointMetrics.terminate.Time(func() {
response, err = m.ExecutionManager.DeleteExecutionPhase(ctx, request)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using specific metric for DeleteExecutionPhase

Consider using a more specific metric name for DeleteExecutionPhase. Currently using terminate metric which seems to be shared with termination functionality. This could lead to misleading metrics.

Code suggestion
Check the AI-generated fix before applying
 	terminate   util.RequestMetrics
 +	deletePhase util.RequestMetrics
 @@ -160,9 +160,9 @@
 -	m.Metrics.executionEndpointMetrics.terminate.Time(func() {
 -		response, err = m.ExecutionManager.DeleteExecutionPhase(ctx, request)
 -	})
 -	if err != nil {
 -		return nil, util.TransformAndRecordError(err, &m.Metrics.executionEndpointMetrics.terminate)
 -	}
 -	m.Metrics.executionEndpointMetrics.terminate.Success()
 +	m.Metrics.executionEndpointMetrics.deletePhase.Time(func() {
 +		response, err = m.ExecutionManager.DeleteExecutionPhase(ctx, request)
 +	})
 +	if err != nil {
 +		return nil, util.TransformAndRecordError(err, &m.Metrics.executionEndpointMetrics.deletePhase)
 +	}
 +	m.Metrics.executionEndpointMetrics.deletePhase.Success()

Code Review Run #50b8fe


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines 175 to 179
result := r.db.Delete(&models.Execution{}, "phase = ?", executionPhase)
if result.Error != nil {
return result.Error
}
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding validation for execution phase

Consider adding validation to ensure executionPhase is not empty and matches valid execution phase values. Also, consider adding error handling for when no records are deleted.

Code suggestion
Check the AI-generated fix before applying
Suggested change
result := r.db.Delete(&models.Execution{}, "phase = ?", executionPhase)
if result.Error != nil {
return result.Error
}
return nil
if executionPhase == "" {
return fmt.Errorf("execution phase cannot be empty")
}
result := r.db.Delete(&models.Execution{}, "phase = ?", executionPhase)
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return fmt.Errorf("no executions found with phase %s", executionPhase)
}
return nil

Code Review Run #50b8fe


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines +376 to +379
_va := make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding nil check for opts

Consider adding validation for the opts parameter in the DeleteExecutionPhase method. Currently, there's no check if opts is nil before iterating over it.

Code suggestion
Check the AI-generated fix before applying
Suggested change
_va := make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
_va := []interface{}{}
if opts != nil {
_va = make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
}

Code Review Run #50b8fe


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines 671 to 672
get: "/api/v1/delete_execution_phase/{execution_phase}"
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using DELETE instead of GET

The DeleteExecutionPhase endpoint is using GET HTTP method for a deletion operation. Consider using DELETE HTTP method instead to better align with REST conventions and make the API more intuitive.

Code suggestion
Check the AI-generated fix before applying
Suggested change
get: "/api/v1/delete_execution_phase/{execution_phase}"
};
delete: "/api/v1/delete_execution_phase/{execution_phase}"
};

Code Review Run #50b8fe


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them


err := m.db.ExecutionRepo().Delete(ctx, executionPhase)
if err != nil {
return nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding context to error return

Consider adding error wrapping with context when returning the database error. This would help with debugging by providing more context about what operation failed. Maybe something like: fmt.Errorf("failed to delete execution phase %s: %w", executionPhase, err)

Code suggestion
Check the AI-generated fix before applying
Suggested change
return nil, err
return nil, fmt.Errorf("failed to delete execution phase %s: %w", executionPhase, err)

Code Review Run #50b8fe


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines 5811 to 5814
protoReq.ExecutionPhase, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "execution_phase", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding empty string validation

Consider adding validation for empty string in execution_phase parameter. The current implementation accepts empty strings which could lead to unintended behavior when deleting execution phases.

Code suggestion
Check the AI-generated fix before applying
Suggested change
protoReq.ExecutionPhase, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "execution_phase", err)
}
protoReq.ExecutionPhase, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "execution_phase", err)
}
if protoReq.ExecutionPhase == "" {
return nil, metadata, status.Errorf(codes.InvalidArgument, "parameter %s cannot be empty", "execution_phase")
}

Code Review Run #50b8fe


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines +2045 to +2047
in := new(admin.ExecutionPhaseDeleteRequest)
if err := dec(in); err != nil {
return nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding nil check for request

Consider adding error validation in the _AdminService_DeleteExecutionPhase_Handler function to ensure the input request is not nil before proceeding with the decoding operation.

Code suggestion
Check the AI-generated fix before applying
Suggested change
in := new(admin.ExecutionPhaseDeleteRequest)
if err := dec(in); err != nil {
return nil, err
if srv == nil {
return nil, status.Error(codes.InvalidArgument, "server interface is nil")
}
in := new(admin.ExecutionPhaseDeleteRequest)
if err := dec(in); err != nil {
return nil, err

Code Review Run #50b8fe


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@flyte-bot
Copy link
Collaborator

flyte-bot commented Feb 28, 2025

Code Review Agent Run #26e38f

Actionable Suggestions - 6
  • flyteidl/gen/pb-es/flyteidl/admin/execution_pb.ts - 1
  • flyteadmin/pkg/manager/impl/execution_manager.go - 2
  • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.pb.gw.go - 1
  • flyteidl/gen/pb_rust/flyteidl.admin.rs - 1
  • flyteadmin/pkg/repositories/interfaces/common.go - 1
    • Consider adding field validation checks · Line 49-52
Additional Suggestions - 1
  • flyteidl/gen/pb-js/flyteidl.d.ts - 1
Review Details
  • Files reviewed - 16 · Commit Range: 48c547a..739b16c
    • flyteadmin/pkg/manager/impl/execution_manager.go
    • flyteadmin/pkg/repositories/gormimpl/execution_repo.go
    • flyteadmin/pkg/repositories/interfaces/common.go
    • flyteadmin/pkg/repositories/interfaces/execution_repo.go
    • flyteidl/gen/pb-es/flyteidl/admin/execution_pb.ts
    • flyteidl/gen/pb-go/flyteidl/admin/execution.pb.go
    • flyteidl/gen/pb-go/flyteidl/service/admin.pb.go
    • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.pb.gw.go
    • flyteidl/gen/pb-js/flyteidl.d.ts
    • flyteidl/gen/pb-js/flyteidl.js
    • flyteidl/gen/pb_python/flyteidl/admin/execution_pb2.py
    • flyteidl/gen/pb_python/flyteidl/admin/execution_pb2.pyi
    • flyteidl/gen/pb_python/flyteidl/service/admin_pb2.py
    • flyteidl/gen/pb_rust/flyteidl.admin.rs
    • flyteidl/protos/flyteidl/admin/execution.proto
    • flyteidl/protos/flyteidl/service/admin.proto
  • Files skipped - 2
    • flyteidl/clients/go/assets/admin.swagger.json - Reason: Filter setting
    • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.swagger.json - Reason: Filter setting
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines +1624 to +1625
{ no: 1, name: "id", kind: "message", T: WorkflowExecutionIdentifier },
{ no: 2, name: "phase", kind: "enum", T: proto3.getEnumType(WorkflowExecution_Phase) },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider more descriptive field naming

Consider updating the field names to be more descriptive. The change from execution_phase to phase may reduce clarity. Perhaps consider keeping the prefix to maintain context and avoid potential naming conflicts.

Code suggestion
Check the AI-generated fix before applying
Suggested change
{ no: 1, name: "id", kind: "message", T: WorkflowExecutionIdentifier },
{ no: 2, name: "phase", kind: "enum", T: proto3.getEnumType(WorkflowExecution_Phase) },
{ no: 1, name: "id", kind: "message", T: WorkflowExecutionIdentifier },
{ no: 2, name: "execution_phase", kind: "enum", T: proto3.getEnumType(WorkflowExecution_Phase) },

Code Review Run #26e38f


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines +1961 to +1963
if executionPhase == core.WorkflowExecution_UNDEFINED {
return nil, fmt.Errorf("execution phase cannot be undefined")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider more thorough phase validation

Consider adding more specific validation for the execution phase. The current check only validates against UNDEFINED but there may be other invalid phases. Consider validating against a list of allowed phases.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if executionPhase == core.WorkflowExecution_UNDEFINED {
return nil, fmt.Errorf("execution phase cannot be undefined")
}
validPhases := []core.WorkflowExecution_Phase{
core.WorkflowExecution_QUEUED,
core.WorkflowExecution_RUNNING,
core.WorkflowExecution_SUCCEEDING,
core.WorkflowExecution_SUCCEEDED,
core.WorkflowExecution_FAILING,
core.WorkflowExecution_FAILED,
core.WorkflowExecution_ABORTED,
core.WorkflowExecution_TIMED_OUT,
core.WorkflowExecution_ABORTING,
}
isValid := false
for _, phase := range validPhases {
if executionPhase == phase {
isValid = true
break
}
}
if !isValid {
return nil, fmt.Errorf("invalid execution phase: %s", executionPhase)
}

Code Review Run #26e38f


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines 1970 to 1971
if workflowExecutionID.Project == "" || workflowExecutionID.Domain == "" {
return nil, fmt.Errorf("workflow execution identifier must have project, domain")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider validating workflow execution name field

Consider validating the Name field of workflowExecutionID as well. The WorkflowExecutionIdentifier typically requires all fields (Project, Domain, and Name) to be non-empty for a valid identifier.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if workflowExecutionID.Project == "" || workflowExecutionID.Domain == "" {
return nil, fmt.Errorf("workflow execution identifier must have project, domain")
if workflowExecutionID.Project == "" || workflowExecutionID.Domain == "" || workflowExecutionID.Name == "" {
return nil, fmt.Errorf("workflow execution identifier must have project, domain, and name")

Code Review Run #26e38f


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "phase")
}

e, err = runtime.Enum(val, extCore.WorkflowExecution_Phase_value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding phase parameter validation

Consider adding validation for the phase parameter against valid workflow execution phases before attempting enum conversion. The current implementation may allow invalid phase values to be processed.

Code suggestion
Check the AI-generated fix before applying
Suggested change
e, err = runtime.Enum(val, extCore.WorkflowExecution_Phase_value)
_, exists := extCore.WorkflowExecution_Phase_value[val]
if !exists {
return nil, metadata, status.Errorf(codes.InvalidArgument, "invalid phase value: %s", val)
}
e, err = runtime.Enum(val, extCore.WorkflowExecution_Phase_value)

Code Review Run #26e38f


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines +1852 to +1855
#[prost(message, optional, tag="1")]
pub id: ::core::option::Option<super::core::WorkflowExecutionIdentifier>,
#[prost(enumeration="super::core::workflow_execution::Phase", tag="2")]
pub phase: i32,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider more descriptive field names

Consider updating the struct field names to be more descriptive. The field phase could be renamed to execution_phase to better indicate its purpose and maintain consistency with the previous implementation.

Code suggestion
Check the AI-generated fix before applying
Suggested change
#[prost(message, optional, tag="1")]
pub id: ::core::option::Option<super::core::WorkflowExecutionIdentifier>,
#[prost(enumeration="super::core::workflow_execution::Phase", tag="2")]
pub phase: i32,
#[prost(message, optional, tag="1")]
pub execution_id: ::core::option::Option<super::core::WorkflowExecutionIdentifier>,
#[prost(enumeration="super::core::workflow_execution::Phase", tag="2")]
pub execution_phase: i32,

Code Review Run #26e38f


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines 49 to 52
type ExecutionPhaseDeleteInput struct {
WorkflowExecutionID core.WorkflowExecutionIdentifier
ExecutionPhase core.WorkflowExecution_Phase
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding field validation checks

Consider adding validation for WorkflowExecutionID and ExecutionPhase fields in ExecutionPhaseDeleteInput struct. These fields appear to be critical for deletion operations and should be validated before use.

Code suggestion
Check the AI-generated fix before applying
Suggested change
type ExecutionPhaseDeleteInput struct {
WorkflowExecutionID core.WorkflowExecutionIdentifier
ExecutionPhase core.WorkflowExecution_Phase
}
type ExecutionPhaseDeleteInput struct {
WorkflowExecutionID core.WorkflowExecutionIdentifier
ExecutionPhase core.WorkflowExecution_Phase
}
func (i *ExecutionPhaseDeleteInput) Validate() error {
if i.WorkflowExecutionID.Project == "" || i.WorkflowExecutionID.Domain == "" || i.WorkflowExecutionID.Name == "" {
return fmt.Errorf("invalid workflow execution identifier")
}
if i.ExecutionPhase == core.WorkflowExecution_UNDEFINED {
return fmt.Errorf("execution phase cannot be undefined")
}
return nil
}

Code Review Run #26e38f


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@taieeuu taieeuu changed the title [WIP] [Feature] add batch delete execution_phase api [WIP] [Feature] add delete execution phase api Feb 28, 2025
@flyte-bot
Copy link
Collaborator

flyte-bot commented Mar 1, 2025

Code Review Agent Run #66451d

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: 739b16c..c452608
    • flyteidl/gen/pb-go/flyteidl/service/admin.pb.go
    • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.pb.gw.go
    • flyteidl/gen/pb_python/flyteidl/service/admin_pb2.py
    • flyteidl/protos/flyteidl/service/admin.proto
  • Files skipped - 2
    • flyteidl/clients/go/assets/admin.swagger.json - Reason: Filter setting
    • flyteidl/gen/pb-go/gateway/flyteidl/service/admin.swagger.json - Reason: Filter setting
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Signed-off-by: taieeuu <[email protected]>
@flyte-bot
Copy link
Collaborator

flyte-bot commented Mar 2, 2025

Code Review Agent Run #de2c1d

Actionable Suggestions - 0
Review Details
  • Files reviewed - 6 · Commit Range: c452608..6fccc9b
    • flyteadmin/pkg/manager/impl/execution_manager.go
    • flyteadmin/pkg/manager/impl/execution_manager_test.go
    • flyteadmin/pkg/manager/mocks/execution_interface.go
    • flyteadmin/pkg/repositories/gormimpl/execution_repo.go
    • flyteadmin/pkg/repositories/interfaces/common.go
    • flyteadmin/pkg/repositories/mocks/execution_repo.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@taieeuu taieeuu changed the title [WIP] [Feature] add delete execution phase api [Feature] add delete execution phase api Mar 4, 2025
taieeuu added 2 commits March 5, 2025 23:33
Signed-off-by: taieeuu <[email protected]>
Signed-off-by: taieeuu <[email protected]>
@flyte-bot
Copy link
Collaborator

flyte-bot commented Mar 5, 2025

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - Bito Code Review Agent didn't review this pull request automatically because it exceeded the size limit. No action is needed if you didn't intend for the agent to review it. Otherwise, you can initiate the review by typing /review in a comment below.

Signed-off-by: taieeuu <[email protected]>
@Future-Outlier Future-Outlier changed the title [Feature] add delete execution phase api [flyteadmin] add delete execution phase api Mar 6, 2025
@flyte-bot
Copy link
Collaborator

flyte-bot commented Mar 6, 2025

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - Bito Code Review Agent didn't review this pull request automatically because it exceeded the size limit. No action is needed if you didn't intend for the agent to review it. Otherwise, you can initiate the review by typing /review in a comment below.

Copy link
Member

@Future-Outlier Future-Outlier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. do we want to return how many executions we deleted?
    There's a field called result.RowsAffected? in result
// DB GORM DB definition
type DB struct {
	*Config
	Error        error
	RowsAffected int64
	Statement    *Statement
	clone        int
}
  1. should we use soft delete? or hard delete is what we want?

let's discuss next week!
cc @pingsutw @katrogan

Comment on lines +155 to +161

func (m *AdminService) DeleteExecutionPhase(
ctx context.Context, request *admin.ExecutionPhaseDeleteRequest) (*admin.ExecutionPhaseDeleteResponse, error) {
var response *admin.ExecutionPhaseDeleteResponse
var err error
m.Metrics.executionEndpointMetrics.terminate.Time(func() {
response, err = m.ExecutionManager.DeleteExecutionPhase(ctx, request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know where to see the metrics?
is it stored in database or a metric server something like that?

Copy link
Contributor Author

@taieeuu taieeuu Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data is stored in Prometheus, but 'flytectl demo start' does not launch Prometheus.

message ExecutionPhaseDeleteResponse {
string message = 1;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -430,3 +430,13 @@ message WorkflowExecutionGetMetricsResponse {
// hierarchical structure using Flyte entity references.
core.Span span = 1;
}

message ExecutionPhaseDeleteRequest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than requiring this deletion to be based on phase attributes only (what if one day we want to support timestamp filters instead?) can we make this more generic and re-use the ResourceListRequest (

message ResourceListRequest {
// id represents the unique identifier of the resource.
// +required
NamedEntityIdentifier id = 1;
// Indicates the number of resources to be returned.
// +required
uint32 limit = 2;
// In the case of multiple pages of results, this server-provided token can be used to fetch the next page
// in a query.
// +optional
string token = 3;
// Indicates a list of filters passed as string.
// More info on constructing filters : <Link>
// +optional
string filters = 4;
// Sort ordering.
// +optional
Sort sort_by = 5;
}
) which includes out of the box support for filtering by phase, timestamp and other fields?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like

rpc DeleteExecutions (flyteidl.admin. ResourceListRequest) returns (flyteidl.admin.ExecutionDeleteResponse) {
		option (google.api.http) = {
      delete: "/api/v1/delete_execution/{id.project}/{id.domain}"
		};
		option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
		  description: "Delete all executions matching request filters"
		};
	};
}

@katrogan
Copy link
Contributor

before we proceed with deleting items from the db can we maybe write up an issue to address

  1. what we're trying to solve (mass terminate executions)
  2. why the current api is insufficient
  3. and if the current api works, how we can use the remote client in flytekit SDK to allow us to batch terminate executions and accepts a list of input parameters (created at window, current phase filters, etc)

I think as it stands now this PR could orphan executions unintentionally if we're not careful or make it really easy to delete from the DB which is a departure from how flyteadmin currently records entities. Flyteadmin allows us to archive or tombstone various entities but delete is a scarier tool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants