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

Fix errors not being proxied to client #45

Merged
merged 2 commits into from
Jul 29, 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## v0.2.1 (unreleased)
## [v0.2.1](https://github.com/bradleyjkemp/grpc-tools/releases/tag/v0.2.1)
* Fixed bug where `grpc-dump` would not forward errors from server to client [#45](https://github.com/bradleyjkemp/grpc-tools/pull/45).
* `grpc-proxy` now will transparently forward all non-HTTP traffic to the original destination [#28](https://github.com/bradleyjkemp/grpc-tools/pull/28).
* When the `--proto_roots` or `--proto_descriptors` flags are used, `grpc-replay` and `grpc-fixture` will marshall messages from the human readable form instead of using the raw message.

Expand Down
4 changes: 3 additions & 1 deletion grpc-dump/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dump
import (
"github.com/bradleyjkemp/grpc-tools/grpc-proxy"
"github.com/bradleyjkemp/grpc-tools/internal/proto_decoder"
"github.com/sirupsen/logrus"
"io"
"strings"
)
Expand All @@ -24,7 +25,8 @@ func Run(output io.Writer, protoRoots, protoDescriptors string, proxyConfig ...g
resolvers = append(resolvers, r)
}

opts := append(proxyConfig, grpc_proxy.WithInterceptor(dumpInterceptor(output, proto_decoder.NewDecoder(resolvers...))))
// TODO: unify this logger with the one provided by grpc_proxy?
opts := append(proxyConfig, grpc_proxy.WithInterceptor(dumpInterceptor(logrus.New(), output, proto_decoder.NewDecoder(resolvers...))))
proxy, err := grpc_proxy.New(
opts...,
)
Expand Down
16 changes: 10 additions & 6 deletions grpc-dump/dump/dump_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/bradleyjkemp/grpc-tools/internal"
"github.com/bradleyjkemp/grpc-tools/internal/proto_decoder"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
Expand All @@ -13,13 +14,13 @@ import (
)

// dump interceptor implements a gRPC.StreamingServerInterceptor that dumps all RPC details
func dumpInterceptor(output io.Writer, decoder proto_decoder.MessageDecoder) grpc.StreamServerInterceptor {
func dumpInterceptor(logger logrus.FieldLogger, output io.Writer, decoder proto_decoder.MessageDecoder) grpc.StreamServerInterceptor {
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
dss := &recordedServerStream{ServerStream: ss}
err := handler(srv, dss)
rpcErr := handler(srv, dss)
var rpcStatus *internal.Status
if err != nil {
grpcStatus, _ := status.FromError(err)
if rpcErr != nil {
grpcStatus, _ := status.FromError(rpcErr)
rpcStatus = &internal.Status{
Code: grpcStatus.Code().String(),
Message: grpcStatus.Message(),
Expand All @@ -36,13 +37,16 @@ func dumpInterceptor(output io.Writer, decoder proto_decoder.MessageDecoder) grp
Metadata: md,
}

var err error
for _, message := range rpc.Messages {
message.Message, err = decoder.Decode(info.FullMethod, message)
// TODO: log warning if error occurs here
if err != nil {
logger.WithError(err).Warn("Failed to decode message")
}
}

dump, _ := json.Marshal(rpc)
fmt.Fprintln(output, string(dump))
return err
return rpcErr
}
}