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

add friendly name execution object column #5965

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flyteadmin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ require (
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737 // indirect
github.com/cloudevents/sdk-go/protocol/kafka_sarama/v2 v2.8.0
github.com/imdario/mergo v0.3.13 // indirect
github.com/wolfeidau/humanhash v1.1.0
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions flyteadmin/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/wI2L/jsondiff v0.5.0 h1:RRMTi/mH+R2aXcPe1VYyvGINJqQfC3R+KSEakuU1Ikw=
github.com/wI2L/jsondiff v0.5.0/go.mod h1:qqG6hnK0Lsrz2BpIVCxWiK9ItsBCpIZQiv0izJjOZ9s=
github.com/wolfeidau/humanhash v1.1.0 h1:06KgtyyABJGBbrfMONrW7S+b5TTYVyrNB/jss5n7F3E=
github.com/wolfeidau/humanhash v1.1.0/go.mod h1:jkpynR1bfyfkmKEQudIC0osWKynFAoayRjzH9OJdVIg=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
Expand Down
4 changes: 3 additions & 1 deletion flyteadmin/pkg/repositories/gormimpl/execution_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func getMockExecutionResponseFromDb(expected models.Execution) map[string]interf
execution["execution_name"] = expected.Name
execution["launch_plan_id"] = expected.LaunchPlanID
execution["workflow_id"] = expected.WorkflowID
execution["friendly_name"] = expected.FriendlyName
execution["phase"] = expected.Phase
execution["closure"] = expected.Closure
execution["spec"] = expected.Spec
Expand Down Expand Up @@ -381,6 +382,7 @@ func TestListExecutionsForWorkflow(t *testing.T) {
},
LaunchPlanID: uint(2),
WorkflowID: uint(3),
FriendlyName: "its-a-friendly-name",
Phase: core.WorkflowExecution_SUCCEEDED.String(),
Closure: []byte{1, 2},
Spec: []byte{3, 4},
Expand All @@ -394,7 +396,7 @@ func TestListExecutionsForWorkflow(t *testing.T) {
GlobalMock := mocket.Catcher.Reset()
GlobalMock.Logging = true
// Only match on queries that append expected filters
GlobalMock.NewMock().WithQuery(`SELECT "executions"."id","executions"."created_at","executions"."updated_at","executions"."deleted_at","executions"."execution_project","executions"."execution_domain","executions"."execution_name","executions"."launch_plan_id","executions"."workflow_id","executions"."task_id","executions"."phase","executions"."closure","executions"."spec","executions"."started_at","executions"."execution_created_at","executions"."execution_updated_at","executions"."duration","executions"."abort_cause","executions"."mode","executions"."source_execution_id","executions"."parent_node_execution_id","executions"."cluster","executions"."inputs_uri","executions"."user_inputs_uri","executions"."error_kind","executions"."error_code","executions"."user","executions"."state","executions"."launch_entity" FROM "executions" INNER JOIN workflows ON executions.workflow_id = workflows.id INNER JOIN tasks ON executions.task_id = tasks.id WHERE executions.execution_project = $1 AND executions.execution_domain = $2 AND executions.execution_name = $3 AND workflows.name = $4 AND tasks.name = $5 AND execution_tags.key in ($6,$7) LIMIT 20`).WithReply(executions)
GlobalMock.NewMock().WithQuery(`SELECT "executions"."id","executions"."created_at","executions"."updated_at","executions"."deleted_at","executions"."execution_project","executions"."execution_domain","executions"."execution_name","executions"."launch_plan_id","executions"."workflow_id","executions"."task_id","executions"."friendly_name","executions"."phase","executions"."closure","executions"."spec","executions"."started_at","executions"."execution_created_at","executions"."execution_updated_at","executions"."duration","executions"."abort_cause","executions"."mode","executions"."source_execution_id","executions"."parent_node_execution_id","executions"."cluster","executions"."inputs_uri","executions"."user_inputs_uri","executions"."error_kind","executions"."error_code","executions"."user","executions"."state","executions"."launch_entity" FROM "executions" INNER JOIN workflows ON executions.workflow_id = workflows.id INNER JOIN tasks ON executions.task_id = tasks.id WHERE executions.execution_project = $1 AND executions.execution_domain = $2 AND executions.execution_name = $3 AND workflows.name = $4 AND tasks.name = $5 AND execution_tags.key in ($6,$7) LIMIT 20`).WithReply(executions)
vals := []string{"tag1", "tag2"}
tagFilter, err := common.NewRepeatedValueFilter(common.AdminTag, common.ValueIn, "name", vals)
assert.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions flyteadmin/pkg/repositories/models/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Execution struct {
LaunchPlanID uint `gorm:"index"`
WorkflowID uint `gorm:"index"`
TaskID uint `gorm:"index"`
FriendlyName string `valid:"length(0|255)"`
Phase string `valid:"length(0|255)"`
Closure []byte
Spec []byte `gorm:"not null"`
Expand Down
2 changes: 2 additions & 0 deletions flyteadmin/pkg/repositories/transformers/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func CreateExecutionModel(input CreateExecutionModelInput) (*models.Execution, e
return nil, flyteErrs.NewFlyteAdminErrorf(codes.Internal, "Failed to serialize execution spec: %v", err)
}
createdAt := timestamppb.New(input.CreatedAt)
friendlyName := CreateFriendlyName(input.CreatedAt.UnixNano())
closure := admin.ExecutionClosure{
CreatedAt: createdAt,
UpdatedAt: createdAt,
Expand Down Expand Up @@ -119,6 +120,7 @@ func CreateExecutionModel(input CreateExecutionModelInput) (*models.Execution, e
Name: input.WorkflowExecutionID.Name,
},
Spec: spec,
FriendlyName: friendlyName,
Phase: closure.Phase.String(),
Closure: closureBytes,
WorkflowID: input.WorkflowID,
Expand Down
17 changes: 17 additions & 0 deletions flyteadmin/pkg/repositories/transformers/friendly_name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package transformers

import (
"github.com/wolfeidau/humanhash"
"k8s.io/apimachinery/pkg/util/rand"
)

const RandStringLength = 20
wayner0628 marked this conversation as resolved.
Show resolved Hide resolved

/* #nosec */
wayner0628 marked this conversation as resolved.
Show resolved Hide resolved
func CreateFriendlyName(seed int64) string {
rand.Seed(seed)
hashKey := []byte(rand.String(RandStringLength))
// Ignoring the error as it's guaranteed hash key longer than result in this context.
result, _ := humanhash.Humanize(hashKey, 4)
return result
}
29 changes: 29 additions & 0 deletions flyteadmin/pkg/repositories/transformers/friendly_name_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package transformers

import (
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

const AllowedFriendlyNameStr = "abcdefghijklmnopqrstuvwxyz-"
const FriendlyNameLengthLimit = 255

var AllowedFriendlyNameChars = []rune(AllowedFriendlyNameStr)

func TestCreateFriendlyName(t *testing.T) {
t.Run("successful creation", func(t *testing.T) {
randString := CreateFriendlyName(time.Now().UnixNano())
assert.LessOrEqual(t, len(randString), FriendlyNameLengthLimit)
for i := 0; i < len(randString); i++ {
assert.Contains(t, AllowedFriendlyNameChars, rune(randString[i]))
}
hyphenCount := strings.Count(randString, "-")
assert.Equal(t, 3, hyphenCount, "FriendlyName should contain exactly three hyphens")
words := strings.Split(randString, "-")
assert.Equal(t, 4, len(words), "FriendlyName should be split into exactly four words")
})

}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ require (
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/wI2L/jsondiff v0.5.0 // indirect
github.com/wolfeidau/humanhash v1.1.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/wI2L/jsondiff v0.5.0 h1:RRMTi/mH+R2aXcPe1VYyvGINJqQfC3R+KSEakuU1Ikw=
github.com/wI2L/jsondiff v0.5.0/go.mod h1:qqG6hnK0Lsrz2BpIVCxWiK9ItsBCpIZQiv0izJjOZ9s=
github.com/wolfeidau/humanhash v1.1.0 h1:06KgtyyABJGBbrfMONrW7S+b5TTYVyrNB/jss5n7F3E=
github.com/wolfeidau/humanhash v1.1.0/go.mod h1:jkpynR1bfyfkmKEQudIC0osWKynFAoayRjzH9OJdVIg=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
Expand Down
Loading