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

go/vt/vtgate: add mirror query stats to vtgate /debug/querylogz #17698

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions go/vt/vtgate/querylogz.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ var (
<th>Duration</th>
<th>Plan Time</th>
<th>Execute Time</th>
<th>Mirror Source Execute Time</th>
<th>Mirror Target Execute Time</th>
<th>Commit Time</th>
<th>Stmt Type</th>
<th>SQL</th>
<th>ShardQueries</th>
<th>RowsAffected</th>
<th>Error</th>
<th>Mirror Target Error</th>
</tr>
</thead>
`)
Expand All @@ -71,12 +74,15 @@ var (
<td>{{.TotalTime.Seconds}}</td>
<td>{{.PlanTime.Seconds}}</td>
<td>{{.ExecuteTime.Seconds}}</td>
<td>{{.MirrorSourceExecuteTime.Seconds}}</td>
<td>{{.MirrorTargetExecuteTime.Seconds}}</td>
<td>{{.CommitTime.Seconds}}</td>
<td>{{.StmtType}}</td>
<td>{{.SQL | .Parser.TruncateForUI | unquote | cssWrappable}}</td>
<td>{{.ShardQueries}}</td>
<td>{{.RowsAffected}}</td>
<td>{{.ErrorStr}}</td>
<td>{{.MirrorTargetErrorStr}}</td>
</tr>
`))
)
Expand Down
14 changes: 13 additions & 1 deletion go/vt/vtgate/querylogz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package vtgate

import (
"context"
"errors"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -43,12 +44,15 @@ func TestQuerylogzHandlerFormatting(t *testing.T) {
logStats.StartTime, _ = time.Parse("Jan 2 15:04:05", "Nov 29 13:33:09")
logStats.PlanTime = 1 * time.Millisecond
logStats.ExecuteTime = 2 * time.Millisecond
logStats.MirrorSourceExecuteTime = 2 * time.Millisecond
logStats.MirrorTargetExecuteTime = 1 * time.Millisecond
logStats.CommitTime = 3 * time.Millisecond
logStats.Ctx = callerid.NewContext(
context.Background(),
callerid.NewEffectiveCallerID("effective-caller", "component", "subcomponent"),
callerid.NewImmediateCallerID("immediate-caller"),
)
logStats.MirrorTargetError = errors.New("mirror target error")

// fast query
fastQueryPattern := []string{
Expand All @@ -63,12 +67,15 @@ func TestQuerylogzHandlerFormatting(t *testing.T) {
`<td>0.001</td>`,
`<td>0.001</td>`,
`<td>0.002</td>`,
`<td>0.002</td>`,
`<td>0.001</td>`,
`<td>0.003</td>`,
`<td>select</td>`,
regexp.QuoteMeta(`<td>select name,​ &#39;inject &lt;script&gt;alert()​;&lt;/script&gt;&#39; from test_table limit 1000</td>`),
`<td>1</td>`,
`<td>1000</td>`,
`<td></td>`,
`<td>mirror target error</td>`,
`</tr>`,
}
logStats.EndTime = logStats.StartTime.Add(1 * time.Millisecond)
Expand All @@ -93,12 +100,15 @@ func TestQuerylogzHandlerFormatting(t *testing.T) {
`<td>0.02</td>`,
`<td>0.001</td>`,
`<td>0.002</td>`,
`<td>0.002</td>`,
`<td>0.001</td>`,
`<td>0.003</td>`,
`<td>select</td>`,
regexp.QuoteMeta(`<td>select name,​ &#39;inject &lt;script&gt;alert()​;&lt;/script&gt;&#39; from test_table limit 1000</td>`),
`<td>1</td>`,
`<td>1000</td>`,
`<td></td>`,
`<td>mirror target error</td>`,
`</tr>`,
}
logStats.EndTime = logStats.StartTime.Add(20 * time.Millisecond)
Expand All @@ -123,12 +133,15 @@ func TestQuerylogzHandlerFormatting(t *testing.T) {
`<td>0.5</td>`,
`<td>0.001</td>`,
`<td>0.002</td>`,
`<td>0.002</td>`,
`<td>0.001</td>`,
`<td>0.003</td>`,
`<td>select</td>`,
regexp.QuoteMeta(`<td>select name,​ &#39;inject &lt;script&gt;alert()​;&lt;/script&gt;&#39; from test_table limit 1000</td>`),
`<td>1</td>`,
`<td>1000</td>`,
`<td></td>`,
`<td>mirror target error</td>`,
`</tr>`,
}
logStats.EndTime = logStats.StartTime.Add(500 * time.Millisecond)
Expand All @@ -147,7 +160,6 @@ func TestQuerylogzHandlerFormatting(t *testing.T) {
close(ch)
body, _ = io.ReadAll(response.Body)
checkQuerylogzHasStats(t, slowQueryPattern, logStats, body)

}

func checkQuerylogzHasStats(t *testing.T, pattern []string, logStats *logstats.LogStats, page []byte) {
Expand Down
Loading