Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Clean up ocgrpc: remote NewXXXStatsHandler methods.
Browse files Browse the repository at this point in the history
Since we provide options on the ClientHandler and ServerHandler structs
and the NewXXX methods were trivial, it is better to have users use a
struct literal.
  • Loading branch information
Ramon Nogueira committed Mar 9, 2018
1 parent 2ecd8d9 commit 410fb67
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/grpc/helloworld_client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {

// Set up a connection to the server with the OpenCensus
// stats handler to enable stats and tracing.
conn, err := grpc.Dial(address, grpc.WithStatsHandler(ocgrpc.NewClientStatsHandler()), grpc.WithInsecure())
conn, err := grpc.Dial(address, grpc.WithStatsHandler(&ocgrpc.ClientHandler{}), grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/helloworld_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {

// Set up a new server with the OpenCensus
// stats handler to enable stats and tracing.
s := grpc.NewServer(grpc.StatsHandler(ocgrpc.NewServerStatsHandler()))
s := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{}))
pb.RegisterGreeterServer(s, &server{})
// Register reflection service on gRPC server.
reflection.Register(s)
Expand Down
6 changes: 0 additions & 6 deletions plugin/ocgrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ import (
"google.golang.org/grpc/stats"
)

// NewClientStatsHandler enables OpenCensus stats and trace
// for gRPC clients. Deprecated, construct a ClientHandler directly.
func NewClientStatsHandler() stats.Handler {
return &ClientHandler{}
}

// ClientHandler implements a gRPC stats.Handler for recording OpenCensus stats and
// traces. Use with gRPC clients only.
type ClientHandler struct {
Expand Down
14 changes: 6 additions & 8 deletions plugin/ocgrpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ import (
"google.golang.org/grpc/stats"
)

func TestNewClientStatsHandler(t *testing.T) {
func TestClientHandler(t *testing.T) {
ctx := context.Background()

handler := NewClientStatsHandler()

te := &traceExporter{}
trace.RegisterExporter(te)
if err := ClientRequestCountView.Subscribe(); err != nil {
Expand All @@ -42,6 +39,7 @@ func TestNewClientStatsHandler(t *testing.T) {
})
ctx = trace.WithSpan(ctx, span)

var handler ClientHandler
ctx = handler.TagRPC(ctx, &stats.RPCTagInfo{
FullMethodName: "/service.foo/method",
})
Expand Down Expand Up @@ -71,21 +69,21 @@ func TestNewClientStatsHandler(t *testing.T) {
view.Unsubscribe(ClientErrorCountView)
}

func TestNewServerStatsHandler(t *testing.T) {
func TestServerHandler(t *testing.T) {
ctx := context.Background()

handler := NewServerStatsHandler()

te := &traceExporter{}
trace.RegisterExporter(te)
if err := ServerRequestCountView.Subscribe(); err != nil {
t.Fatal(err)
}

// Ensure we start tracing
span := trace.NewSpan("/foo", nil, trace.StartOptions{
Sampler: trace.AlwaysSample(),
})
ctx = trace.WithSpan(ctx, span)

var handler ServerHandler
ctx = handler.TagRPC(ctx, &stats.RPCTagInfo{
FullMethodName: "/service.foo/method",
})
Expand Down
6 changes: 0 additions & 6 deletions plugin/ocgrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ import (
"google.golang.org/grpc/stats"
)

// NewServerStatsHandler enables OpenCensus stats and trace
// for gRPC servers. Deprecated, construct a ServerHandler directly.
func NewServerStatsHandler() stats.Handler {
return &ServerHandler{}
}

// ServerHandler implements gRPC stats.Handler recording OpenCensus stats and
// traces. Use with gRPC servers.
type ServerHandler struct {
Expand Down

0 comments on commit 410fb67

Please sign in to comment.