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

Draft
wants to merge 2 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.

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 0.72464% with 137 lines in your changes missing coverage. Please review.

Project coverage is 67.66%. Comparing base (54dfd60) to head (a2cb477).

Files with missing lines Patch % Lines
go/vt/vtadmin/cluster/cluster.go 0.00% 62 Missing ⚠️
go/vt/vtadmin/api.go 1.63% 60 Missing ⚠️
go/vt/vtadmin/http/vexplain.go 0.00% 8 Missing ⚠️
go/vt/vtadmin/vtsql/vtsql.go 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17508      +/-   ##
==========================================
- Coverage   67.71%   67.66%   -0.06%     
==========================================
  Files        1584     1585       +1     
  Lines      254511   254649     +138     
==========================================
- Hits       172346   172304      -42     
- Misses      82165    82345     +180     

☔ 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!

onChange={onChangeSQL}
rows={10}
value={sql || ''}
placeholder="vexplain [ALL|PLAN|QUERIES|TRACE|KEYS] <query>"
Copy link
Member

Choose a reason for hiding this comment

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

Since, we only have these options: [ALL|PLAN|QUERIES|TRACE|KEYS] . We can create a dropdown instead for this. Also, since the textarea label says SQL, I think it would be better to simply write query here (similar to what we follow in the VTExplain screen)

Comment on lines +2664 to +2686
var (
response *vtadminpb.VExplainResponse
wg sync.WaitGroup
er concurrency.AllErrorRecorder
m sync.Mutex
)

wg.Add(1)

go func(c *cluster.Cluster) {
defer wg.Done()
resp, err := c.GetVExplain(ctx, req, stmt.(*sqlparser.VExplainStmt))

if err != nil {
er.RecordError(err)
return
}
m.Lock()
response = resp
m.Unlock()
}(c)

wg.Wait()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need WaitGroup/ Mutex/ AllErrorRecorder/ goroutine here. Since, we are not running it for multiple clusters.

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?

switch vexplainStmt.Type {
case sqlparser.QueriesVExplainType:
return convertVExplainQueriesResultToString(rows)
case sqlparser.AllVExplainType, sqlparser.TraceVExplainType, sqlparser.PlanVExplainType:
Copy link
Member

Choose a reason for hiding this comment

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

I think this misses sqlparser.KeysVExplainType.

}

func convertVExplainQueriesResultToString(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: Please remove this empty line.

@@ -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.

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VTAdmin to use VTGate's vexplain
2 participants