Skip to content

Commit e47388c

Browse files
authored
Merge pull request #743 from ydb-platform/gtrace
Gtrace refactoring
2 parents 16a5bfd + 867221e commit e47388c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+359
-307
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
*.out
1616
vendor
1717
changes.txt
18+
./internal/cmd/gtrace/gtrace

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* Refactored `internal/cmd/gtrace` tool (prefer pointers instead trace struct copies) for bust performance
2+
* Fixed usage of generated traces in code
3+
14
## v3.47.1
25
* Removed test artifacts from repository
36

config/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
type Config struct {
2020
config.Common
2121

22-
trace trace.Driver
22+
trace *trace.Driver
2323
dialTimeout time.Duration
2424
connectionTTL time.Duration
2525
balancerConfig *balancerConfig.Config
@@ -93,7 +93,7 @@ func (c Config) Database() string {
9393
}
9494

9595
// Trace contains driver tracing options.
96-
func (c Config) Trace() trace.Driver {
96+
func (c Config) Trace() *trace.Driver {
9797
return c.trace
9898
}
9999

@@ -151,7 +151,7 @@ func WithTLSConfig(tlsConfig *tls.Config) Option {
151151

152152
func WithTrace(t trace.Driver, opts ...trace.DriverComposeOption) Option {
153153
return func(c *Config) {
154-
c.trace = c.trace.Compose(t, opts...)
154+
c.trace = c.trace.Compose(&t, opts...)
155155
}
156156
}
157157

config/defaults.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
}
3030
)
3131

32-
func defaultGrpcOptions(t trace.Driver, secure bool, tlsConfig *tls.Config) (opts []grpc.DialOption) {
32+
func defaultGrpcOptions(t *trace.Driver, secure bool, tlsConfig *tls.Config) (opts []grpc.DialOption) {
3333
opts = append(opts,
3434
// keep-aliving all connections
3535
grpc.WithKeepaliveParams(
@@ -89,5 +89,6 @@ func defaultConfig() (c Config) {
8989
balancerConfig: balancers.Default(),
9090
tlsConfig: defaultTLSConfig(),
9191
dialTimeout: DefaultDialTimeout,
92+
trace: &trace.Driver{},
9293
}
9394
}

internal/cmd/gtrace/gtrace

1.11 MB
Binary file not shown.

internal/cmd/gtrace/writer.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,10 @@ func (w *Writer) compose(trace *Trace) {
317317
w.line(`// Compose returns a new `, trace.Name, ` which has functional fields composed both from `,
318318
t, ` and `, x, `.`,
319319
)
320-
w.code(`func (`, t, ` `, trace.Name, `) Compose(`, x, ` `, trace.Name, `, opts ...`+trace.Name+`ComposeOption) `)
321-
w.line(`(`, ret, ` `, trace.Name, `) {`)
320+
w.code(`func (`, t, ` *`, trace.Name, `) Compose(`, x, ` *`, trace.Name, `, opts ...`+trace.Name+`ComposeOption) `)
321+
w.line(`*`, trace.Name, ` {`)
322322
w.block(func() {
323+
w.line(`var `, ret, ` `, trace.Name, ``)
323324
if len(trace.Hooks) > 0 {
324325
w.line(`options := `, unexported(trace.Name), `ComposeOptions{}`)
325326
w.line(`for _, opt := range opts {`)
@@ -335,7 +336,7 @@ func (w *Writer) compose(trace *Trace) {
335336
for _, hook := range trace.Hooks {
336337
w.composeHook(hook, t, x, ret+"."+hook.Name)
337338
}
338-
w.line(`return `, ret)
339+
w.line(`return &`, ret)
339340
})
340341
w.line(`}`)
341342
})
@@ -455,7 +456,7 @@ func (w *Writer) hook(trace *Trace, hook Hook) {
455456
t := w.declare("t")
456457
fn := w.declare("fn")
457458

458-
w.code(`func (`, t, ` `, trace.Name, `) `, unexported(hook.Name))
459+
w.code(`func (`, t, ` *`, trace.Name, `) `, unexported(hook.Name))
459460

460461
w.code(`(`)
461462
var args []string
@@ -626,7 +627,7 @@ func (w *Writer) hookShortcut(trace *Trace, hook Hook) {
626627
w.code(`func `, name)
627628
w.code(`(`)
628629
var ctx string
629-
w.code(t, ` `, trace.Name)
630+
w.code(t, ` *`, trace.Name)
630631

631632
var (
632633
params = flattenParams(hook.Func.Params)

internal/conn/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
type Config interface {
1212
DialTimeout() time.Duration
13-
Trace() trace.Driver
13+
Trace() *trace.Driver
1414
ConnectionTTL() time.Duration
1515
GrpcDialOptions() []grpc.DialOption
1616
}

internal/coordination/config/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
type Config struct {
1212
config.Common
1313

14-
trace trace.Coordination
14+
trace *trace.Coordination
1515
}
1616

1717
// Trace returns trace over coordination client calls
18-
func (c Config) Trace() trace.Coordination {
18+
func (c Config) Trace() *trace.Coordination {
1919
return c.trace
2020
}
2121

@@ -24,7 +24,7 @@ type Option func(c *Config)
2424
// WithTrace appends coordination trace to early defined traces
2525
func WithTrace(trace trace.Coordination, opts ...trace.CoordinationComposeOption) Option {
2626
return func(c *Config) {
27-
c.trace = c.trace.Compose(trace, opts...)
27+
c.trace = c.trace.Compose(&trace, opts...)
2828
}
2929
}
3030

@@ -36,7 +36,9 @@ func With(config config.Common) Option {
3636
}
3737

3838
func New(opts ...Option) Config {
39-
c := Config{}
39+
c := Config{
40+
trace: &trace.Coordination{},
41+
}
4042
for _, o := range opts {
4143
if o != nil {
4244
o(&c)

internal/discovery/config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ type Config struct {
2121
meta meta.Meta
2222

2323
interval time.Duration
24-
trace trace.Discovery
24+
trace *trace.Discovery
2525
}
2626

2727
func New(opts ...Option) Config {
2828
c := Config{
2929
interval: DefaultInterval,
30+
trace: &trace.Discovery{},
3031
}
3132
for _, o := range opts {
3233
if o != nil {
@@ -56,7 +57,7 @@ func (c Config) Secure() bool {
5657
return c.secure
5758
}
5859

59-
func (c Config) Trace() trace.Discovery {
60+
func (c Config) Trace() *trace.Discovery {
6061
return c.trace
6162
}
6263

@@ -102,7 +103,7 @@ func WithMeta(meta meta.Meta) Option {
102103
// WithTrace configures discovery client calls tracing
103104
func WithTrace(trace trace.Discovery, opts ...trace.DiscoveryComposeOption) Option {
104105
return func(c *Config) {
105-
c.trace = c.trace.Compose(trace, opts...)
106+
c.trace = c.trace.Compose(&trace, opts...)
106107
}
107108
}
108109

internal/meta/meta.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
func New(
1515
database string,
1616
credentials credentials.Credentials,
17-
trace trace.Driver,
17+
trace *trace.Driver,
1818
opts ...Option,
1919
) Meta {
2020
m := Meta{
@@ -64,7 +64,7 @@ func ForbidOption(feature string) Option {
6464
}
6565

6666
type Meta struct {
67-
trace trace.Driver
67+
trace *trace.Driver
6868
credentials credentials.Credentials
6969
database string
7070
requestsType string

0 commit comments

Comments
 (0)