Skip to content

Commit d5ac00c

Browse files
authored
Merge pull request #1086 from dolthub/taylor/metrics
Implement metrics, `describe` system table tests
2 parents da67983 + 1d230f9 commit d5ac00c

File tree

8 files changed

+82
-19
lines changed

8 files changed

+82
-19
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ require (
66
github.com/PuerkitoBio/goquery v1.8.1
77
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
88
github.com/cockroachdb/errors v1.7.5
9-
github.com/dolthub/dolt/go v0.40.5-0.20241218181729-d62130f67059
9+
github.com/dolthub/dolt/go v0.40.5-0.20241227214751-bfb33fe9c9e1
1010
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d
1111
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
1212
github.com/dolthub/go-icu-regex v0.0.0-20241215010122-db690dd53c90
13-
github.com/dolthub/go-mysql-server v0.18.2-0.20241217205639-85adcd5e580f
13+
github.com/dolthub/go-mysql-server v0.19.1-0.20241227200914-69b2934b5468
1414
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
15-
github.com/dolthub/vitess v0.0.0-20241211024425-b00987f7ba54
15+
github.com/dolthub/vitess v0.0.0-20241220202600-b18f18d0cde7
1616
github.com/fatih/color v1.13.0
1717
github.com/goccy/go-json v0.10.2
1818
github.com/gogo/protobuf v1.3.2

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
214214
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
215215
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
216216
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
217-
github.com/dolthub/dolt/go v0.40.5-0.20241218181729-d62130f67059 h1:ughDGwhqfIsfCF8LpGhTXqqVu/Cx2UsbJoMuvzIX8ME=
218-
github.com/dolthub/dolt/go v0.40.5-0.20241218181729-d62130f67059/go.mod h1:AQKcVKL5Dbv14cz1E0rEhhSKiSpQs358Gyiso19RCFk=
217+
github.com/dolthub/dolt/go v0.40.5-0.20241227214751-bfb33fe9c9e1 h1:WOyXDfnn/z3q9yzkx+vuXyeZkVYb5NHRJLrMbdXiDNo=
218+
github.com/dolthub/dolt/go v0.40.5-0.20241227214751-bfb33fe9c9e1/go.mod h1:kJKbaXFI6g8fpv8WJip6wxGfxwXmAcx8fsmF5aItNJI=
219219
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d h1:gO9+wrmNHXukPNCO1tpfCcXIdMlW/qppbUStfLvqz/U=
220220
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY=
221221
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
@@ -224,8 +224,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
224224
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
225225
github.com/dolthub/go-icu-regex v0.0.0-20241215010122-db690dd53c90 h1:Sni8jrP0sy/w9ZYXoff4g/ixe+7bFCZlfCqXKJSU+zM=
226226
github.com/dolthub/go-icu-regex v0.0.0-20241215010122-db690dd53c90/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA=
227-
github.com/dolthub/go-mysql-server v0.18.2-0.20241217205639-85adcd5e580f h1:TTUk8P8Rt4YUrQ9A6yp91v5/kIlvWl30Mt3inK+V1Z4=
228-
github.com/dolthub/go-mysql-server v0.18.2-0.20241217205639-85adcd5e580f/go.mod h1:elfIatfq2fkU5lqTBrTcpL0RcHZOgYPE8EzBD7yQFiY=
227+
github.com/dolthub/go-mysql-server v0.19.1-0.20241227200914-69b2934b5468 h1:b0yy2NKmg6P0sqrvxWw229uVchHjpgAcg6jtsKjSJSQ=
228+
github.com/dolthub/go-mysql-server v0.19.1-0.20241227200914-69b2934b5468/go.mod h1:ToNOAVZAJ6iQBpigxYZo3q8JZDRxpI2/VRrtUoZeehI=
229229
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
230230
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
231231
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
@@ -238,8 +238,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4
238238
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
239239
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
240240
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
241-
github.com/dolthub/vitess v0.0.0-20241211024425-b00987f7ba54 h1:nzBnC0Rt1gFtscJEz4veYd/mazZEdbdmed+tujdaKOo=
242-
github.com/dolthub/vitess v0.0.0-20241211024425-b00987f7ba54/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
241+
github.com/dolthub/vitess v0.0.0-20241220202600-b18f18d0cde7 h1:w130WLeARGGNYWmhGPugsHXzJEelKKimt3kTWg6/Puk=
242+
github.com/dolthub/vitess v0.0.0-20241220202600-b18f18d0cde7/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
243243
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
244244
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
245245
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=

server/connection_handler.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
3131
"github.com/dolthub/dolt/go/libraries/doltcore/sqlserver"
32+
"github.com/dolthub/go-mysql-server/server"
3233
"github.com/dolthub/go-mysql-server/sql"
3334
"github.com/dolthub/vitess/go/mysql"
3435
"github.com/dolthub/vitess/go/vt/sqlparser"
@@ -87,7 +88,7 @@ func init() {
8788
}
8889

8990
// NewConnectionHandler returns a new ConnectionHandler for the connection provided
90-
func NewConnectionHandler(conn net.Conn, handler mysql.Handler) *ConnectionHandler {
91+
func NewConnectionHandler(conn net.Conn, handler mysql.Handler, sel server.ServerEventListener) *ConnectionHandler {
9192
mysqlConn := &mysql.Conn{
9293
Conn: conn,
9394
PrepareData: make(map[uint32]*mysql.PrepareData),
@@ -111,6 +112,9 @@ func NewConnectionHandler(conn net.Conn, handler mysql.Handler) *ConnectionHandl
111112
encodeLoggedQuery: false, // cfg.EncodeLoggedQuery,
112113
pgTypeMap: pgtype.NewMap(),
113114
}
115+
if sel != nil {
116+
doltgresHandler.sel = sel
117+
}
114118

115119
return &ConnectionHandler{
116120
mysqlConn: mysqlConn,

server/doltgres_handler.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type DoltgresHandler struct {
8484
readTimeout time.Duration
8585
encodeLoggedQuery bool
8686
pgTypeMap *pgtype.Map
87+
sel server.ServerEventListener
8788
}
8889

8990
var _ Handler = &DoltgresHandler{}
@@ -120,11 +121,21 @@ func (h *DoltgresHandler) ComExecuteBound(ctx context.Context, conn *mysql.Conn,
120121
return fmt.Errorf("boundQuery must be a sql.Node, but got %T", boundQuery)
121122
}
122123

124+
// TODO: This technically isn't query start and underestimates query execution time
125+
start := time.Now()
126+
if h.sel != nil {
127+
h.sel.QueryStarted()
128+
}
129+
123130
err := h.doQuery(ctx, conn, query, nil, analyzedPlan, h.executeBoundPlan, callback)
124131
if err != nil {
125132
err = sql.CastSQLError(err)
126133
}
127134

135+
if h.sel != nil {
136+
h.sel.QueryCompleted(err == nil, time.Since(start))
137+
}
138+
128139
return err
129140
}
130141

@@ -163,10 +174,21 @@ func (h *DoltgresHandler) ComPrepareParsed(ctx context.Context, c *mysql.Conn, q
163174

164175
// ComQuery implements the Handler interface.
165176
func (h *DoltgresHandler) ComQuery(ctx context.Context, c *mysql.Conn, query string, parsed sqlparser.Statement, callback func(*Result) error) error {
177+
// TODO: This technically isn't query start and underestimates query execution time
178+
start := time.Now()
179+
if h.sel != nil {
180+
h.sel.QueryStarted()
181+
}
182+
166183
err := h.doQuery(ctx, c, query, parsed, nil, h.executeQuery, callback)
167184
if err != nil {
168185
err = sql.CastSQLError(err)
169186
}
187+
188+
if h.sel != nil {
189+
h.sel.QueryCompleted(err == nil, time.Since(start))
190+
}
191+
170192
return err
171193
}
172194

@@ -191,6 +213,12 @@ func (h *DoltgresHandler) ComResetConnection(c *mysql.Conn) error {
191213

192214
// ConnectionClosed implements the Handler interface.
193215
func (h *DoltgresHandler) ConnectionClosed(c *mysql.Conn) {
216+
defer func() {
217+
if h.sel != nil {
218+
h.sel.ClientDisconnected()
219+
}
220+
}()
221+
194222
defer h.sm.RemoveConn(c)
195223
defer h.e.CloseSession(c.ConnectionID)
196224

@@ -201,6 +229,10 @@ func (h *DoltgresHandler) ConnectionClosed(c *mysql.Conn) {
201229

202230
// NewConnection implements the Handler interface.
203231
func (h *DoltgresHandler) NewConnection(c *mysql.Conn) {
232+
if h.sel != nil {
233+
h.sel.ClientConnected()
234+
}
235+
204236
h.sm.AddConn(c)
205237
sql.StatusVariables.IncrementGlobal("Connections", 1)
206238

server/listener.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var (
3535
type Listener struct {
3636
listener net.Listener
3737
cfg mysql.ListenerConfig
38+
sel server.ServerEventListener
3839
}
3940

4041
var _ server.ProtocolListener = (*Listener)(nil)
@@ -48,14 +49,15 @@ func WithCertificate(cert tls.Certificate) ListenerOpt {
4849
}
4950

5051
// NewListener creates a new Listener.
51-
func NewListener(listenerCfg mysql.ListenerConfig) (server.ProtocolListener, error) {
52-
return NewListenerWithOpts(listenerCfg)
52+
func NewListener(listenerCfg mysql.ListenerConfig, sel server.ServerEventListener) (server.ProtocolListener, error) {
53+
return NewListenerWithOpts(listenerCfg, sel)
5354
}
5455

55-
func NewListenerWithOpts(listenerCfg mysql.ListenerConfig, opts ...ListenerOpt) (server.ProtocolListener, error) {
56+
func NewListenerWithOpts(listenerCfg mysql.ListenerConfig, sel server.ServerEventListener, opts ...ListenerOpt) (server.ProtocolListener, error) {
5657
l := &Listener{
5758
listener: listenerCfg.Listener,
5859
cfg: listenerCfg,
60+
sel: sel,
5961
}
6062

6163
for _, opt := range opts {
@@ -83,7 +85,7 @@ func (l *Listener) Accept() {
8385
conn = netutil.NewConnWithTimeouts(conn, l.cfg.ConnReadTimeout, l.cfg.ConnWriteTimeout)
8486
}
8587

86-
connectionHandler := NewConnectionHandler(conn, l.cfg.Handler)
88+
connectionHandler := NewConnectionHandler(conn, l.cfg.Handler, l.sel)
8789
go connectionHandler.HandleConnection()
8890
}
8991
}

testing/go/dolt_tables_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,31 @@ func TestUserSpaceDoltTables(t *testing.T) {
18851885
Query: `SELECT * FROM dolt_status`,
18861886
Expected: []sql.Row{{"public.t", "f", "new table"}},
18871887
},
1888+
{
1889+
Query: `DESCRIBE dolt."status"`,
1890+
Expected: []sql.Row{
1891+
{"table_name", "text", "NO", "PRI", nil, ""},
1892+
{"staged", "boolean", "NO", "PRI", nil, ""},
1893+
{"status", "text", "NO", "PRI", nil, ""},
1894+
},
1895+
},
1896+
{
1897+
Skip: true, // TODO: ERROR: at or near "status": syntax error
1898+
Query: `DESCRIBE dolt.status`,
1899+
Expected: []sql.Row{
1900+
{"table_name", "text", "NO", "PRI", nil, ""},
1901+
{"staged", "boolean", "NO", "PRI", nil, ""},
1902+
{"status", "text", "NO", "PRI", nil, ""},
1903+
},
1904+
},
1905+
{
1906+
Query: `DESCRIBE dolt_status`,
1907+
Expected: []sql.Row{
1908+
{"table_name", "text", "NO", "PRI", nil, ""},
1909+
{"staged", "boolean", "NO", "PRI", nil, ""},
1910+
{"status", "text", "NO", "PRI", nil, ""},
1911+
},
1912+
},
18881913
{
18891914
Query: `SELECT * FROM dolt.status WHERE staged=true`,
18901915
Expected: []sql.Row{},

testing/go/enginetest/doltgres_engine_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,12 +1735,12 @@ func TestStatsHistograms(t *testing.T) {
17351735
denginetest.RunStatsHistogramTests(t, h)
17361736
}
17371737

1738-
// TestStatsIO force a provider reload in-between setup and assertions that
1738+
// TestStatsStorage force a provider reload in-between setup and assertions that
17391739
// forces a round trip of the statistics table before inspecting values.
1740-
func TestStatsIO(t *testing.T) {
1740+
func TestStatsStorage(t *testing.T) {
17411741
t.Skip()
17421742
h := newDoltgresServerHarness(t)
1743-
denginetest.RunStatsIOTests(t, h)
1743+
denginetest.RunStatsStorageTests(t, h)
17441744
}
17451745

17461746
func TestJoinStats(t *testing.T) {

testing/go/ssl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type SSLListener struct {
2323
*dserver.Listener
2424
}
2525

26-
func NewSslListener(listenerCfg mysql.ListenerConfig) (server.ProtocolListener, error) {
26+
func NewSslListener(listenerCfg mysql.ListenerConfig, sel server.ServerEventListener) (server.ProtocolListener, error) {
2727
// Since this is intended for testing, we'll configure a test certificate so that we can test for SSL support
2828
cert, key, err := testcerts.GenerateCerts()
2929
if err != nil {
@@ -35,7 +35,7 @@ func NewSslListener(listenerCfg mysql.ListenerConfig) (server.ProtocolListener,
3535
panic(err)
3636
}
3737

38-
listener, err := dserver.NewListenerWithOpts(listenerCfg, dserver.WithCertificate(certificate))
38+
listener, err := dserver.NewListenerWithOpts(listenerCfg, sel, dserver.WithCertificate(certificate))
3939
if err != nil {
4040
return nil, err
4141
}

0 commit comments

Comments
 (0)