Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

zhexuany
Copy link
Contributor

@zhexuany zhexuany commented Jul 16, 2018

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)

  • New feature (non-breaking change which adds functionality)

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!

@zz-jason
Copy link
Member

why vendor is updated?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version 1.12.0?

Copy link
Contributor Author

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.

@zhexuany
Copy link
Contributor Author

Becuase tracer.go depends on opentracing-go and basicTracer. #7016 is too large hence I split it into small PR which could be easier to review. ;)

@zhexuany zhexuany changed the title adding tracing package util/tracing: adding tracing package Jul 16, 2018
@zhexuany zhexuany force-pushed the adding_tracing_package branch 3 times, most recently from 9a1982f to cd88645 Compare July 16, 2018 12:59
@zhexuany zhexuany mentioned this pull request Jul 16, 2018
3 tasks
"testing"

. "github.com/pingcap/check"

Copy link
Contributor

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?

return sp
}

// ChildSpanFromContxt return a non-nil span. If span can be got from ctx, then returned span is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/return/returns

Copy link
Contributor

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()
Copy link
Contributor

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.

Copy link
Contributor Author

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.

"testing"

. "github.com/pingcap/check"

Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor

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]]
Copy link
Contributor

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.

Copy link
Contributor Author

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.

// 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)
Copy link
Collaborator

@lysu lysu Jul 17, 2018

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it~

@coocood
Copy link
Member

coocood commented Jul 17, 2018

@zhexuany please only update the vendor first.

}

// NewSnowball returns a span which records directly via the specified
// callback. If the given WireSpan is the zero value, a new trace is created;
Copy link
Contributor

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?

// 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 {
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Good suggestion~

Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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 {
Copy link
Contributor

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)
Copy link
Contributor

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"
Copy link
Contributor

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"

Copy link
Contributor Author

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.

@zhexuany
Copy link
Contributor Author

Closing this PR since changes are already small and can be reviewed in original PR.

@zhexuany zhexuany closed this Jul 19, 2018
@zhexuany zhexuany deleted the adding_tracing_package branch July 19, 2018 15:37
@zhexuany zhexuany added this to In Progress in tracing system for tidb Aug 15, 2018
@zz-jason zz-jason moved this from In Progress to Done in tracing system for tidb Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

8 participants