Skip to content

Commit

Permalink
Merge pull request vitessio#10905 from planetscale/vtctld-full-status (
Browse files Browse the repository at this point in the history
…#357)

Add GetFullStatus RPC to vtctld

Co-authored-by: Deepthi Sigireddi <deepthi@planetscale.com>
  • Loading branch information
timvaillancourt and deepthi committed May 21, 2024
1 parent af819e5 commit 8ce8799
Show file tree
Hide file tree
Showing 17 changed files with 2,571 additions and 1,361 deletions.
33 changes: 33 additions & 0 deletions go/cmd/vtctldclient/command/tablets.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ Note: hook names may not contain slash (/) characters.
Args: cobra.MinimumNArgs(2),
RunE: commandExecuteHook,
}
// GetFullStatus makes a FullStatus gRPC call to a vttablet.
GetFullStatus = &cobra.Command{
Use: "GetFullStatus <alias>",
Short: "Outputs a JSON structure that contains full status of MySQL including the replication information, semi-sync information, GTID information among others.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandGetFullStatus,
}
// GetPermissions makes a GetPermissions gRPC call to a vtctld.
GetPermissions = &cobra.Command{
Use: "GetPermissions <tablet_alias>",
Expand Down Expand Up @@ -299,6 +307,30 @@ func commandExecuteHook(cmd *cobra.Command, args []string) error {
return nil
}

func commandGetFullStatus(cmd *cobra.Command, args []string) error {
aliasStr := cmd.Flags().Arg(0)
alias, err := topoproto.ParseTabletAlias(aliasStr)
if err != nil {
return err
}

cli.FinishedParsing(cmd)

resp, err := client.GetFullStatus(commandCtx, &vtctldatapb.GetFullStatusRequest{TabletAlias: alias})
if err != nil {
return err
}

data, err := cli.MarshalJSON(resp.Status)
if err != nil {
return err
}

fmt.Printf("%s\n", data)

return nil
}

func commandGetPermissions(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
Expand Down Expand Up @@ -596,6 +628,7 @@ func init() {
Root.AddCommand(DeleteTablets)

Root.AddCommand(ExecuteHook)
Root.AddCommand(GetFullStatus)
Root.AddCommand(GetPermissions)
Root.AddCommand(GetTablet)

Expand Down
5 changes: 3 additions & 2 deletions go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ type LocalProcessCluster struct {
VtctlMajorVersion int

// standalone executable
VtctlclientProcess VtctlClientProcess
VtctlProcess VtctlProcess
VtctlclientProcess VtctlClientProcess
VtctldClientProcess VtctldClientProcess
VtctlProcess VtctlProcess

// background executable processes
TopoProcess TopoProcess
Expand Down
18 changes: 13 additions & 5 deletions go/test/endtoend/reparent/newfeaturetest/reparent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/encoding/protojson"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/reparent/utils"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
replicationdatapb "vitess.io/vitess/go/vt/proto/replicationdata"
)

// ERS TESTS
Expand Down Expand Up @@ -134,7 +136,10 @@ func TestFullStatus(t *testing.T) {
utils.ConfirmReplication(t, tablets[0], []*cluster.Vttablet{tablets[1], tablets[2], tablets[3]})

// Check that full status gives the correct result for a primary tablet
primaryStatus, err := utils.TmcFullStatus(context.Background(), tablets[0])
primaryStatusString, err := clusterInstance.VtctldClientProcess.ExecuteCommandWithOutput("GetFullStatus", tablets[0].Alias)
require.NoError(t, err)
primaryStatus := &replicationdatapb.FullStatus{}
err = protojson.Unmarshal([]byte(primaryStatusString), primaryStatus)
require.NoError(t, err)
assert.NotEmpty(t, primaryStatus.ServerUuid)
assert.NotEmpty(t, primaryStatus.ServerId)
Expand All @@ -159,7 +164,10 @@ func TestFullStatus(t *testing.T) {
assert.NotEmpty(t, primaryStatus.VersionComment)

// Check that full status gives the correct result for a replica tablet
replicaStatus, err := utils.TmcFullStatus(context.Background(), tablets[1])
replicaStatusString, err := clusterInstance.VtctldClientProcess.ExecuteCommandWithOutput("GetFullStatus", tablets[1].Alias)
require.NoError(t, err)
replicaStatus := &replicationdatapb.FullStatus{}
err = protojson.Unmarshal([]byte(replicaStatusString), replicaStatus)
require.NoError(t, err)
assert.NotEmpty(t, replicaStatus.ServerUuid)
assert.NotEmpty(t, replicaStatus.ServerId)
Expand Down
23 changes: 3 additions & 20 deletions go/test/endtoend/reparent/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import (
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/vt/log"
tmc "vitess.io/vitess/go/vt/vttablet/grpctmclient"

replicationdatapb "vitess.io/vitess/go/vt/proto/replicationdata"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
)
Expand Down Expand Up @@ -163,8 +161,8 @@ func setupCluster(ctx context.Context, t *testing.T, shardName string, cells []s
}
}
if clusterInstance.VtctlMajorVersion >= 14 {
vtctldClientProcess := cluster.VtctldClientProcessInstance("localhost", clusterInstance.VtctldProcess.GrpcPort, clusterInstance.TmpDirectory)
out, err := vtctldClientProcess.ExecuteCommandWithOutput("SetKeyspaceDurabilityPolicy", KeyspaceName, fmt.Sprintf("--durability-policy=%s", durability))
clusterInstance.VtctldClientProcess = *cluster.VtctldClientProcessInstance("localhost", clusterInstance.VtctldProcess.GrpcPort, clusterInstance.TmpDirectory)
out, err := clusterInstance.VtctldClientProcess.ExecuteCommandWithOutput("SetKeyspaceDurabilityPolicy", KeyspaceName, fmt.Sprintf("--durability-policy=%s", durability))
require.NoError(t, err, out)
}

Expand Down Expand Up @@ -327,7 +325,7 @@ func setupShardLegacy(ctx context.Context, t *testing.T, clusterInstance *cluste

//endregion

//region database queries
// region database queries
func getMysqlConnParam(tablet *cluster.Vttablet) mysql.ConnParams {
connParams := mysql.ConnParams{
Uname: username,
Expand Down Expand Up @@ -788,18 +786,3 @@ func ReplicationThreadsStatus(t *testing.T, status *replicationdatapb.Status, vt
}
return ioThread, sqlThread
}

// TmcFullStatus retuns the result of the TabletManagerClient RPC FullStatus
func TmcFullStatus(ctx context.Context, tablet *cluster.Vttablet) (*replicationdatapb.FullStatus, error) {
// create tablet manager client
tmClient := tmc.NewClient()

vttablet := getTablet(tablet.GrpcPort)
return tmClient.FullStatus(ctx, vttablet)
}

func getTablet(tabletGrpcPort int) *topodatapb.Tablet {
portMap := make(map[string]int32)
portMap["grpc"] = int32(tabletGrpcPort)
return &topodatapb.Tablet{Hostname: Hostname, PortMap: portMap}
}
Loading

0 comments on commit 8ce8799

Please sign in to comment.