Skip to content

Commit

Permalink
return early with noroute.Inc when target is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
andyroyle committed Nov 30, 2018
1 parent bf09fda commit 0b951c2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions proxy/grpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ func (g GrpcProxyInterceptor) Stream(srv interface{}, stream grpc.ServerStream,
target, err := g.lookup(ctx, info.FullMethod)

if err != nil {
log.Println("[WARN] grpc: error looking up route ", err)
return status.Errorf(codes.Internal, "internal error")
log.Println("[ERROR] grpc: error looking up route", err)
return status.Error(codes.Internal, "internal error")
}

if target == nil {
g.StatsHandler.NoRoute.Inc(1)
log.Println("[WARN] grpc: no route found for", info.FullMethod)
return status.Error(codes.NotFound, "no route found")
}

ctx = context.WithValue(ctx, targetKey{}, target)
Expand All @@ -111,11 +117,7 @@ func (g GrpcProxyInterceptor) Stream(srv interface{}, stream grpc.ServerStream,
end := time.Now()
dur := end.Sub(start)

if target != nil {
target.Timer.Update(dur)
} else {
g.StatsHandler.NoRoute.Inc(1)
}
target.Timer.Update(dur)

return err
}
Expand Down

0 comments on commit 0b951c2

Please sign in to comment.