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

Dump error codes as strings instead of integers #25

Merged
merged 5 commits into from
Jun 25, 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,9 +1,10 @@
# Changelog

## v0.1.3 (unreleased)
## v0.2.0 (unreleased)
* Added proxy loop detection so that misconfiguration (e.g. missing/incorrent `--destination` flag) do not cause infinite loops and connection exhaustion.
* `grpc-proxy` now supports requests with gzip compression (however requests are still proxied uncompressed).
* `grpc-dump` now includes a timestamp along with each message sent/received.
* **Breaking Change**: `grpc-dump` now reports RPC error codes as their human-readable string form instead of a raw integer code.

## [v0.1.2](https://github.com/bradleyjkemp/grpc-tools/releases/tag/v0.1.2)
* Fixed bug where the `--destination` flag didn't work (issue [#13](https://github.com/bradleyjkemp/grpc-tools/issues/13)).
Expand Down
2 changes: 1 addition & 1 deletion grpc-dump/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Each message has the format:
}
],
"error" : { // present if the gRPC status is not OK
"code" : 2,
"code" : "Status code string",
"message" : "the gRPC error message"
},
"metadata" : { // the metadata present in the gRPC context
Expand Down
12 changes: 8 additions & 4 deletions grpc-dump/dump_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ func dumpInterceptor(knownMethods map[string]*desc.MethodDescriptor) grpc.Stream
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
dss := &recordedServerStream{ServerStream: ss}
err := handler(srv, dss)
var rpcStatus *status.Status
var rpcStatus *internal.Status
if err != nil {
rpcStatus, _ = status.FromError(err)
grpcStatus, _ := status.FromError(err)
rpcStatus = &internal.Status{
Code: grpcStatus.Code().String(),
Message: grpcStatus.Message(),
}
}

fullMethod := strings.Split(info.FullMethod, "/")
md, _ := metadata.FromIncomingContext(ss.Context())
rpc := internal.RPC{
Metadata: md,
Service: fullMethod[1],
Method: fullMethod[2],
Messages: dss.events,
Status: rpcStatus.Proto(),
Status: rpcStatus,
Metadata: md,
}

knownMethod := knownMethods[info.FullMethod]
Expand Down
8 changes: 6 additions & 2 deletions internal/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal

import (
"fmt"
spb "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc/metadata"
"time"
)
Expand All @@ -11,10 +10,15 @@ type RPC struct {
Service string `json:"service"`
Method string `json:"method"`
Messages []*StreamEvent `json:"messages"`
Status *spb.Status `json:"error,omitempty"`
Status *Status `json:"error,omitempty"`
Metadata metadata.MD `json:"metadata"`
}

type Status struct {
Code string `json:"code"`
Message string `json:"message"`
}

func (r RPC) StreamName() string {
return fmt.Sprintf("/%s/%s", r.Service, r.Method)
}
Expand Down