Skip to content

Commit

Permalink
Fix TestVtctldclientCLI
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Feb 15, 2025
1 parent a9d3ac9 commit fbffb28
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
4 changes: 0 additions & 4 deletions go/cmd/vtctldclient/command/vreplication/common/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func commandShow(cmd *cobra.Command, args []string) error {
// We always use compact format with SHOW to reduce the overall
// size and noise.
cli.DefaultMarshalOptions.EmitUnpopulated = false
if len(resp.Workflows) == 0 {
return fmt.Errorf("workflow %s not found in the %s keyspace",
BaseOptions.Workflow, BaseOptions.TargetKeyspace)
}
data, err := cli.MarshalJSONPretty(resp)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions go/cmd/vtctldclient/command/vreplication/workflow/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ func commandGetWorkflows(cmd *cobra.Command, args []string) error {
ks := cmd.Flags().Arg(0)

resp, err := common.GetClient().GetWorkflows(common.GetCommandCtx(), &vtctldatapb.GetWorkflowsRequest{
Keyspace: ks,
ActiveOnly: !getWorkflowsOptions.ShowAll,
IncludeLogs: workflowShowOptions.IncludeLogs,
Keyspace: ks,
ActiveOnly: !getWorkflowsOptions.ShowAll,
IncludeLogs: workflowShowOptions.IncludeLogs,
VerbosityLevel: workflowShowOptions.VerbosityLevel,
})

if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions go/cmd/vtctldclient/command/vreplication/workflow/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ func commandShow(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

req := &vtctldatapb.GetWorkflowsRequest{
Keyspace: baseOptions.Keyspace,
Workflow: baseOptions.Workflow,
IncludeLogs: workflowShowOptions.IncludeLogs,
Shards: baseOptions.Shards,
Keyspace: baseOptions.Keyspace,
Workflow: baseOptions.Workflow,
IncludeLogs: workflowShowOptions.IncludeLogs,
Shards: baseOptions.Shards,
VerbosityLevel: workflowShowOptions.VerbosityLevel,
}
resp, err := common.GetClient().GetWorkflows(common.GetCommandCtx(), req)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ var (
}{}

workflowShowOptions = struct {
IncludeLogs bool
IncludeLogs bool
VerbosityLevel uint32
}{}
)

Expand All @@ -55,6 +56,7 @@ func registerCommands(root *cobra.Command) {

getWorkflows.Flags().BoolVar(&workflowShowOptions.IncludeLogs, "include-logs", true, "Include recent logs for the workflows.")
getWorkflows.Flags().BoolVarP(&getWorkflowsOptions.ShowAll, "show-all", "a", false, "Show all workflows instead of just active workflows.")
getWorkflows.Flags().Uint32Var(&workflowShowOptions.VerbosityLevel, "verbosity-level", 0, "How much detail to include in the results.")
root.AddCommand(getWorkflows) // Yes this is supposed to be root as GetWorkflows is a top-level command.

delete.Flags().StringVarP(&baseOptions.Workflow, "workflow", "w", "", "The workflow you want to delete.")
Expand All @@ -71,6 +73,7 @@ func registerCommands(root *cobra.Command) {
show.Flags().StringVarP(&baseOptions.Workflow, "workflow", "w", "", "The workflow you want the details for.")
show.MarkFlagRequired("workflow")
show.Flags().BoolVar(&workflowShowOptions.IncludeLogs, "include-logs", true, "Include recent logs for the workflow.")
show.Flags().Uint32Var(&workflowShowOptions.VerbosityLevel, "verbosity-level", 0, "How much detail to include in the results.")
common.AddShardSubsetFlag(show, &baseOptions.Shards)
base.AddCommand(show)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/tidwall/gjson"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"

"vitess.io/vitess/go/json2"
"vitess.io/vitess/go/test/endtoend/cluster"
Expand Down Expand Up @@ -152,7 +153,8 @@ func testMoveTablesFlags1(t *testing.T, mt *iMoveTables, sourceKeyspace, targetK
workflowResponse := getWorkflow(targetKeyspace, workflowName)

// also validates that MoveTables Show and Workflow Show return the same output.
require.EqualValues(t, moveTablesResponse.CloneVT(), workflowResponse)
//require.EqualValues(t, moveTablesResponse.CloneVT(), workflowResponse)
require.True(t, proto.Equal(moveTablesResponse.CloneVT(), workflowResponse))

// Validate that the flags are set correctly in the database.
validateMoveTablesWorkflow(t, workflowResponse.Workflows)
Expand Down Expand Up @@ -485,7 +487,7 @@ func splitShard(t *testing.T, keyspace, workflowName, sourceShards, targetShards
validateOverrides(t, targetTabs, overrides)
workflowResponse := getWorkflow(keyspace, workflowName)
reshardShowResponse := getReshardShowResponse(&rs)
require.EqualValues(t, reshardShowResponse, workflowResponse)
require.True(t, proto.Equal(reshardShowResponse, workflowResponse))
validateReshardWorkflow(t, workflowResponse.Workflows)
waitForWorkflowState(t, vc, fmt.Sprintf("%s.%s", keyspace, workflowName), binlogdatapb.VReplicationWorkflowState_Stopped.String())
rs.Start()
Expand Down Expand Up @@ -709,8 +711,8 @@ func getReshardResponse(rs iReshard) *vtctldatapb.WorkflowStatusResponse {
// helper functions

func getWorkflow(targetKeyspace, workflow string) *vtctldatapb.GetWorkflowsResponse {
workflowOutput, err := vc.VtctldClient.ExecuteCommandWithOutput("Workflow", "--keyspace", targetKeyspace, "show", "--workflow", workflow)
require.NoError(vc.t, err)
workflowOutput, err := vc.VtctldClient.ExecuteCommandWithOutput("Workflow", "--keyspace", targetKeyspace, "show", "--workflow", workflow, verbosityFlag)
require.NoError(vc.t, err, workflowOutput)
var workflowResponse vtctldatapb.GetWorkflowsResponse
err = protojson.Unmarshal([]byte(workflowOutput), &workflowResponse)
require.NoError(vc.t, err)
Expand All @@ -720,8 +722,8 @@ func getWorkflow(targetKeyspace, workflow string) *vtctldatapb.GetWorkflowsRespo
}

func getWorkflows(targetKeyspace string) *vtctldatapb.GetWorkflowsResponse {
getWorkflowsOutput, err := vc.VtctldClient.ExecuteCommandWithOutput("GetWorkflows", targetKeyspace, "--show-all", "--compact", "--include-logs=false")
require.NoError(vc.t, err)
getWorkflowsOutput, err := vc.VtctldClient.ExecuteCommandWithOutput("GetWorkflows", targetKeyspace, "--show-all", "--compact", "--include-logs=false", verbosityFlag)
require.NoError(vc.t, err, getWorkflowsOutput)
var getWorkflowsResponse vtctldatapb.GetWorkflowsResponse
err = protojson.Unmarshal([]byte(getWorkflowsOutput), &getWorkflowsResponse)
require.NoError(vc.t, err)
Expand Down
7 changes: 6 additions & 1 deletion go/test/endtoend/vreplication/wrappers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package vreplication

import (
"fmt"
"math"
"math/rand/v2"
"strconv"
"strings"
Expand All @@ -26,6 +28,8 @@ import (
"vitess.io/vitess/go/vt/log"
)

var verbosityFlag = fmt.Sprintf("--verbosity-level=%d", math.MaxUint32)

type iWorkflow interface {
Create()
Show()
Expand Down Expand Up @@ -163,6 +167,7 @@ func (v VtctldMoveTables) ReverseReadsAndWrites() {

func (v VtctldMoveTables) Show() {
args := []string{"Show"}
args = append(args, verbosityFlag)
args = append(args, v.showFlags...)
v.exec(args...)
}
Expand Down Expand Up @@ -308,7 +313,7 @@ func (v VtctldReshard) ReverseReadsAndWrites() {
}

func (v VtctldReshard) Show() {
v.exec("Show")
v.exec("Show", verbosityFlag)
}

func (v *VtctldReshard) Status() {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtctl/workflow/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ func (wf *workflowFetcher) scanWorkflow(

workflow.ShardStreams[shardStreamKey] = shardStream
}
workflow.WorkflowType = res.WorkflowType.String()

for _, rstream := range res.Streams {
// The value in the pos column can be compressed and thus not
Expand Down Expand Up @@ -428,7 +429,6 @@ func (wf *workflowFetcher) scanWorkflow(
if vreplicationLag.Seconds() > meta.maxVReplicationLag {
meta.maxVReplicationLag = vreplicationLag.Seconds()
}
workflow.WorkflowType = res.WorkflowType.String()
workflow.WorkflowSubType = res.WorkflowSubType.String()
workflow.DeferSecondaryKeys = res.DeferSecondaryKeys
}
Expand Down

0 comments on commit fbffb28

Please sign in to comment.