Skip to content

Commit c5d149d

Browse files
VReplication: Add traffic state to vtctldclient workflow status output (#14280)
Signed-off-by: Matt Lord <mattalord@gmail.com>
1 parent fe31219 commit c5d149d

File tree

10 files changed

+233
-139
lines changed

10 files changed

+233
-139
lines changed

go/cmd/vtctldclient/command/vreplication/common/status.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func GetStatusCommand(opts *SubCommandsOpts) *cobra.Command {
4040
}
4141

4242
func commandStatus(cmd *cobra.Command, args []string) error {
43+
format, err := GetOutputFormat(cmd)
44+
if err != nil {
45+
return err
46+
}
4347
cli.FinishedParsing(cmd)
4448

4549
req := &vtctldatapb.WorkflowStatusRequest{
@@ -51,7 +55,7 @@ func commandStatus(cmd *cobra.Command, args []string) error {
5155
return err
5256
}
5357

54-
if err = OutputStatusResponse(resp, "json"); err != nil {
58+
if err = OutputStatusResponse(resp, format); err != nil {
5559
return err
5660
}
5761

go/cmd/vtctldclient/command/vreplication/common/utils.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ func OutputStatusResponse(resp *vtctldatapb.WorkflowStatusResponse, format strin
165165
shardstream.Id, BaseOptions.TargetKeyspace, tablet, shardstream.Status, shardstream.Info))
166166
}
167167
}
168+
tout.WriteString("\nTraffic State: ")
169+
tout.WriteString(resp.TrafficState)
168170
output = tout.Bytes()
169171
}
170-
fmt.Printf("%s\n", output)
172+
fmt.Println(string(output))
171173
return nil
172174
}
173175

go/test/endtoend/vreplication/migrate_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,17 @@ func TestVtctldMigrate(t *testing.T) {
221221
var output, expected string
222222

223223
t.Run("mount external cluster", func(t *testing.T) {
224-
output, err := vc.VtctldClient.ExecuteCommandWithOutput("Mount", "Register", "--topo-type=etcd2",
224+
output, err := vc.VtctldClient.ExecuteCommandWithOutput("Mount", "register", "--topo-type=etcd2",
225225
fmt.Sprintf("--topo-server=localhost:%d", extVc.ClusterConfig.topoPort), "--topo-root=/vitess/global", "ext1")
226226
require.NoError(t, err, "Mount Register command failed with %s", output)
227227

228-
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "List")
228+
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "list")
229229
require.NoError(t, err, "Mount List command failed with %s", output)
230230

231231
names := gjson.Get(output, "names")
232232
require.Equal(t, 1, len(names.Array()))
233233
require.Equal(t, "ext1", names.Array()[0].String())
234-
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "Show", "ext1")
234+
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "show", "ext1")
235235
require.NoError(t, err, "Mount command failed with %s\n", output)
236236

237237
require.Equal(t, "etcd2", gjson.Get(output, "topo_type").String())
@@ -244,7 +244,7 @@ func TestVtctldMigrate(t *testing.T) {
244244
t.Run("migrate from external cluster", func(t *testing.T) {
245245
if output, err = vc.VtctldClient.ExecuteCommandWithOutput("Migrate",
246246
"--target-keyspace", "product", "--workflow", "e1",
247-
"Create", "--source-keyspace", "rating", "--mount-name", "ext1", "--all-tables", "--cells=extcell1", "--tablet-types=primary,replica"); err != nil {
247+
"create", "--source-keyspace", "rating", "--mount-name", "ext1", "--all-tables", "--cells=extcell1", "--tablet-types=primary,replica"); err != nil {
248248
t.Fatalf("Migrate command failed with %+v : %s\n", err, output)
249249
}
250250
waitForWorkflowState(t, vc, ksWorkflow, binlogdatapb.VReplicationWorkflowState_Running.String())
@@ -258,21 +258,21 @@ func TestVtctldMigrate(t *testing.T) {
258258
vdiffSideBySide(t, ksWorkflow, "extcell1")
259259

260260
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Migrate",
261-
"--target-keyspace", "product", "--workflow", "e1", "Show")
261+
"--target-keyspace", "product", "--workflow", "e1", "show")
262262
require.NoError(t, err, "Migrate command failed with %s", output)
263263

264264
wf := gjson.Get(output, "workflows").Array()[0]
265265
require.Equal(t, "e1", wf.Get("name").String())
266266
require.Equal(t, "Migrate", wf.Get("workflow_type").String())
267267

268268
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Migrate",
269-
"--target-keyspace", "product", "--workflow", "e1", "Progress")
269+
"--target-keyspace", "product", "--workflow", "e1", "status", "--format=json")
270270
require.NoError(t, err, "Migrate command failed with %s", output)
271271

272272
require.Equal(t, "Running", gjson.Get(output, "shard_streams.product/0.streams.0.status").String())
273273

274274
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Migrate",
275-
"--target-keyspace", "product", "--workflow", "e1", "Complete")
275+
"--target-keyspace", "product", "--workflow", "e1", "complete")
276276
require.NoError(t, err, "Migrate command failed with %s", output)
277277

278278
expectNumberOfStreams(t, vtgateConn, "migrate", "e1", "product:0", 0)
@@ -288,7 +288,7 @@ func TestVtctldMigrate(t *testing.T) {
288288
waitForRowCount(t, vtgateConn, "product:0", "rating", 0)
289289
waitForRowCount(t, vtgateConn, "product:0", "review", 0)
290290
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Migrate",
291-
"--target-keyspace", "product", "--workflow", "e1", "Cancel")
291+
"--target-keyspace", "product", "--workflow", "e1", "cancel")
292292
require.NoError(t, err, "Migrate command failed with %s", output)
293293

294294
expectNumberOfStreams(t, vtgateConn, "migrate", "e1", "product:0", 0)
@@ -302,15 +302,15 @@ func TestVtctldMigrate(t *testing.T) {
302302
})
303303

304304
t.Run("unmount external cluster", func(t *testing.T) {
305-
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "Unregister", "ext1")
305+
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "unregister", "ext1")
306306
require.NoError(t, err, "Mount command failed with %s\n", output)
307307

308-
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "List")
308+
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "list")
309309
require.NoError(t, err, "Mount command failed with %+v : %s\n", output)
310310
expected = "{}\n"
311311
require.Equal(t, expected, output)
312312

313-
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "Show", "ext1")
313+
output, err = vc.VtctldClient.ExecuteCommandWithOutput("Mount", "show", "ext1")
314314
require.Errorf(t, err, "there is no vitess cluster named ext1")
315315
})
316316
}

0 commit comments

Comments
 (0)