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

[vtadmin-api] Update GetTablet to use alias instead of hostname #8163

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
262 changes: 131 additions & 131 deletions go/vt/proto/vtadmin/vtadmin.pb.go

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions go/vt/vtadmin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,15 @@ func (api *API) GetTablet(ctx context.Context, req *vtadminpb.GetTabletRequest)
span, ctx := trace.NewSpan(ctx, "API.GetTablet")
defer span.Finish()

span.Annotate("tablet_hostname", req.Hostname)
span.Annotate("tablet_alias", req.Alias)

alias, err := topoproto.ParseTabletAlias(req.Alias)
if err != nil {
return nil, fmt.Errorf("failed to parse tablet_alias %s: %w", req.Alias, err)
}

span.Annotate("tablet_cell", alias.Cell)
span.Annotate("tablet_uid", alias.Uid)

clusters, ids := api.getClustersForRequest(req.ClusterIds)

Expand All @@ -549,7 +557,7 @@ func (api *API) GetTablet(ctx context.Context, req *vtadminpb.GetTabletRequest)
var found []*vtadminpb.Tablet

for _, t := range ts {
if t.Tablet.Hostname == req.Hostname {
if t.Tablet.Alias.Cell == alias.Cell && t.Tablet.Alias.Uid == alias.Uid {
found = append(found, t)
}
}
Expand All @@ -568,12 +576,12 @@ func (api *API) GetTablet(ctx context.Context, req *vtadminpb.GetTabletRequest)

switch len(tablets) {
case 0:
return nil, vterrors.Errorf(vtrpcpb.Code_NOT_FOUND, "%s: %s, searched clusters = %v", errors.ErrNoTablet, req.Hostname, ids)
return nil, vterrors.Errorf(vtrpcpb.Code_NOT_FOUND, "%s: %s, searched clusters = %v", errors.ErrNoTablet, req.Alias, ids)
case 1:
return tablets[0], nil
}

return nil, vterrors.Errorf(vtrpcpb.Code_NOT_FOUND, "%s: %s, searched clusters = %v", errors.ErrAmbiguousTablet, req.Hostname, ids)
return nil, vterrors.Errorf(vtrpcpb.Code_NOT_FOUND, "%s: %s, searched clusters = %v", errors.ErrAmbiguousTablet, req.Alias, ids)
}

// GetTablets is part of the vtadminpb.VTAdminServer interface.
Expand Down
12 changes: 6 additions & 6 deletions go/vt/vtadmin/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ func TestGetTablet(t *testing.T) {
},
dbconfigs: map[string]vtadmintestutil.Dbcfg{},
req: &vtadminpb.GetTabletRequest{
Hostname: "ks1-00-00-zone1-a",
Alias: "zone1-100",
},
expected: &vtadminpb.Tablet{
Cluster: &vtadminpb.Cluster{
Expand Down Expand Up @@ -2592,7 +2592,7 @@ func TestGetTablet(t *testing.T) {
"c1": {ShouldErr: true},
},
req: &vtadminpb.GetTabletRequest{
Hostname: "doesn't matter",
Alias: "doesn't matter",
},
expected: nil,
shouldErr: true,
Expand Down Expand Up @@ -2635,7 +2635,7 @@ func TestGetTablet(t *testing.T) {
},
dbconfigs: map[string]vtadmintestutil.Dbcfg{},
req: &vtadminpb.GetTabletRequest{
Hostname: "ks1-00-00-zone1-a",
Alias: "zone1-100",
ClusterIds: []string{"c0"},
},
expected: &vtadminpb.Tablet{
Expand Down Expand Up @@ -2682,7 +2682,7 @@ func TestGetTablet(t *testing.T) {
State: vtadminpb.Tablet_SERVING,
Tablet: &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Uid: 200,
Uid: 100,
Cell: "zone1",
},
Hostname: "ks1-00-00-zone1-a",
Expand All @@ -2695,7 +2695,7 @@ func TestGetTablet(t *testing.T) {
},
dbconfigs: map[string]vtadmintestutil.Dbcfg{},
req: &vtadminpb.GetTabletRequest{
Hostname: "ks1-00-00-zone1-a",
Alias: "zone1-100",
},
expected: nil,
shouldErr: true,
Expand All @@ -2708,7 +2708,7 @@ func TestGetTablet(t *testing.T) {
},
dbconfigs: map[string]vtadmintestutil.Dbcfg{},
req: &vtadminpb.GetTabletRequest{
Hostname: "ks1-00-00-zone1-a",
Alias: "zone1-100",
},
expected: nil,
shouldErr: true,
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtadmin/http/experimental/tablets.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TabletDebugVarsPassthrough(ctx context.Context, r vtadminhttp.Request, api
vars := r.Vars()

tablet, err := api.Server().GetTablet(ctx, &vtadminpb.GetTabletRequest{
Hostname: vars["tablet"],
Alias: vars["tablet"],
ClusterIds: r.URL.Query()["cluster"],
})

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtadmin/http/tablets.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetTablet(ctx context.Context, r Request, api *API) *JSONResponse {
vars := r.Vars()

tablet, err := api.server.GetTablet(ctx, &vtadminpb.GetTabletRequest{
Hostname: vars["tablet"],
Alias: vars["tablet"],
ClusterIds: r.URL.Query()["cluster"],
})

Expand Down
3 changes: 2 additions & 1 deletion proto/vtadmin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ message GetSchemaTableSizeOptions {
}

message GetTabletRequest {
string hostname = 1;
// Unique (per cluster) tablet alias of the standard form: "$cell-$uid"
string alias = 1;
// ClusterIDs is an optional parameter to narrow the scope of the search, if
// the caller knows which cluster the tablet may be in, or, to disamiguate if
// multiple clusters have a tablet with the same hostname.
Expand Down
8 changes: 4 additions & 4 deletions web/vtadmin/src/proto/vtadmin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2592,8 +2592,8 @@ export namespace vtadmin {
/** Properties of a GetTabletRequest. */
interface IGetTabletRequest {

/** GetTabletRequest hostname */
hostname?: (string|null);
/** GetTabletRequest alias */
alias?: (string|null);

/** GetTabletRequest cluster_ids */
cluster_ids?: (string[]|null);
Expand All @@ -2608,8 +2608,8 @@ export namespace vtadmin {
*/
constructor(properties?: vtadmin.IGetTabletRequest);

/** GetTabletRequest hostname. */
public hostname: string;
/** GetTabletRequest alias. */
public alias: string;

/** GetTabletRequest cluster_ids. */
public cluster_ids: string[];
Expand Down
30 changes: 15 additions & 15 deletions web/vtadmin/src/proto/vtadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6029,7 +6029,7 @@ $root.vtadmin = (function() {
* Properties of a GetTabletRequest.
* @memberof vtadmin
* @interface IGetTabletRequest
* @property {string|null} [hostname] GetTabletRequest hostname
* @property {string|null} [alias] GetTabletRequest alias
* @property {Array.<string>|null} [cluster_ids] GetTabletRequest cluster_ids
*/

Expand All @@ -6050,12 +6050,12 @@ $root.vtadmin = (function() {
}

/**
* GetTabletRequest hostname.
* @member {string} hostname
* GetTabletRequest alias.
* @member {string} alias
* @memberof vtadmin.GetTabletRequest
* @instance
*/
GetTabletRequest.prototype.hostname = "";
GetTabletRequest.prototype.alias = "";

/**
* GetTabletRequest cluster_ids.
Expand Down Expand Up @@ -6089,8 +6089,8 @@ $root.vtadmin = (function() {
GetTabletRequest.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.hostname != null && Object.hasOwnProperty.call(message, "hostname"))
writer.uint32(/* id 1, wireType 2 =*/10).string(message.hostname);
if (message.alias != null && Object.hasOwnProperty.call(message, "alias"))
writer.uint32(/* id 1, wireType 2 =*/10).string(message.alias);
if (message.cluster_ids != null && message.cluster_ids.length)
for (var i = 0; i < message.cluster_ids.length; ++i)
writer.uint32(/* id 2, wireType 2 =*/18).string(message.cluster_ids[i]);
Expand Down Expand Up @@ -6129,7 +6129,7 @@ $root.vtadmin = (function() {
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.hostname = reader.string();
message.alias = reader.string();
break;
case 2:
if (!(message.cluster_ids && message.cluster_ids.length))
Expand Down Expand Up @@ -6171,9 +6171,9 @@ $root.vtadmin = (function() {
GetTabletRequest.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.hostname != null && message.hasOwnProperty("hostname"))
if (!$util.isString(message.hostname))
return "hostname: string expected";
if (message.alias != null && message.hasOwnProperty("alias"))
if (!$util.isString(message.alias))
return "alias: string expected";
if (message.cluster_ids != null && message.hasOwnProperty("cluster_ids")) {
if (!Array.isArray(message.cluster_ids))
return "cluster_ids: array expected";
Expand All @@ -6196,8 +6196,8 @@ $root.vtadmin = (function() {
if (object instanceof $root.vtadmin.GetTabletRequest)
return object;
var message = new $root.vtadmin.GetTabletRequest();
if (object.hostname != null)
message.hostname = String(object.hostname);
if (object.alias != null)
message.alias = String(object.alias);
if (object.cluster_ids) {
if (!Array.isArray(object.cluster_ids))
throw TypeError(".vtadmin.GetTabletRequest.cluster_ids: array expected");
Expand All @@ -6224,9 +6224,9 @@ $root.vtadmin = (function() {
if (options.arrays || options.defaults)
object.cluster_ids = [];
if (options.defaults)
object.hostname = "";
if (message.hostname != null && message.hasOwnProperty("hostname"))
object.hostname = message.hostname;
object.alias = "";
if (message.alias != null && message.hasOwnProperty("alias"))
object.alias = message.alias;
if (message.cluster_ids && message.cluster_ids.length) {
object.cluster_ids = [];
for (var j = 0; j < message.cluster_ids.length; ++j)
Expand Down