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 to use VTGate's vexplain #17508

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

Conversation

c-r-dev
Copy link
Contributor

@c-r-dev c-r-dev commented Jan 13, 2025

Description

VTAdmin's VTExplain feature currently uses VTExplain directly.

With this PR introduced

  1. A new end point in VTADMIN-API /api/vexplain , which leverages VTGate sql connection to run vexplain [ALL|PLAN|QUERIES|TRACE|KEYS] <QUERY> ( https://vitess.io/docs/22.0/user-guides/sql/vexplain/ )

  2. A new page in VTADMIN-WEB /vexplain which connect to VTADMIN-API /api/vexplain.

Please note - currently PR has /vexplain and /api/vexplain , will merge/patch these over /vtexplain and /api/vtexplain based on feedback.

While testing the changes on local , i came across below scenario , need inputs from team on #17508 (comment)

thanks to @beingnoble03 , i have tried to move things around and added a drop down for vexplain options with 4099f0e

vexplain_demo

Related Issue(s)

Fixes #16412

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

Deployment Notes

Copy link
Contributor

vitess-bot bot commented Jan 13, 2025

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 Jan 13, 2025
@github-actions github-actions bot added this to the v22.0.0 milestone Jan 13, 2025
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 56.58915% with 56 lines in your changes missing coverage. Please review.

Project coverage is 67.62%. Comparing base (a6c2896) to head (918d02e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtadmin/vtsql/vtsql.go 34.54% 36 Missing ⚠️
go/vt/vtadmin/api.go 70.73% 12 Missing ⚠️
go/vt/vtadmin/http/vexplain.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17508      +/-   ##
==========================================
- Coverage   67.64%   67.62%   -0.02%     
==========================================
  Files        1586     1587       +1     
  Lines      255629   255758     +129     
==========================================
+ Hits       172910   172958      +48     
- Misses      82719    82800      +81     

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

@deepthi deepthi requested a review from beingnoble03 January 13, 2025 15:39
Copy link
Member

@beingnoble03 beingnoble03 left a comment

Choose a reason for hiding this comment

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

Please have a look at the comments, rest looks good to me. Would lean on other reviewers for further review. Thank you!

web/vtadmin/src/components/routes/VExplain.tsx Outdated Show resolved Hide resolved
go/vt/vtadmin/api.go Outdated Show resolved Hide resolved
Comment on lines +640 to +645
// As an easy enhancement for later, we can also validate the request parameters on the front-end
// instead of defaulting to '', to save a round trip.
const req = new URLSearchParams();
req.append('cluster_id', cluster_id || '');
req.append('keyspace', keyspace || '');
req.append('sql', sql || '');
Copy link
Member

Choose a reason for hiding this comment

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

Can we check these parameters in the component itself? Maybe disabling the 'Run VExplain' button if keyspace is not selected or SQL is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks , i have added client side validation to check and alert if sql and keyspace are empty. Please let me know.

Client side validation code

Copy link
Member

Choose a reason for hiding this comment

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

nit: I don't think we need alert here, is it possible to simply disable the button until all the parameters are non-empty?

go/vt/vtadmin/cluster/cluster.go Outdated Show resolved Hide resolved
go/vt/vtadmin/cluster/cluster.go Outdated Show resolved Hide resolved
@@ -2505,6 +2508,82 @@ func (c *Cluster) ToggleTabletReplication(ctx context.Context, tablet *vtadminpb
return err
}

// GetVExplain returns the VExplain json message.
func (c *Cluster) GetVExplain(ctx context.Context, req *vtadminpb.VExplainRequest, vexplainStmt *sqlparser.VExplainStmt) (*vtadminpb.VExplainResponse, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we need this to be here as it doesn't really need any property from c *Cluster, maybe we can directly parse the result in c.DB.VExplain(), then we won't need it to be here. So, this would include moving convertVExplainResultToString and convertVExplainQueriesResultToString to vtsql.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks , incorporated with a79c71f

Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this method from here, and call c.DB.VExplain directly in api.go?

@c-r-dev
Copy link
Contributor Author

c-r-dev commented Jan 14, 2025

Thanks @beingnoble03 for helping to review and share feedback.

Will go over and incorporate before making PR ready for review.

@c-r-dev
Copy link
Contributor Author

c-r-dev commented Jan 20, 2025

@systay , @beingnoble03 , @harshit-gangal , @deepthi , team,

While testing changes locally , came across below scenario :

  • from UI , we are letting choose keyspace (similar to VTExplain)

  • on the /api/vexplain , current code is not validating if table(s) mentioned in sql are present in keyspace passed from UI.
    VTADMIN API Vexplain Code

  • in case user chooses keyspace1 in UI , but fires sql on a table present in keyspace2
    /api/vexplain gets back with result ( as long as keyspace1 and keyspace2 belong to same vitess cluster)

To resolve this , couple of diff ways I can think off :

  1. From UI , on VExplain screen - shall we ask use to just provide cluster name (and not keyspace)

  2. Or in the api /api/vexplain , validate if the table(s) mentioned in sql belong to keyspace which is passed from UI.

@c-r-dev c-r-dev requested a review from beingnoble03 January 24, 2025 17:40
@c-r-dev c-r-dev marked this pull request as ready for review January 24, 2025 17:41
@rohit-nayak-ps rohit-nayak-ps added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VTAdmin VTadmin interface and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work labels Jan 24, 2025
@rohit-nayak-ps rohit-nayak-ps removed NeedsWebsiteDocsUpdate What it says NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jan 24, 2025
Copy link
Member

@beingnoble03 beingnoble03 left a comment

Choose a reason for hiding this comment

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

Rest LGTM. Tested this locally as well, works as expected. Thank you!


// We don't particularly care to test the contents of the VExplain response,
// just that it exists.
print(resp.Response)
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think this print statement can be removed?

Comment on lines +640 to +645
// As an easy enhancement for later, we can also validate the request parameters on the front-end
// instead of defaulting to '', to save a round trip.
const req = new URLSearchParams();
req.append('cluster_id', cluster_id || '');
req.append('keyspace', keyspace || '');
req.append('sql', sql || '');
Copy link
Member

Choose a reason for hiding this comment

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

nit: I don't think we need alert here, is it possible to simply disable the button until all the parameters are non-empty?

Comment on lines +204 to +205
}
func convertVExplainResultToString(rows *sql.Rows) (*vtadminpb.VExplainResponse, error) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we can leave a line between these 2 functions.

@@ -2505,6 +2508,82 @@ func (c *Cluster) ToggleTabletReplication(ctx context.Context, tablet *vtadminpb
return err
}

// GetVExplain returns the VExplain json message.
func (c *Cluster) GetVExplain(ctx context.Context, req *vtadminpb.VExplainRequest, vexplainStmt *sqlparser.VExplainStmt) (*vtadminpb.VExplainResponse, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this method from here, and call c.DB.VExplain directly in api.go?

@beingnoble03 beingnoble03 removed the NeedsIssue A linked issue is missing for this Pull Request label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VTAdmin VTadmin interface Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VTAdmin to use VTGate's vexplain
3 participants