Skip to content

Commit

Permalink
go/vt/vtgate: add mirror query stats to vtgate /debug/querylogz
Browse files Browse the repository at this point in the history
Signed-off-by: Max Englander <[email protected]>
  • Loading branch information
maxenglander committed Feb 4, 2025
1 parent 5d439cd commit 1706774
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit 1706774

Please sign in to comment.