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

Bug Fix: Ensure that client can send OpenCensus spans over to the server #4144

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions dgraph/cmd/counter/increment.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.opencensus.io/trace"
)

// Increment is the sub-command invoked when calling "dgraph increment".
Expand Down Expand Up @@ -59,6 +60,7 @@ func init() {
"Read-only. Read the counter value without updating it.")
flag.Bool("be", false,
"Best-effort. Read counter value without retrieving timestamp from Zero.")
flag.String("jaeger.collector", "", "Send opencensus traces to Jaeger.")
// TLS configuration
x.RegisterClientTLSFlags(flag)
}
Expand All @@ -73,8 +75,10 @@ type Counter struct {
mLatency time.Duration
}

func queryCounter(txn *dgo.Txn, pred string) (Counter, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
func queryCounter(ctx context.Context, txn *dgo.Txn, pred string) (Counter, error) {
span := trace.FromContext(ctx)

ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

var counter Counter
Expand All @@ -99,6 +103,7 @@ func queryCounter(txn *dgo.Txn, pred string) (Counter, error) {
} else {
panic(fmt.Sprintf("Invalid response: %q", resp.Json))
}
span.Annotatef(nil, "Found counter: %+v", counter)
counter.startTs = resp.GetTxn().GetStartTs()
counter.qLatency = time.Duration(queryLatency).Round(time.Millisecond)
return counter, nil
Expand All @@ -124,7 +129,10 @@ func process(dg *dgo.Dgraph, conf *viper.Viper) (Counter, error) {
}
}()

counter, err := queryCounter(txn, pred)
ctx, span := trace.StartSpan(context.Background(), "Counter")
defer span.End()

counter, err := queryCounter(ctx, txn, pred)
if err != nil {
return Counter{}, err
}
Expand All @@ -141,7 +149,7 @@ func process(dg *dgo.Dgraph, conf *viper.Viper) (Counter, error) {
mu.SetNquads = []byte(fmt.Sprintf(`<%s> <%s> "%d"^^<xs:int> .`, counter.Uid, pred, counter.Val))

// Don't put any timeout for mutation.
resp, err := txn.Mutate(context.Background(), &mu)
resp, err := txn.Mutate(ctx, &mu)
if err != nil {
return Counter{}, err
}
Expand All @@ -153,6 +161,12 @@ func process(dg *dgo.Dgraph, conf *viper.Viper) (Counter, error) {
}

func run(conf *viper.Viper) {
trace.ApplyConfig(trace.Config{
DefaultSampler: trace.AlwaysSample(),
MaxAnnotationEventsPerSpan: 256,
})
x.RegisterExporters(conf, "dgraph.increment")

startTime := time.Now()
defer func() { fmt.Println("Total:", time.Since(startTime).Round(time.Millisecond)) }()

Expand Down
2 changes: 2 additions & 0 deletions x/x.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/spf13/viper"
"go.opencensus.io/plugin/ocgrpc"
"go.opencensus.io/trace"
"golang.org/x/crypto/ssh/terminal"
"google.golang.org/grpc"
Expand Down Expand Up @@ -529,6 +530,7 @@ func SetupConnection(host string, tlsCfg *tls.Config, useGz bool) (*grpc.ClientC
}

dialOpts := append([]grpc.DialOption{},
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}),
grpc.WithDefaultCallOptions(callOpts...),
grpc.WithBlock())

Expand Down