-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util/tracing: adding tracing package #7063
Conversation
why |
Gopkg.toml
Outdated
@@ -19,6 +19,7 @@ required = ["github.com/golang/protobuf/jsonpb"] | |||
name = "github.com/coreos/etcd" | |||
version = "=3.2.18" | |||
|
|||
# lock grpc version at 1.7.5 because etcd depdens on this version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version 1.12.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. This should be removed.
Becuase |
9a1982f
to
cd88645
Compare
0e734be
to
8747b3c
Compare
util/tracing/tracer_test.go
Outdated
"testing" | ||
|
||
. "github.com/pingcap/check" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add this blank line?
util/tracing/tracer.go
Outdated
return sp | ||
} | ||
|
||
// ChildSpanFromContxt return a non-nil span. If span can be got from ctx, then returned span is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/return/returns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to unify the span
? In line 46 and 34, it's Span
.
return child | ||
} | ||
} | ||
return NoopSpan() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noop span will not be chained ? If so, we can define a constant to avoid allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. Any operation on noop
results in returning itself.
util/tracing/tracer_test.go
Outdated
"testing" | ||
|
||
. "github.com/pingcap/check" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line
TestingT(t) | ||
} | ||
|
||
type testTraceSuite struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just cover the noop span case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Friendly ping
Gopkg.lock
Outdated
@@ -86,6 +86,12 @@ | |||
packages = ["."] | |||
revision = "3955978caca48c1658a4bb7a9c6a0f084e326af3" | |||
|
|||
[[projects]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to make sure other project doesn't use this, or use the same version of this package, or at least compatible to this package version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, you should not review changes made in Gopkg.lock
because such file is generated by dep
.
util/tracing/tracer.go
Outdated
// otherwise, the created Span is a child. | ||
func NewSnowball(opName string, callback func(sp basictracer.RawSpan)) opentracing.Span { | ||
tr := basictracer.New(CallbackRecorder(callback)) | ||
opentracing.SetGlobalTracer(tr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems NewSnowBall()
will be called in TraceExecutor.Open
which will be called per statement.
So If two people do trace command at the same time via two connections, this global variable will be a race condition and be modified in two different goroutines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is by design. Only TracExec
calls NewSnowBall()
. It will be evolving quickly, so I prefer to keeping it like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz explain more about the correctness of this by design~~~?
multi goroutines(os threads underneath) write/read same gobal variable seems be a well-known bug. (ref: https://golang.org/ref/mem#tmp_1).
I still can not understand how can u got right value without any memory corruption in multi trace stmt exec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By design means there will be only one TracExec
running. In general, this feature is executed from MySQL-shell and usually done by ops engineer or client. We just need to collect useful information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it~
@zhexuany please only update the vendor first. |
a832e5a
to
f2a068c
Compare
f2a068c
to
615e243
Compare
util/tracing/tracer.go
Outdated
} | ||
|
||
// NewSnowball returns a span which records directly via the specified | ||
// callback. If the given WireSpan is the zero value, a new trace is created; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see any WireSpan
?
util/tracing/tracer.go
Outdated
// NewSnowball returns a span which records directly via the specified | ||
// callback. If the given WireSpan is the zero value, a new trace is created; | ||
// otherwise, the created Span is a child. | ||
func NewSnowball(opName string, callback func(sp basictracer.RawSpan)) opentracing.Span { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comments for the input parameters.
} | ||
|
||
// NoopSpan returns a span which discards all operations. | ||
func NoopSpan() opentracing.Span { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need to make this an exported function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Good suggestion~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So any change here?
// ChildSpanFromContxt returns a non-nil span. If span can be got from ctx, then returned span is | ||
// a child of such span. Otherwise, returned span is a noop span. | ||
func ChildSpanFromContxt(ctx context.Context, opName string) (sp opentracing.Span) { | ||
if sp := opentracing.SpanFromContext(ctx); sp != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that SpanFromContext
will not return nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will if there is no span in Context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if sp = opentracing.SpanFromContext(ctx); sp == nil {
return NoopSpan()
}
But it will not return nil?
} | ||
|
||
// NoopSpan returns a span which discards all operations. | ||
func NoopSpan() opentracing.Span { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So any change here?
// callback. | ||
func NewSnowball(opName string, callback func(sp basictracer.RawSpan)) opentracing.Span { | ||
tr := basictracer.New(CallbackRecorder(callback)) | ||
opentracing.SetGlobalTracer(tr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will we reset the global tracer? or once NewSnowball
function is called, we'll always have the tracing on?
package tracing | ||
|
||
import ( | ||
"context" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably use this one:
"golang.org/x/net/context"
Or, change all the repo to use
"context"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, "golang.org/x/net/context" is definitely correct choice.
Closing this PR since changes are already small and can be reviewed in original PR. |
What have you changed? (mandatory)
adding a tracing package. #7016 is too large, so I split that PR into several PR in hope of speeding up the review process.
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
unit test
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
Nope
Does this PR affect tidb-ansible update? (mandatory)
Nope
Does this PR need to be added to the release notes? (mandatory)
gogo protobuf version is updated!