Skip to content

Commit 6fdae01

Browse files
committed
Added debug mark for attach sessions
1 parent 2fe7275 commit 6fdae01

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

internal/query/session_core.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package query
22

33
import (
44
"context"
5+
"os"
6+
"runtime/pprof"
7+
"strconv"
58
"sync/atomic"
69
"time"
710

@@ -22,6 +25,9 @@ import (
2225
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
2326
)
2427

28+
// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals
29+
var setGoroutineLabelForAttachStream = os.Getenv("YDB_QUERY_SESSION_ATTACH_STREAM_GOROUTINE_LABEL") == "1"
30+
2531
type (
2632
Core interface {
2733
query.SessionInfo
@@ -110,6 +116,7 @@ func WithTrace(t *trace.Query) Option {
110116
}
111117
}
112118

119+
//nolint:funlen
113120
func Open(
114121
ctx context.Context, client Ydb_Query_V1.QueryServiceClient, opts ...Option,
115122
) (_ *sessionCore, finalErr error) {
@@ -152,7 +159,20 @@ func Open(
152159
core.id = response.GetSessionId()
153160
core.nodeID = uint32(response.GetNodeId())
154161

155-
err = core.attach(ctx)
162+
if setGoroutineLabelForAttachStream {
163+
attachRes := make(chan error)
164+
pprof.Do(ctx, pprof.Labels(
165+
"node_id", strconv.Itoa(int(core.NodeID())),
166+
"session_id", core.id,
167+
), func(ctx context.Context) {
168+
go func() {
169+
attachRes <- core.attach(ctx)
170+
}()
171+
})
172+
err = <-attachRes
173+
} else {
174+
err = core.attach(ctx)
175+
}
156176
if err != nil {
157177
_ = core.deleteSession(ctx)
158178

0 commit comments

Comments
 (0)