Skip to content

Commit

Permalink
fix methodFamily breakage
Browse files Browse the repository at this point in the history
  • Loading branch information
iamqizhao committed Oct 2, 2015
1 parent 5925858 commit b4aa9ea
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion call.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
}
}()
if EnableTracing {
c.traceInfo.tr = trace.New("grpc.Sent."+methodFamily(method), method)
c.traceInfo.tr = trace.New("grpc.Sent."+transport.MethodFamily(method), method)
defer c.traceInfo.tr.Finish()
c.traceInfo.firstLine.client = true
if deadline, ok := ctx.Deadline(); ok {
Expand Down
2 changes: 1 addition & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func NewClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
tracing: EnableTracing,
}
if cs.tracing {
cs.traceInfo.tr = trace.New("grpc.Sent."+methodFamily(method), method)
cs.traceInfo.tr = trace.New("grpc.Sent."+transport.MethodFamily(method), method)
cs.traceInfo.firstLine.client = true
if deadline, ok := ctx.Deadline(); ok {
cs.traceInfo.firstLine.deadline = deadline.Sub(time.Now())
Expand Down
14 changes: 0 additions & 14 deletions trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"fmt"
"io"
"net"
"strings"
"time"

"golang.org/x/net/trace"
Expand All @@ -48,19 +47,6 @@ import (
// This should only be set before any RPCs are sent or received by this program.
var EnableTracing = true

// methodFamily returns the trace family for the given method.
// It turns "/pkg.Service/GetFoo" into "pkg.Service".
func methodFamily(m string) string {
m = strings.TrimPrefix(m, "/") // remove leading slash
if i := strings.Index(m, "/"); i >= 0 {
m = m[:i] // remove everything from second slash
}
if i := strings.LastIndex(m, "."); i >= 0 {
m = m[i+1:] // cut down to last dotted component
}
return m
}

// traceInfo contains tracing information for an RPC.
type traceInfo struct {
tr trace.Trace
Expand Down
2 changes: 1 addition & 1 deletion transport/http2_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import (

"golang.org/x/net/context"
"golang.org/x/net/http2"
"golang.org/x/net/trace"
"golang.org/x/net/http2/hpack"
"golang.org/x/net/trace"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
Expand Down
14 changes: 14 additions & 0 deletions transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"fmt"
"io"
"net"
"strings"
"sync"
"time"

Expand All @@ -53,6 +54,19 @@ import (
"google.golang.org/grpc/metadata"
)

// MethodFamily returns the trace family for the given method.
// It turns "/pkg.Service/GetFoo" into "pkg.Service".
func MethodFamily(m string) string {
m = strings.TrimPrefix(m, "/") // remove leading slash
if i := strings.Index(m, "/"); i >= 0 {
m = m[:i] // remove everything from second slash
}
if i := strings.LastIndex(m, "."); i >= 0 {
m = m[i+1:] // cut down to last dotted component
}
return m
}

// recvMsg represents the received msg from the transport. All transport
// protocol specific info has been removed.
type recvMsg struct {
Expand Down

0 comments on commit b4aa9ea

Please sign in to comment.