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

dump the full vtgate view of vschema #20

Merged
merged 1 commit into from
Aug 12, 2024
Merged
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
16 changes: 4 additions & 12 deletions src/vitess-tester/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ limitations under the License.
package vitess_tester

import (
"encoding/json"
"fmt"
"net/url"
"os"
"path"
"strings"
"time"

"vitess.io/vitess/go/vt/vtgate/vindexes"
)

type Suite interface {
Expand All @@ -37,7 +34,7 @@ type Suite interface {
type Reporter interface {
AddTestCase(query string, lineNo int)
EndTestCase()
AddFailure(vschema vindexes.VSchema, err error)
AddFailure(vschema []byte, err error)
AddInfo(info string)
Report() string
Failed() bool
Expand Down Expand Up @@ -118,7 +115,7 @@ func (e *FileReporter) EndTestCase() {
}
}

func (e *FileReporter) AddFailure(vschema vindexes.VSchema, err error) {
func (e *FileReporter) AddFailure(vschema []byte, err error) {
e.failureCount++
e.currentQueryFailed = true
if e.currentQuery == "" {
Expand Down Expand Up @@ -165,19 +162,14 @@ func (e *FileReporter) createErrorFileFor() *os.File {
return file
}

func (e *FileReporter) createVSchemaDump(vschema vindexes.VSchema) {
func (e *FileReporter) createVSchemaDump(vschema []byte) {
errorDir := e.errorDir()
err := os.MkdirAll(errorDir, PERM)
if err != nil {
panic("failed to create vschema directory\n" + err.Error())
}

vschemaBytes, err := json.MarshalIndent(vschema, "", "\t")
if err != nil {
panic("failed to marshal vschema\n" + err.Error())
}

err = os.WriteFile(path.Join(errorDir, "vschema.json"), vschemaBytes, PERM)
err = os.WriteFile(path.Join(errorDir, "vschema.json"), vschema, PERM)
if err != nil {
panic("failed to write vschema\n" + err.Error())
}
Expand Down
42 changes: 30 additions & 12 deletions src/vitess-tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/pingcap/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -113,14 +114,31 @@ func (t *Tester) addSuccess() {

}

func (t *Tester) getVschema() []byte {
httpClient := &http.Client{Timeout: 5 * time.Second}
resp, err := httpClient.Get(t.clusterInstance.VtgateProcess.VSchemaURL)
if err != nil {
log.Errorf(err.Error())
return nil
}
defer resp.Body.Close()
res, err := io.ReadAll(resp.Body)
if err != nil {
log.Errorf(err.Error())
return nil
}

return res
}

func (t *Tester) Run() error {
t.preProcess()
if t.autoVSchema() {
defer t.postProcess()
}
queries, err := t.loadQueries()
if err != nil {
t.reporter.AddFailure(t.vschema, err)
t.reporter.AddFailure(t.getVschema(), err)
return err
}

Expand All @@ -142,26 +160,26 @@ func (t *Tester) Run() error {
case Q_SKIP:
t.skipNext = true
case Q_BEGIN_CONCURRENT, Q_END_CONCURRENT, Q_CONNECT, Q_CONNECTION, Q_DISCONNECT, Q_LET, Q_REPLACE_COLUMN:
t.reporter.AddFailure(t.vschema, fmt.Errorf("%s not supported", String(q.tp)))
t.reporter.AddFailure(t.getVschema(), fmt.Errorf("%s not supported", String(q.tp)))
case Q_SKIP_IF_BELOW_VERSION:
strs := strings.Split(q.Query, " ")
if len(strs) != 3 {
t.reporter.AddFailure(t.vschema, fmt.Errorf("incorrect syntax for Q_SKIP_IF_BELOW_VERSION in: %v", q.Query))
t.reporter.AddFailure(t.getVschema(), fmt.Errorf("incorrect syntax for Q_SKIP_IF_BELOW_VERSION in: %v", q.Query))
continue
}
t.skipBinary = strs[1]
var err error
t.skipVersion, err = strconv.Atoi(strs[2])
if err != nil {
t.reporter.AddFailure(t.vschema, err)
t.reporter.AddFailure(t.getVschema(), err)
continue
}
case Q_ERROR:
t.expectedErrs = true
case Q_VEXPLAIN:
strs := strings.Split(q.Query, " ")
if len(strs) != 2 {
t.reporter.AddFailure(t.vschema, fmt.Errorf("incorrect syntax for Q_VEXPLAIN in: %v", q.Query))
t.reporter.AddFailure(t.getVschema(), fmt.Errorf("incorrect syntax for Q_VEXPLAIN in: %v", q.Query))
continue
}

Expand All @@ -185,14 +203,14 @@ func (t *Tester) Run() error {
result, err := t.curr.VtConn.ExecuteFetch("vexplain "+t.vexplain+" "+q.Query, -1, false)
t.vexplain = ""
if err != nil {
t.reporter.AddFailure(t.vschema, err)
t.reporter.AddFailure(t.getVschema(), err)
continue
}

t.reporter.AddInfo(fmt.Sprintf("VExplain Output:\n %s\n", result.Rows[0][0].ToString()))
}
if err = t.execute(q); err != nil && !t.expectedErrs {
t.reporter.AddFailure(t.vschema, err)
t.reporter.AddFailure(t.getVschema(), err)
}
t.reporter.EndTestCase()
// clear expected errors and current query after we execute any query
Expand All @@ -203,7 +221,7 @@ func (t *Tester) Run() error {
return errors.Annotate(err, "failed to remove file")
}
default:
t.reporter.AddFailure(t.vschema, fmt.Errorf("%s not supported", String(q.tp)))
t.reporter.AddFailure(t.getVschema(), fmt.Errorf("%s not supported", String(q.tp)))
}
}
fmt.Printf("%s\n", t.reporter.Report())
Expand Down Expand Up @@ -237,21 +255,21 @@ func (t *Tester) waitAuthoritative(query string) {
var err error
ksName, err = t.findTable(tblName)
if err != nil {
t.reporter.AddFailure(t.vschema, err)
t.reporter.AddFailure(t.getVschema(), err)
return
}
case 3:
tblName = strs[1]
ksName = strs[2]

default:
t.reporter.AddFailure(t.vschema, fmt.Errorf("expected table name and keyspace for wait_authoritative in: %v", query))
t.reporter.AddFailure(t.getVschema(), fmt.Errorf("expected table name and keyspace for wait_authoritative in: %v", query))
}

log.Infof("Waiting for authoritative schema for table %s", tblName)
err := utils.WaitForAuthoritative(t, ksName, tblName, t.clusterInstance.VtgateProcess.ReadVSchema)
if err != nil {
t.reporter.AddFailure(t.vschema, fmt.Errorf("failed to wait for authoritative schema for table %s: %v", tblName, err))
t.reporter.AddFailure(t.getVschema(), fmt.Errorf("failed to wait for authoritative schema for table %s: %v", tblName, err))
}
}

Expand Down Expand Up @@ -439,7 +457,7 @@ func (t *Tester) handleCreateTable(create *sqlparser.CreateTable) {
}

func (t *Tester) Errorf(format string, args ...interface{}) {
t.reporter.AddFailure(t.vschema, errors.Errorf(format, args...))
t.reporter.AddFailure(t.getVschema(), errors.Errorf(format, args...))
}

func (t *Tester) FailNow() {
Expand Down
3 changes: 1 addition & 2 deletions src/vitess-tester/xunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"time"

"github.com/jstemmer/go-junit-report/v2/junit"
"vitess.io/vitess/go/vt/vtgate/vindexes"
)

type XMLTestSuite struct {
Expand Down Expand Up @@ -78,7 +77,7 @@ func (xml *XMLTestSuite) EndTestCase() {
xml.currTestCase = nil
}

func (xml *XMLTestSuite) AddFailure(vschema vindexes.VSchema, err error) {
func (xml *XMLTestSuite) AddFailure(vschema []byte, err error) {
if xml.currTestCase == nil {
xml.AddTestCase("SETUP", 0)
xml.AddFailure(vschema, err)
Expand Down
Loading