Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 8a32ac5

Browse files
authored
Comment out import of Vitess to fix error logging (#1339)
It turns out that JUST IMPORTING Vitess messes up logging in the entire application. Vitess code in its `init()` function (called before our `main`) redirects stderr logging into its own logging implementation (which doesn't print anything for us): https://github.com/vitessio/vitess/blob/41a8d1dd323fb56e9dce88b29c64f9dc87b5a0fe/go/vt/logutil/logutil.go#L17-L18 For now, I just commented out the code that imported (and used) Vitess. Before the fix, if the config validation failed, it wouldn't print the cause of the failure. After this fix, the cause is now properly printed out: ``` ________ \_____ \ __ __ ____ ______ _____ _____ / / \ \| | \_/ __ \ / ___// \\__ \ / \_/. \ | /\ ___/ \___ \| Y Y \/ __ \_ \_____\ \_/____/ \___ >____ >__|_| (____ / \__> \/ \/ \/ \/ 2025/03/03 19:18:14 Config validation failed: 2 errors occurred: * no frontend connectors defined * no pipelines defined, must define at least one ```
1 parent 5b7ed7f commit 8a32ac5

File tree

2 files changed

+183
-177
lines changed

2 files changed

+183
-177
lines changed

platform/frontend_connectors/vitess_mysql_connector.go

Lines changed: 159 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -5,160 +5,166 @@
55

66
package frontend_connectors
77

8-
import (
9-
"context"
10-
"errors"
11-
"time"
12-
"vitess.io/vitess/go/mysql"
13-
"vitess.io/vitess/go/mysql/replication"
14-
"vitess.io/vitess/go/sqltypes"
15-
"vitess.io/vitess/go/vt/proto/query"
16-
"vitess.io/vitess/go/vt/vtenv"
17-
18-
"github.com/QuesmaOrg/quesma/platform/logger"
19-
"github.com/QuesmaOrg/quesma/platform/recovery"
20-
quesma_api "github.com/QuesmaOrg/quesma/platform/v2/core"
21-
)
22-
23-
type VitessMySqlConnector struct {
24-
processors []quesma_api.Processor
25-
listener *mysql.Listener
26-
endpoint string
27-
}
28-
29-
func NewVitessMySqlConnector(endpoint string) (*VitessMySqlConnector, error) {
30-
connector := VitessMySqlConnector{
31-
endpoint: endpoint,
32-
}
33-
34-
// FIXME: the parameter values below should be tweaked, in particular (list not exhaustive):
35-
// - timeouts, delays are set to time.Second * 0
36-
// - authServer is set to mysql.NewAuthServerNone(), meaning no authentication
37-
// - TLS is not set up
38-
listener, err := mysql.NewListener("tcp", endpoint, mysql.NewAuthServerNone(), &connector, time.Second*0, time.Second*0, false, false, time.Second*0, time.Second*0)
39-
if err != nil {
40-
return nil, err
41-
}
42-
connector.listener = listener
43-
44-
return &connector, nil
45-
}
46-
47-
func (t *VitessMySqlConnector) Listen() error {
48-
go func() {
49-
defer recovery.LogPanic()
50-
t.listener.Accept()
51-
}()
52-
return nil
53-
}
54-
55-
// Implementation of Vitess mysql.Handler interface:
56-
8+
// FIXME: commented out because JUST IMPORTING
9+
// Vitess messes up logging in the whole application:
10+
// https://github.com/vitessio/vitess/blob/41a8d1dd323fb56e9dce88b29c64f9dc87b5a0fe/go/vt/logutil/logutil.go#L17-L18
11+
12+
// import (
13+
//
14+
// "context"
15+
// "errors"
16+
// "time"
17+
// "vitess.io/vitess/go/mysql"
18+
// "vitess.io/vitess/go/mysql/replication"
19+
// "vitess.io/vitess/go/sqltypes"
20+
// "vitess.io/vitess/go/vt/proto/query"
21+
// "vitess.io/vitess/go/vt/vtenv"
22+
//
23+
// "github.com/QuesmaOrg/quesma/platform/logger"
24+
// "github.com/QuesmaOrg/quesma/platform/recovery"
25+
// quesma_api "github.com/QuesmaOrg/quesma/platform/v2/core"
26+
//
27+
// )
28+
//
29+
// type VitessMySqlConnector struct {
30+
// processors []quesma_api.Processor
31+
// listener *mysql.Listener
32+
// endpoint string
33+
// }
34+
//
35+
// func NewVitessMySqlConnector(endpoint string) (*VitessMySqlConnector, error) {
36+
// connector := VitessMySqlConnector{
37+
// endpoint: endpoint,
38+
// }
39+
//
40+
// // FIXME: the parameter values below should be tweaked, in particular (list not exhaustive):
41+
// // - timeouts, delays are set to time.Second * 0
42+
// // - authServer is set to mysql.NewAuthServerNone(), meaning no authentication
43+
// // - TLS is not set up
44+
// listener, err := mysql.NewListener("tcp", endpoint, mysql.NewAuthServerNone(), &connector, time.Second*0, time.Second*0, false, false, time.Second*0, time.Second*0)
45+
// if err != nil {
46+
// return nil, err
47+
// }
48+
// connector.listener = listener
49+
//
50+
// return &connector, nil
51+
// }
52+
//
53+
// func (t *VitessMySqlConnector) Listen() error {
54+
// go func() {
55+
// defer recovery.LogPanic()
56+
// t.listener.Accept()
57+
// }()
58+
// return nil
59+
// }
60+
//
61+
// // Implementation of Vitess mysql.Handler interface:
5762
type ComQueryMessage struct {
5863
Query string
5964
}
6065

61-
func (t *VitessMySqlConnector) NewConnection(c *mysql.Conn) {
62-
// TODO: should we do something here?
63-
}
64-
65-
func (t *VitessMySqlConnector) ConnectionReady(c *mysql.Conn) {
66-
// TODO: should we do something here?
67-
}
68-
69-
func (t *VitessMySqlConnector) ConnectionClosed(c *mysql.Conn) {
70-
// TODO: should we do something here?
71-
}
72-
73-
func (t *VitessMySqlConnector) ComQuery(c *mysql.Conn, query string, callback func(*sqltypes.Result) error) error {
74-
metadata := make(map[string]interface{})
75-
var message any = ComQueryMessage{
76-
Query: query,
77-
}
78-
79-
dispatcher := quesma_api.Dispatcher{}
80-
_, result := dispatcher.Dispatch(t.processors, metadata, message)
81-
switch result := result.(type) {
82-
case *sqltypes.Result:
83-
err := callback(result)
84-
if err != nil {
85-
return err
86-
}
87-
return nil
88-
case error:
89-
return result
90-
default:
91-
logger.Error().Msgf("Unexpected ComQuery result type received from the processor: %T", result)
92-
return nil
93-
}
94-
}
95-
96-
func (t *VitessMySqlConnector) ComPrepare(c *mysql.Conn, query string, bindVars map[string]*query.BindVariable) ([]*query.Field, error) {
97-
// TODO implement ComPrepare
98-
logger.Error().Msg("ComPrepare not implemented")
99-
return nil, errors.New("ComPrepare not implemented")
100-
}
101-
102-
func (t *VitessMySqlConnector) ComStmtExecute(c *mysql.Conn, prepare *mysql.PrepareData, callback func(*sqltypes.Result) error) error {
103-
// TODO implement ComStmtExecute
104-
logger.Error().Msg("ComStmtExecute not implemented")
105-
return errors.New("ComStmtExecute not implemented")
106-
}
107-
108-
func (t *VitessMySqlConnector) ComRegisterReplica(c *mysql.Conn, replicaHost string, replicaPort uint16, replicaUser string, replicaPassword string) error {
109-
// TODO implement ComRegisterReplica
110-
logger.Error().Msg("ComRegisterReplica not implemented")
111-
return errors.New("ComRegisterReplica not implemented")
112-
}
113-
114-
func (t *VitessMySqlConnector) ComBinlogDump(c *mysql.Conn, logFile string, binlogPos uint32) error {
115-
// TODO implement ComBinlogDump
116-
logger.Error().Msg("ComBinlogDump not implemented")
117-
return errors.New("ComBinlogDump not implemented")
118-
}
119-
120-
func (t *VitessMySqlConnector) ComBinlogDumpGTID(c *mysql.Conn, logFile string, logPos uint64, gtidSet replication.GTIDSet) error {
121-
// TODO implement ComBinlogDumpGTID
122-
logger.Error().Msg("ComBinlogDumpGTID not implemented")
123-
return errors.New("ComBinlogDumpGTID not implemented")
124-
}
125-
126-
func (t *VitessMySqlConnector) WarningCount(c *mysql.Conn) uint16 {
127-
return 0
128-
}
129-
130-
func (t *VitessMySqlConnector) ComResetConnection(c *mysql.Conn) {
131-
// TODO implement ComResetConnection
132-
logger.Error().Msg("ComResetConnection not implemented")
133-
}
134-
135-
func (t *VitessMySqlConnector) Env() *vtenv.Environment {
136-
env, err := vtenv.New(vtenv.Options{
137-
MySQLServerVersion: "", // will use Vitess's default version
138-
TruncateUILen: 512,
139-
TruncateErrLen: 512,
140-
})
141-
if err != nil {
142-
logger.Error().Msgf("failed to create environment: %v", err)
143-
return nil
144-
}
145-
146-
return env
147-
}
148-
149-
func (t *VitessMySqlConnector) InstanceName() string {
150-
return "VitessMySqlConnector"
151-
}
152-
153-
func (t *VitessMySqlConnector) GetEndpoint() string {
154-
return t.endpoint
155-
}
156-
157-
func (t *VitessMySqlConnector) Stop(ctx context.Context) error {
158-
t.listener.Shutdown()
159-
return nil
160-
}
161-
162-
func (t *VitessMySqlConnector) SetHandlers(processors []quesma_api.Processor) {
163-
t.processors = processors
164-
}
66+
//
67+
//func (t *VitessMySqlConnector) NewConnection(c *mysql.Conn) {
68+
// // TODO: should we do something here?
69+
//}
70+
//
71+
//func (t *VitessMySqlConnector) ConnectionReady(c *mysql.Conn) {
72+
// // TODO: should we do something here?
73+
//}
74+
//
75+
//func (t *VitessMySqlConnector) ConnectionClosed(c *mysql.Conn) {
76+
// // TODO: should we do something here?
77+
//}
78+
//
79+
//func (t *VitessMySqlConnector) ComQuery(c *mysql.Conn, query string, callback func(*sqltypes.Result) error) error {
80+
// metadata := make(map[string]interface{})
81+
// var message any = ComQueryMessage{
82+
// Query: query,
83+
// }
84+
//
85+
// dispatcher := quesma_api.Dispatcher{}
86+
// _, result := dispatcher.Dispatch(t.processors, metadata, message)
87+
// switch result := result.(type) {
88+
// case *sqltypes.Result:
89+
// err := callback(result)
90+
// if err != nil {
91+
// return err
92+
// }
93+
// return nil
94+
// case error:
95+
// return result
96+
// default:
97+
// logger.Error().Msgf("Unexpected ComQuery result type received from the processor: %T", result)
98+
// return nil
99+
// }
100+
//}
101+
//
102+
//func (t *VitessMySqlConnector) ComPrepare(c *mysql.Conn, query string, bindVars map[string]*query.BindVariable) ([]*query.Field, error) {
103+
// // TODO implement ComPrepare
104+
// logger.Error().Msg("ComPrepare not implemented")
105+
// return nil, errors.New("ComPrepare not implemented")
106+
//}
107+
//
108+
//func (t *VitessMySqlConnector) ComStmtExecute(c *mysql.Conn, prepare *mysql.PrepareData, callback func(*sqltypes.Result) error) error {
109+
// // TODO implement ComStmtExecute
110+
// logger.Error().Msg("ComStmtExecute not implemented")
111+
// return errors.New("ComStmtExecute not implemented")
112+
//}
113+
//
114+
//func (t *VitessMySqlConnector) ComRegisterReplica(c *mysql.Conn, replicaHost string, replicaPort uint16, replicaUser string, replicaPassword string) error {
115+
// // TODO implement ComRegisterReplica
116+
// logger.Error().Msg("ComRegisterReplica not implemented")
117+
// return errors.New("ComRegisterReplica not implemented")
118+
//}
119+
//
120+
//func (t *VitessMySqlConnector) ComBinlogDump(c *mysql.Conn, logFile string, binlogPos uint32) error {
121+
// // TODO implement ComBinlogDump
122+
// logger.Error().Msg("ComBinlogDump not implemented")
123+
// return errors.New("ComBinlogDump not implemented")
124+
//}
125+
//
126+
//func (t *VitessMySqlConnector) ComBinlogDumpGTID(c *mysql.Conn, logFile string, logPos uint64, gtidSet replication.GTIDSet) error {
127+
// // TODO implement ComBinlogDumpGTID
128+
// logger.Error().Msg("ComBinlogDumpGTID not implemented")
129+
// return errors.New("ComBinlogDumpGTID not implemented")
130+
//}
131+
//
132+
//func (t *VitessMySqlConnector) WarningCount(c *mysql.Conn) uint16 {
133+
// return 0
134+
//}
135+
//
136+
//func (t *VitessMySqlConnector) ComResetConnection(c *mysql.Conn) {
137+
// // TODO implement ComResetConnection
138+
// logger.Error().Msg("ComResetConnection not implemented")
139+
//}
140+
//
141+
//func (t *VitessMySqlConnector) Env() *vtenv.Environment {
142+
// env, err := vtenv.New(vtenv.Options{
143+
// MySQLServerVersion: "", // will use Vitess's default version
144+
// TruncateUILen: 512,
145+
// TruncateErrLen: 512,
146+
// })
147+
// if err != nil {
148+
// logger.Error().Msgf("failed to create environment: %v", err)
149+
// return nil
150+
// }
151+
//
152+
// return env
153+
//}
154+
//
155+
//func (t *VitessMySqlConnector) InstanceName() string {
156+
// return "VitessMySqlConnector"
157+
//}
158+
//
159+
//func (t *VitessMySqlConnector) GetEndpoint() string {
160+
// return t.endpoint
161+
//}
162+
//
163+
//func (t *VitessMySqlConnector) Stop(ctx context.Context) error {
164+
// t.listener.Shutdown()
165+
// return nil
166+
//}
167+
//
168+
//func (t *VitessMySqlConnector) SetHandlers(processors []quesma_api.Processor) {
169+
// t.processors = processors
170+
//}

platform/main.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func main() {
6969
// TODO: Experimental feature, move to the configuration after architecture v2
7070
const mysql_vitess_experiment = false
7171
if mysql_vitess_experiment {
72-
launchMySqlVitess()
72+
// launchMySqlVitess()
7373
return
7474
}
7575

@@ -168,29 +168,29 @@ func main() {
168168

169169
}
170170

171-
func launchMySqlVitess() {
172-
var frontendConn, err = frontend_connectors.NewVitessMySqlConnector(":13306")
173-
if err != nil {
174-
panic(err)
175-
}
176-
var vitessProcessor quesma_api.Processor = processors.NewVitessMySqlProcessor()
177-
frontendConn.SetHandlers([]quesma_api.Processor{vitessProcessor})
178-
var mySqlBackendConn = backend_connectors.NewMySqlBackendConnector("root:my-secret-pw@tcp(localhost:3306)/exampledb3")
179-
var mySqlPipeline quesma_api.PipelineBuilder = quesma_api.NewPipeline()
180-
mySqlPipeline.AddProcessor(vitessProcessor)
181-
mySqlPipeline.AddFrontendConnector(frontendConn)
182-
mySqlPipeline.AddBackendConnector(mySqlBackendConn)
183-
var quesmaBuilder quesma_api.QuesmaBuilder = quesma_api.NewQuesma(quesma_api.EmptyDependencies())
184-
quesmaBuilder.AddPipeline(mySqlPipeline)
185-
qb, err := quesmaBuilder.Build()
186-
if err != nil {
187-
panic(err)
188-
}
189-
qb.Start()
190-
stop := make(chan os.Signal, 1)
191-
<-stop
192-
qb.Stop(context.Background())
193-
}
171+
//func launchMySqlVitess() {
172+
// var frontendConn, err = frontend_connectors.NewVitessMySqlConnector(":13306")
173+
// if err != nil {
174+
// panic(err)
175+
// }
176+
// var vitessProcessor quesma_api.Processor = processors.NewVitessMySqlProcessor()
177+
// frontendConn.SetHandlers([]quesma_api.Processor{vitessProcessor})
178+
// var mySqlBackendConn = backend_connectors.NewMySqlBackendConnector("root:my-secret-pw@tcp(localhost:3306)/exampledb3")
179+
// var mySqlPipeline quesma_api.PipelineBuilder = quesma_api.NewPipeline()
180+
// mySqlPipeline.AddProcessor(vitessProcessor)
181+
// mySqlPipeline.AddFrontendConnector(frontendConn)
182+
// mySqlPipeline.AddBackendConnector(mySqlBackendConn)
183+
// var quesmaBuilder quesma_api.QuesmaBuilder = quesma_api.NewQuesma(quesma_api.EmptyDependencies())
184+
// quesmaBuilder.AddPipeline(mySqlPipeline)
185+
// qb, err := quesmaBuilder.Build()
186+
// if err != nil {
187+
// panic(err)
188+
// }
189+
// qb.Start()
190+
// stop := make(chan os.Signal, 1)
191+
// <-stop
192+
// qb.Stop(context.Background())
193+
//}
194194

195195
func launchMySqlPassthrough() {
196196
var frontendConn = frontend_connectors.NewTCPConnector(":13306")

0 commit comments

Comments
 (0)