-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: c-r-dev <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Codecov ReportAttention: Patch coverage is
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. |
Signed-off-by: c-r-dev <[email protected]>
There was a problem hiding this 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>" |
There was a problem hiding this comment.
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)
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() |
There was a problem hiding this comment.
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.
// 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 || ''); |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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) { | ||
|
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
.
Thanks @beingnoble03 for helping to review and share feedback. Will go over and incorporate before making PR ready for review. |
Description
VTAdmin's VTExplain feature currently uses VTExplain directly.
With this PR introduced
A new end point in VTADMIN-API
/api/vexplain
, which leverages VTGate sql connection to runvexplain [ALL|PLAN|QUERIES|TRACE|KEYS] <QUERY>
( https://vitess.io/docs/22.0/user-guides/sql/vexplain/ )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
Deployment Notes