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

Add vtctldclient missing cmds #17442

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Dec 27, 2024

Description

This implements client commands in vtctldclient that were never ported during the client migration. These are things that were identified while moving all endtoend tests to use vtctldclient exclusively in #17441.

We will (after merging in main once #17441 is merged) also then replace all remaining vtctlclient usage in the e2e tests with usage of these new vtctldclient commands.

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Copy link
Contributor

vitess-bot bot commented Dec 27, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Dec 27, 2024
@mattlord mattlord added Type: Internal Cleanup Component: vtctldclient and removed NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Dec 27, 2024
@github-actions github-actions bot added this to the v22.0.0 milestone Dec 27, 2024
Copy link

codecov bot commented Dec 27, 2024

Codecov Report

Attention: Patch coverage is 11.18644% with 262 lines in your changes missing coverage. Please review.

Project coverage is 67.61%. Comparing base (059d01a) to head (9e87209).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtctl/grpcvtctldserver/server.go 7.00% 93 Missing ⚠️
go/cmd/vtctldclient/command/schema.go 18.44% 84 Missing ⚠️
go/cmd/vtctldclient/command/permissions.go 8.51% 43 Missing ⚠️
go/cmd/vtctldclient/command/topology.go 9.67% 28 Missing ⚠️
go/vt/vtctl/grpcvtctldclient/client_gen.go 0.00% 10 Missing ⚠️
go/vt/vtctl/localvtctldclient/client_gen.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17442      +/-   ##
==========================================
- Coverage   67.68%   67.61%   -0.08%     
==========================================
  Files        1583     1585       +2     
  Lines      254321   254596     +275     
==========================================
+ Hits       172131   172135       +4     
- Misses      82190    82461     +271     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mattlord mattlord force-pushed the vtctldclient_missing_cmds branch 2 times, most recently from 9824c10 to ec59343 Compare December 27, 2024 12:41
@mattlord mattlord force-pushed the vtctldclient_missing_cmds branch from ec59343 to 851ccac Compare December 27, 2024 22:53
Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord force-pushed the vtctldclient_missing_cmds branch from 8c5f3e9 to 05c4c1d Compare December 27, 2024 23:47
Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request labels Dec 28, 2024
}

message ValidatePermissionsKeyspaceResponse {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not contain any results?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it returns an error if there's a validation failure:

vitess/go/vt/vtctl/vtctl.go

Lines 3259 to 3269 in 76abae4

func commandValidatePermissionsKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags *pflag.FlagSet, args []string) error {
if err := subFlags.Parse(args); err != nil {
return err
}
if subFlags.NArg() != 1 {
return fmt.Errorf("the <keyspace name> argument is required for the ValidatePermissionsKeyspace command")
}
keyspace := subFlags.Arg(0)
return wr.ValidatePermissionsKeyspace(ctx, keyspace)
}

We could change that, of course, but here I'm primarily just porting these missing commands over.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this as common practice to sometimes have empty responses, where it's "error or nothing" and with the potential of adding proto fields in the future without breaking gRPC signature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess this is more a question for a separate change perhaps. But given we have various inputs with different shards, wouldn't we want to reflect that in the output similar to the next command listed here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point, worth extended discussion.

Copy link
Contributor Author

@mattlord mattlord Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"We" here would be whomever uses and consumes this command (certainly not me to date). This PR is about migrating the missing but still used/needed commands from the old client to the new, where maintaining "drop in compatibility" is the only concern. Why are we discussing this here? Is there some feature gap or request? If so, we should open a feature request that lays it out and someone can pick that up at a later date.

I'm actually leaning towards removing the endtoend test code for it (ValidatePermissions*, as I did with CopySchemaShard) since I cannot find anything that actually uses it today (in vitess, vitess-operator, etc):

go/test/endtoend/sharded/sharded_keyspace_test.go:      err = clusterInstance.VtctlclientProcess.ExecuteCommand("ValidatePermissionsShard", fmt.Sprintf("%s/%s", keyspaceName, shard1.Name))
go/test/endtoend/sharded/sharded_keyspace_test.go:      err = clusterInstance.VtctlclientProcess.ExecuteCommand("ValidatePermissionsKeyspace", keyspaceName)
go/vt/vtctl/vtctl.go:                           name:   "ValidatePermissionsShard",
go/vt/vtctl/vtctl.go:                           method: commandValidatePermissionsShard,
go/vt/vtctl/vtctl.go:                           name:   "ValidatePermissionsKeyspace",
go/vt/vtctl/vtctl.go:                           method: commandValidatePermissionsKeyspace,
go/vt/vtctl/vtctl.go:func commandValidatePermissionsShard(ctx context.Context, wr *wrangler.Wrangler, subFlags *pflag.FlagSet, args []string) error {
go/vt/vtctl/vtctl.go:           return fmt.Errorf("the <keyspace/shard> argument is required for the ValidatePermissionsShard command")
go/vt/vtctl/vtctl.go:   return wr.ValidatePermissionsShard(ctx, keyspace, shard)
go/vt/vtctl/vtctl.go:func commandValidatePermissionsKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags *pflag.FlagSet, args []string) error {
go/vt/vtctl/vtctl.go:           return fmt.Errorf("the <keyspace name> argument is required for the ValidatePermissionsKeyspace command")
go/vt/vtctl/vtctl.go:   return wr.ValidatePermissionsKeyspace(ctx, keyspace)
go/vt/vtctld/vtctld.go: actionRepo.RegisterKeyspaceAction("ValidatePermissionsKeyspace",
go/vt/vtctld/vtctld.go:                 return "", wr.ValidatePermissionsKeyspace(ctx, keyspace)
go/vt/vtctld/vtctld.go: actionRepo.RegisterShardAction("ValidatePermissionsShard",
go/vt/vtctld/vtctld.go:                 return "", wr.ValidatePermissionsShard(ctx, keyspace, shard)
go/vt/wrangler/permissions.go:// ValidatePermissionsShard validates all the permissions are the same
go/vt/wrangler/permissions.go:func (wr *Wrangler) ValidatePermissionsShard(ctx context.Context, keyspace, shard string) error {
go/vt/wrangler/permissions.go:// ValidatePermissionsKeyspace validates all the permissions are the same
go/vt/wrangler/permissions.go:func (wr *Wrangler) ValidatePermissionsKeyspace(ctx context.Context, keyspace string) error {
go/vt/wrangler/permissions.go:          return wr.ValidatePermissionsShard(ctx, keyspace, shards[0])
go/vt/wrangler/testlib/permissions_test.go:     // run ValidatePermissionsKeyspace, this should work
go/vt/wrangler/testlib/permissions_test.go:     if err := vp.Run([]string{"ValidatePermissionsKeyspace", primary.Tablet.Keyspace}); err != nil {
go/vt/wrangler/testlib/permissions_test.go:             t.Fatalf("ValidatePermissionsKeyspace failed: %v", err)
go/vt/wrangler/testlib/permissions_test.go:     // run ValidatePermissionsKeyspace again, this should now fail
go/vt/wrangler/testlib/permissions_test.go:     if err := vp.Run([]string{"ValidatePermissionsKeyspace", primary.Tablet.Keyspace}); err == nil || !strings.Contains(err.Error(), "has an extra user") {
go/vt/wrangler/testlib/permissions_test.go:             t.Fatalf("ValidatePermissionsKeyspace has unexpected err: %v", err)

So rather than spending time discussing how we could improve it... I think we should kill it off during the client transition as it no longer seems to serve a valid/used purpose as a client command. Unless you for some reason feel this is needed (and should be improved at a later time)?

Copy link
Contributor Author

@mattlord mattlord Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To provide some context, the GetPermissions client command simply returns the contents of the mysql.user and mysql.db tables as a JSON doc (tmc -> mysqlctl):

❯ vtctldclient GetPermissions zone1-100
{
  "user_permissions": [
    {
      "host": "%",
      "user": "vt_repl",
      "password_checksum": "0",
      "privileges": {
        "Alter_priv": "N",
        "Alter_routine_priv": "N",
        "Create_priv": "N",
        "Create_role_priv": "N",
        "Create_routine_priv": "N",
        "Create_tablespace_priv": "N",
        "Create_tmp_table_priv": "N",
        "Create_user_priv": "N",
        "Create_view_priv": "N",
        "Delete_priv": "N",
        "Drop_priv": "N",
        "Drop_role_priv": "N",
        "Event_priv": "N",
        "Execute_priv": "N",
        "File_priv": "N",
        "Grant_priv": "N",
        "Index_priv": "N",
        "Insert_priv": "N",
        "Lock_tables_priv": "N",
        "Password_require_current": "",
        "Password_reuse_history": "",
        "Password_reuse_time": "",
        "Process_priv": "N",
        "References_priv": "N",
        "Reload_priv": "N",
        "Repl_client_priv": "N",
        "Repl_slave_priv": "Y",
        "Select_priv": "N",
        "Show_db_priv": "N",
        "Show_view_priv": "N",
        "Shutdown_priv": "N",
        "Super_priv": "N",
        "Trigger_priv": "N",
        "Update_priv": "N",
        "User_attributes": "",
        "account_locked": "N",
        "authentication_string": "",
        "max_connections": "0",
        "max_questions": "0",
        "max_updates": "0",
        "max_user_connections": "0",
        "password_expired": "N",
        "password_lifetime": "",
        "plugin": "mysql_native_password",
        "ssl_cipher": "",
        "ssl_type": "",
        "x509_issuer": "",
        "x509_subject": ""
      }
    },
...

The ValidatePermissions* commands then tells you if the output differs within a shard or a keyspace. I don't disagree that telling you what nodes differ and how would be useful (not in this PR, but later enhancements)... IF this is actually still useful in the broader sense today. I haven't yet seen anything to indicate that it's still used or still useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In looking for uses of the ValidatePermissons commands (I found none) I did find uses of CopySchemaShard. So I think I will have to port that over.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last note... FWIW the functions used for the ValidatePermissions* commands do include the details in the error message:

func diffPermissions(name, leftName string, left permissionList, rightName string, right permissionList, er concurrency.ErrorRecorder) {

So I'm going to put this comment thread to bed for now. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants