Skip to content

Commit 9f15b84

Browse files
authored
Merge pull request #755 from ydb-platform/connected
improve connected event
2 parents 85f7487 + 4e6e27e commit 9f15b84

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* Improved code with `go-critic` linter
2+
* Added session info into `database/sql` event `connected`
23

34
## v3.47.3
45
* Added `table/options.Description.Tiering` field

internal/xsql/connector.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,22 @@ func (c *Connector) detach(cc *conn) {
286286
}
287287

288288
func (c *Connector) Connect(ctx context.Context) (_ driver.Conn, err error) {
289-
onDone := trace.DatabaseSQLOnConnectorConnect(c.trace, &ctx)
289+
var (
290+
onDone = trace.DatabaseSQLOnConnectorConnect(c.trace, &ctx)
291+
session table.ClosableSession
292+
)
290293
defer func() {
291-
onDone(err)
294+
onDone(err, session)
292295
}()
293296
if !c.disableServerBalancer {
294297
ctx = meta.WithAllowFeatures(ctx, metaHeaders.HintSessionBalancer)
295298
}
296-
s, err := c.parent.Table().CreateSession(ctx) //nolint
299+
session, err = c.parent.Table().CreateSession(ctx) //nolint
297300
if err != nil {
298301
return nil, xerrors.WithStackTrace(err)
299302
}
300303

301-
return newConn(c, s, withDefaultTxControl(c.defaultTxControl),
304+
return newConn(c, session, withDefaultTxControl(c.defaultTxControl),
302305
withDefaultQueryMode(c.defaultQueryMode),
303306
withDataOpts(c.defaultDataQueryOpts...),
304307
withScanOpts(c.defaultScanQueryOpts...),

log/sql.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ func internalDatabaseSQL(l *wrapper, d trace.Detailer) (t trace.DatabaseSQL) {
2727
start := time.Now()
2828
return func(info trace.DatabaseSQLConnectorConnectDoneInfo) {
2929
if info.Error == nil {
30-
l.Log(WithLevel(ctx, INFO), "connected",
30+
l.Log(WithLevel(ctx, DEBUG), "connected",
3131
latency(start),
32+
String("session_id", info.Session.ID()),
33+
String("session_status", info.Session.Status()),
3234
)
3335
} else {
3436
l.Log(WithLevel(ctx, ERROR), "failed",

table/table.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package table
33
import (
44
"context"
55
"sort"
6+
"time"
67

78
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
89
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table"
@@ -81,6 +82,7 @@ const (
8182
type SessionInfo interface {
8283
ID() string
8384
Status() SessionStatus
85+
LastUsage() time.Time
8486
}
8587

8688
type Session interface {

trace/sql.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ type (
4040
Context *context.Context
4141
}
4242
DatabaseSQLConnectorConnectDoneInfo struct {
43-
Error error
43+
Error error
44+
Session tableSessionInfo
4445
}
4546
DatabaseSQLConnPingStartInfo struct {
4647
// Context make available context in trace callback function.

trace/sql_gtrace.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)