diff --git a/flytectl/cmd/get/execution.go b/flytectl/cmd/get/execution.go index e7164ca90e..e7cd122c9c 100644 --- a/flytectl/cmd/get/execution.go +++ b/flytectl/cmd/get/execution.go @@ -54,6 +54,8 @@ Usage ` ) +var hundredChars = 100 + var executionColumns = []printer.Column{ {Header: "Name", JSONPath: "$.id.name"}, {Header: "Launch Plan Name", JSONPath: "$.spec.launchPlan.name"}, @@ -61,8 +63,8 @@ var executionColumns = []printer.Column{ {Header: "Phase", JSONPath: "$.closure.phase"}, {Header: "Started", JSONPath: "$.closure.startedAt"}, {Header: "Elapsed Time", JSONPath: "$.closure.duration"}, - {Header: "Abort data", JSONPath: "$.closure.abortMetadata[\"cause\"]"}, - {Header: "Error data", JSONPath: "$.closure.error[\"message\"]"}, + {Header: "Abort data (Trunc)", JSONPath: "$.closure.abortMetadata[\"cause\"]", TruncateTo: &hundredChars}, + {Header: "Error data (Trunc)", JSONPath: "$.closure.error[\"message\"]", TruncateTo: &hundredChars}, } func ExecutionToProtoMessages(l []*admin.Execution) []proto.Message { @@ -78,11 +80,11 @@ func getExecutionFunc(ctx context.Context, args []string, cmdCtx cmdCore.Command var executions []*admin.Execution if len(args) > 0 { name := args[0] - execution, err := cmdCtx.AdminFetcherExt().FetchExecution(ctx, name, config.GetConfig().Project, config.GetConfig().Domain) + exec, err := cmdCtx.AdminFetcherExt().FetchExecution(ctx, name, config.GetConfig().Project, config.GetConfig().Domain) if err != nil { return err } - executions = append(executions, execution) + executions = append(executions, exec) logger.Infof(ctx, "Retrieved %v executions", len(executions)) return adminPrinter.Print(config.GetConfig().MustOutputFormat(), executionColumns, ExecutionToProtoMessages(executions)...) diff --git a/flytectl/cmd/get/execution_test.go b/flytectl/cmd/get/execution_test.go index 5940c3d17a..87e970231b 100644 --- a/flytectl/cmd/get/execution_test.go +++ b/flytectl/cmd/get/execution_test.go @@ -6,6 +6,8 @@ import ( "io" "testing" + "github.com/stretchr/testify/mock" + "github.com/flyteorg/flytectl/cmd/config" cmdCore "github.com/flyteorg/flytectl/cmd/core" "github.com/flyteorg/flyteidl/clients/go/admin/mocks" @@ -25,6 +27,10 @@ func TestListExecutionFunc(t *testing.T) { cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) execListRequest := &admin.ResourceListRequest{ Limit: 100, + SortBy: &admin.Sort{ + Key: "created_at", + Direction: admin.Sort_DESCENDING, + }, Id: &admin.NamedEntityIdentifier{ Project: projectValue, Domain: domainValue, @@ -58,7 +64,9 @@ func TestListExecutionFunc(t *testing.T) { executionList := &admin.ExecutionList{ Executions: executions, } - mockClient.OnListExecutionsMatch(ctx, execListRequest).Return(executionList, nil) + mockClient.OnListExecutionsMatch(mock.Anything, mock.MatchedBy(func(o *admin.ResourceListRequest) bool { + return execListRequest.SortBy.Key == o.SortBy.Key && execListRequest.SortBy.Direction == o.SortBy.Direction && execListRequest.Filters == o.Filters && execListRequest.Limit == o.Limit + })).Return(executionList, nil) err := getExecutionFunc(ctx, args, cmdCtx) assert.Nil(t, err) mockClient.AssertCalled(t, "ListExecutions", ctx, execListRequest) @@ -75,6 +83,9 @@ func TestListExecutionFuncWithError(t *testing.T) { cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) execListRequest := &admin.ResourceListRequest{ Limit: 100, + SortBy: &admin.Sort{ + Key: "created_at", + }, Id: &admin.NamedEntityIdentifier{ Project: projectValue, Domain: domainValue, @@ -104,7 +115,9 @@ func TestListExecutionFuncWithError(t *testing.T) { Phase: core.WorkflowExecution_SUCCEEDED, }, } - mockClient.OnListExecutionsMatch(ctx, execListRequest).Return(nil, errors.New("executions NotFound")) + mockClient.OnListExecutionsMatch(mock.Anything, mock.MatchedBy(func(o *admin.ResourceListRequest) bool { + return execListRequest.SortBy.Key == o.SortBy.Key && execListRequest.SortBy.Direction == o.SortBy.Direction && execListRequest.Filters == o.Filters && execListRequest.Limit == o.Limit + })).Return(nil, errors.New("executions NotFound")) err := getExecutionFunc(ctx, args, cmdCtx) assert.NotNil(t, err) assert.Equal(t, err, errors.New("executions NotFound")) diff --git a/flytectl/cmd/sandbox/start.go b/flytectl/cmd/sandbox/start.go index 082c12a54c..913e752d62 100644 --- a/flytectl/cmd/sandbox/start.go +++ b/flytectl/cmd/sandbox/start.go @@ -44,10 +44,10 @@ type ExecResult struct { } func startSandboxCluster(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { - fmt.Printf("%v It will take some time, We will start a fresh flyte cluster for you %v %v\n", emoji.ManTechnologist, emoji.Rocket, emoji.Rocket) + fmt.Printf("%v Bootstrapping a brand new flyte cluster... %v %v\n", emoji.FactoryWorker, emoji.Hammer, emoji.Wrench) cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) if err != nil { - fmt.Printf("Please Check your docker client %v \n", emoji.ManTechnologist) + fmt.Printf("%v Please Check your docker client %v \n", emoji.GrimacingFace, emoji.Whale) return err } @@ -72,13 +72,13 @@ func startSandboxCluster(ctx context.Context, args []string, cmdCtx cmdCore.Comm defer func() { if r := recover(); r != nil { - fmt.Println("Something goes wrong with container status", r) + fmt.Printf("%v Something went horribly wrong! %s\n", emoji.GrimacingFace, r) } }() ID, err := startContainer(cli, volumes) if err != nil { - fmt.Println("Something goes wrong. We are not able to start sandbox container, Please check your docker client and try again ") + fmt.Printf("%v Something went horribly wrong: Failed to start Sandbox container %v, Please check your docker client and try again. \n", emoji.GrimacingFace, emoji.Whale) return fmt.Errorf("error: %v", err) } diff --git a/flytectl/cmd/sandbox/teardown.go b/flytectl/cmd/sandbox/teardown.go index 8afced1178..9f2a217f25 100644 --- a/flytectl/cmd/sandbox/teardown.go +++ b/flytectl/cmd/sandbox/teardown.go @@ -40,6 +40,6 @@ func teardownSandboxCluster(ctx context.Context, args []string, cmdCtx cmdCore.C if err := configCleanup(); err != nil { fmt.Printf("Config cleanup failed. Which Failed due to %v \n ", err) } - fmt.Printf("Sandbox cluster is removed successfully %v \n", emoji.Rocket) + fmt.Printf("%v %v Sandbox cluster is removed successfully. \n", emoji.Broom, emoji.Broom) return nil } diff --git a/flytectl/go.mod b/flytectl/go.mod index 15c5c39675..e324ae6220 100644 --- a/flytectl/go.mod +++ b/flytectl/go.mod @@ -12,7 +12,6 @@ require ( github.com/flyteorg/flyteidl v0.19.3 github.com/flyteorg/flytestdlib v0.3.24 github.com/ghodss/yaml v1.0.0 - github.com/goccy/go-graphviz v0.0.9 github.com/golang/protobuf v1.4.3 github.com/google/go-github v17.0.0+incompatible github.com/google/go-querystring v1.1.0 // indirect diff --git a/flytectl/go.sum b/flytectl/go.sum index 3369537bf4..2638b091b6 100644 --- a/flytectl/go.sum +++ b/flytectl/go.sum @@ -271,8 +271,6 @@ github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+ github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/corona10/goimagehash v1.0.2 h1:pUfB0LnsJASMPGEZLj7tGY251vF+qLGqOgEP4rUs6kA= -github.com/corona10/goimagehash v1.0.2/go.mod h1:/l9umBhvcHQXVtQO1V6Gp1yD20STawkhRnnX0D1bvVI= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -344,8 +342,6 @@ github.com/flyteorg/flyteidl v0.19.3/go.mod h1:576W2ViEyjTpT+kEVHAGbrTP3HARNUZ/e github.com/flyteorg/flytestdlib v0.3.13/go.mod h1:Tz8JCECAbX6VWGwFT6cmEQ+RJpZ/6L9pswu3fzWs220= github.com/flyteorg/flytestdlib v0.3.24 h1:Eu5TMKch9ihOavPKufgTBI677eVYjJpOAPPg9hfZIzU= github.com/flyteorg/flytestdlib v0.3.24/go.mod h1:1XG0DwYTUm34Yrffm1Qy9Tdr/pWQypEqTq5dUxw3/cM= -github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= -github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= @@ -384,8 +380,6 @@ github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= -github.com/goccy/go-graphviz v0.0.9 h1:s/FMMJ1Joj6La3S5ApO3Jk2cwM4LpXECC2muFx3IPQQ= -github.com/goccy/go-graphviz v0.0.9/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk= github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e h1:BWhy2j3IXJhjCbC68FptL43tDKIq8FladmaTs3Xs7Z8= @@ -403,8 +397,6 @@ github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= -github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -544,7 +536,6 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA= -github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -661,8 +652,6 @@ github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ github.com/ncw/swift v1.0.49/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/ncw/swift v1.0.53 h1:luHjjTNtekIEvHg5KdAFIBaH7bWfNkefwFnpDffSIks= github.com/ncw/swift v1.0.53/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= -github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY= -github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= @@ -932,7 +921,6 @@ golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -951,8 +939,6 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.0.0-20200119044424-58c23975cae1 h1:5h3ngYt7+vXCDZCup/HkCQgW5XwmSvR/nA2JmJ0RErg= -golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/flytectl/pkg/filters/type.go b/flytectl/pkg/filters/type.go index 83b7d18a74..5dbad76923 100644 --- a/flytectl/pkg/filters/type.go +++ b/flytectl/pkg/filters/type.go @@ -3,8 +3,9 @@ package filters var ( DefaultLimit int32 = 100 DefaultFilter = Filters{ - Limit: DefaultLimit, - Asc: false, + Limit: DefaultLimit, + SortBy: "created_at", + Asc: false, } ) diff --git a/flytectl/pkg/printer/printer.go b/flytectl/pkg/printer/printer.go index 98282590fe..208b063195 100644 --- a/flytectl/pkg/printer/printer.go +++ b/flytectl/pkg/printer/printer.go @@ -44,6 +44,8 @@ func OutputFormats() []string { type Column struct { Header string JSONPath string + // Optional Truncation directive to limit content. This will simply truncate the string output. + TruncateTo *int } type Printer struct{} @@ -65,7 +67,14 @@ func extractRow(data interface{}, columns []Column) []string { if err != nil || out == nil { out = "" } - tableData = append(tableData, fmt.Sprintf("%s", out)) + s := fmt.Sprintf("%s", out) + if c.TruncateTo != nil { + t := *c.TruncateTo + if len(s) > t { + s = s[:t] + } + } + tableData = append(tableData, s) } return tableData } diff --git a/flytectl/pkg/printer/printer_test.go b/flytectl/pkg/printer/printer_test.go index 08ed10c9f2..faa11a1978 100644 --- a/flytectl/pkg/printer/printer_test.go +++ b/flytectl/pkg/printer/printer_test.go @@ -38,6 +38,7 @@ func WorkflowToProtoMessages(l []*admin.Workflow) []proto.Message { // TODO Convert this to a Testable Example. For some reason the comparison fails func TestJSONToTable(t *testing.T) { + trunc := 5 d := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC) j := []struct { A string `json:"a"` @@ -45,7 +46,7 @@ func TestJSONToTable(t *testing.T) { S *Inner `json:"s"` }{ {"hello", 0, &Inner{"x-hello", nil}}, - {"hello", 0, &Inner{"x-hello", &d}}, + {"hello world", 0, &Inner{"x-hello", &d}}, {"hello", 0, nil}, } @@ -53,8 +54,8 @@ func TestJSONToTable(t *testing.T) { assert.NoError(t, err) p := Printer{} assert.NoError(t, p.JSONToTable(b, []Column{ - {"A", "$.a"}, - {"S", "$.s.y"}, + {"A", "$.a", &trunc}, + {"S", "$.s.y", nil}, })) // Output: // | A | S |