Skip to content

Commit 4ca09f7

Browse files
committed
fix request type headed constant + add cluster init and stop events
1 parent 8f075ee commit 4ca09f7

File tree

6 files changed

+156
-2
lines changed

6 files changed

+156
-2
lines changed

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Config interface {
5454
// That is, some balancing methods allow to be configured.
5555
Balancer() balancer.Balancer
5656

57-
// RequestsType set an additional types hint to all requests.
57+
// RequestsType set an additional type hint to all requests.
5858
// It is needed only for debug purposes and advanced cases.
5959
RequestsType() string
6060

internal/cluster/cluster.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func New(
103103
config config.Config,
104104
balancer balancer.Balancer,
105105
) Cluster {
106+
onDone := trace.DriverOnClusterInit(config.Trace(), &ctx)
107+
defer func() {
108+
onDone()
109+
}()
110+
106111
return &cluster{
107112
config: config,
108113
pool: conn.NewPool(ctx, config),
@@ -118,6 +123,12 @@ func (c *cluster) Close(ctx context.Context) (err error) {
118123
c.mu.Unlock()
119124
return
120125
}
126+
127+
onDone := trace.DriverOnClusterClose(c.config.Trace(), &ctx)
128+
defer func() {
129+
onDone(err)
130+
}()
131+
121132
if c.explorer != nil {
122133
c.explorer.Stop()
123134
}

internal/meta/meta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const (
1616
HeaderDatabase = "x-ydb-database"
1717
HeaderTicket = "x-ydb-auth-ticket"
1818
HeaderVersion = "x-ydb-sdk-build-info"
19-
HeaderRequestType = "x-ydb-request-types"
19+
HeaderRequestType = "x-ydb-request-type"
2020
HeaderTraceID = "x-ydb-trace-id"
2121
HeaderUserAgent = "x-ydb-user-agent"
2222

log/driver.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,31 @@ func Driver(log Logger, details trace.Details) (t trace.Driver) {
332332
if details&trace.DriverClusterEvents != 0 {
333333
// nolint:govet
334334
log := log.WithName(`cluster`)
335+
t.OnClusterInit = func(info trace.ClusterInitStartInfo) func(trace.ClusterInitDoneInfo) {
336+
log.Tracef(`init start`)
337+
start := time.Now()
338+
return func(info trace.ClusterInitDoneInfo) {
339+
log.Debugf(`init done {latency:"%s"}`,
340+
time.Since(start),
341+
)
342+
}
343+
}
344+
t.OnClusterClose = func(info trace.ClusterCloseStartInfo) func(trace.ClusterCloseDoneInfo) {
345+
log.Tracef(`close start`)
346+
start := time.Now()
347+
return func(info trace.ClusterCloseDoneInfo) {
348+
if info.Error == nil {
349+
log.Tracef(`close done {latency:"%s"}`,
350+
time.Since(start),
351+
)
352+
} else {
353+
log.Errorf(`close failed {latency:"%s",error:"%s"}`,
354+
time.Since(start),
355+
info.Error,
356+
)
357+
}
358+
}
359+
}
335360
t.OnClusterGet = func(info trace.ClusterGetStartInfo) func(trace.ClusterGetDoneInfo) {
336361
log.Tracef(`get start`)
337362
start := time.Now()

trace/driver.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type (
3434
OnConnRelease func(ConnReleaseStartInfo) func(ConnReleaseDoneInfo)
3535

3636
// Cluster events
37+
OnClusterInit func(ClusterInitStartInfo) func(ClusterInitDoneInfo)
38+
OnClusterClose func(ClusterCloseStartInfo) func(ClusterCloseDoneInfo)
3739
OnClusterGet func(ClusterGetStartInfo) func(ClusterGetDoneInfo)
3840
OnClusterInsert func(ClusterInsertStartInfo) func(ClusterInsertDoneInfo)
3941
OnClusterUpdate func(ClusterUpdateStartInfo) func(ClusterUpdateDoneInfo)
@@ -228,6 +230,25 @@ type (
228230
State ConnState
229231
Error error
230232
}
233+
ClusterInitStartInfo struct {
234+
// Context make available context in trace callback function.
235+
// Pointer to context provide replacement of context in trace callback function.
236+
// Warning: concurrent access to pointer on client side must be excluded.
237+
// Safe replacement of context are provided only inside callback function
238+
Context *context.Context
239+
}
240+
ClusterInitDoneInfo struct {
241+
}
242+
ClusterCloseStartInfo struct {
243+
// Context make available context in trace callback function.
244+
// Pointer to context provide replacement of context in trace callback function.
245+
// Warning: concurrent access to pointer on client side must be excluded.
246+
// Safe replacement of context are provided only inside callback function
247+
Context *context.Context
248+
}
249+
ClusterCloseDoneInfo struct {
250+
Error error
251+
}
231252
ClusterGetStartInfo struct {
232253
// Context make available context in trace callback function.
233254
// Pointer to context provide replacement of context in trace callback function.

trace/driver_gtrace.go

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

0 commit comments

Comments
 (0)