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

Add wire tracer capabilities to reference client #768

Merged
merged 46 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a91e67f
Tracer
smaye81 Jan 25, 2024
7f26eeb
Tracer
smaye81 Jan 26, 2024
fd0b009
Tracer
smaye81 Jan 26, 2024
76d823e
Revert
smaye81 Jan 26, 2024
3198a13
Revert
smaye81 Jan 26, 2024
2f87a7f
Revert
smaye81 Jan 26, 2024
fbb79ff
LOgging
smaye81 Jan 26, 2024
b2ba9b3
Impl
smaye81 Jan 26, 2024
8049ab9
Update
smaye81 Jan 27, 2024
8106bf7
Update
smaye81 Jan 27, 2024
ead36d4
Raw json
smaye81 Jan 30, 2024
543f288
Merge branch 'main' into sayers/http_tracer
smaye81 Jan 30, 2024
985292e
Content
smaye81 Jan 30, 2024
c2448f1
Tracing
smaye81 Jan 30, 2024
5ba1f02
Revert go.mod
smaye81 Jan 30, 2024
aa57ce8
Revert
smaye81 Jan 30, 2024
21b7974
Lint
smaye81 Jan 30, 2024
c8db7a5
Docs
smaye81 Jan 30, 2024
e4d2c2f
Revert
smaye81 Jan 30, 2024
92d60c8
Merge branch 'main' into sayers/http_tracer
smaye81 Jan 31, 2024
a132b49
Fixes
smaye81 Feb 1, 2024
411aa13
Docs
smaye81 Feb 1, 2024
8c46e10
Race condition
smaye81 Feb 1, 2024
b47a710
Revert
smaye81 Feb 1, 2024
57d8635
Tracer
smaye81 Feb 1, 2024
d53c5e4
Tests
smaye81 Feb 2, 2024
25337a7
Tracer
smaye81 Feb 2, 2024
a83c12e
Tracer
smaye81 Feb 2, 2024
76a7496
Tests
smaye81 Feb 2, 2024
03bd905
Docs
smaye81 Feb 2, 2024
c8ba9c4
Revert
smaye81 Feb 2, 2024
b3baf63
Tests
smaye81 Feb 2, 2024
4263999
Remove debug
smaye81 Feb 2, 2024
af03a89
Merge branch 'main' into sayers/http_tracer
smaye81 Feb 2, 2024
ff03486
Simplify
smaye81 Feb 3, 2024
0906002
Feedback
smaye81 Feb 6, 2024
aa0a862
Impl
smaye81 Feb 6, 2024
67fe5d2
Wire Details
smaye81 Feb 6, 2024
0122e39
Lint
smaye81 Feb 6, 2024
f8cd911
Add TODO
smaye81 Feb 6, 2024
2537552
Feedback
smaye81 Feb 7, 2024
b4bba18
Temp disable breaking step
smaye81 Feb 7, 2024
a2e3f6d
Slim down the breaking comments
smaye81 Feb 7, 2024
e38b33c
Merge branch 'main' into sayers/http_tracer
smaye81 Feb 7, 2024
50df580
Relaxes assertions on query parameters (#771)
jhump Feb 7, 2024
ba04755
Merge
smaye81 Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions internal/app/connectconformance/testsuites/errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,31 @@ testCases:
responseTrailers:
- name: x-custom-trailer
value: ["bing"]
# Client Stream Tests -----------------------------------------------------------
smaye81 marked this conversation as resolved.
Show resolved Hide resolved
- request:
testName: client stream error one request
service: connectrpc.conformance.v1.ConformanceService
method: ClientStream
streamType: STREAM_TYPE_CLIENT_STREAM
requestMessages:
- "@type": type.googleapis.com/connectrpc.conformance.v1.ClientStreamRequest
responseDefinition:
error:
code: 13
message: "client stream failed"
- request:
testName: client stream error multiple requests
service: connectrpc.conformance.v1.ConformanceService
method: ClientStream
streamType: STREAM_TYPE_CLIENT_STREAM
requestMessages:
- "@type": type.googleapis.com/connectrpc.conformance.v1.ClientStreamRequest
responseDefinition:
error:
code: 13
message: "client stream failed"
- "@type": type.googleapis.com/connectrpc.conformance.v1.ClientStreamRequest
requestData: "dGVzdCByZXNwb25zZQ=="
# Bidi Stream Tests -----------------------------------------------------------
- request:
testName: bidi full duplex stream error with responses
Expand Down
8 changes: 5 additions & 3 deletions internal/app/referenceclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ func invoke(ctx context.Context, req *v1.ClientCompatRequest, trace *tracer.Trac
case v1.HTTPVersion_HTTP_VERSION_UNSPECIFIED:
return nil, errors.New("an HTTP version must be specified")
}
if trace != nil {
transport = tracer.TracingRoundTripper(transport, trace)
}

// Create a new TracingRoundTripper with our WireTracer so that the tests can trace values on the
// wire. Note that 'trace' could be nil, in which case, any error traces will
// simply not be printed.
transport = tracer.TracingRoundTripper(transport, NewWireTracer(trace))
smaye81 marked this conversation as resolved.
Show resolved Hide resolved

if req.RawRequest != nil {
transport = &rawRequestSender{transport: transport, rawRequest: req.RawRequest}
Expand Down
129 changes: 108 additions & 21 deletions internal/app/referenceclient/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
v1 "connectrpc.com/conformance/internal/gen/proto/go/connectrpc/conformance/v1"
"connectrpc.com/conformance/internal/gen/proto/go/connectrpc/conformance/v1/conformancev1connect"
"connectrpc.com/connect"
"google.golang.org/protobuf/types/known/structpb"
)

const clientName = "connectconformance-referenceclient"
Expand Down Expand Up @@ -117,8 +118,21 @@ func (i *invoker) unary(
var trailers []*v1.Header
payloads := make([]*v1.ConformancePayload, 0, 1)

ctx, wire := WithWireCapture(ctx)
smaye81 marked this conversation as resolved.
Show resolved Hide resolved

// Invoke the Unary call
resp, err := i.client.Unary(ctx, request)

var actualStatusCode int32
var connectErrorRaw *structpb.Struct
var actualTrailers []*v1.Header
wireDetails := wire.Get()
if wireDetails != nil {
actualStatusCode = wireDetails.StatusCode
actualTrailers = wireDetails.Trailers
connectErrorRaw = wireDetails.ConnectErrorRaw
}

if err != nil {
// If an error was returned, first convert it to a Connect error
// so that we can get the headers from the Meta property. Then,
Expand All @@ -137,11 +151,13 @@ func (i *invoker) unary(
}

return &v1.ClientResponseResult{
ResponseHeaders: headers,
ResponseTrailers: trailers,
Payloads: payloads,
Error: protoErr,
ConnectErrorRaw: nil, // TODO
ResponseHeaders: headers,
ResponseTrailers: trailers,
Payloads: payloads,
Error: protoErr,
ActualStatusCode: actualStatusCode,
ActualHttpTrailers: actualTrailers,
ConnectErrorRaw: connectErrorRaw,
}, nil
}

Expand All @@ -168,8 +184,21 @@ func (i *invoker) idempotentUnary(
var trailers []*v1.Header
payloads := make([]*v1.ConformancePayload, 0, 1)

ctx, wire := WithWireCapture(ctx)

// Invoke the Unary call
resp, err := i.client.IdempotentUnary(ctx, request)

var actualStatusCode int32
var connectErrorRaw *structpb.Struct
var actualTrailers []*v1.Header
wireDetails := wire.Get()
if wireDetails != nil {
actualStatusCode = wireDetails.StatusCode
actualTrailers = wireDetails.Trailers
connectErrorRaw = wireDetails.ConnectErrorRaw
}

if err != nil {
// If an error was returned, first convert it to a Connect error
// so that we can get the headers from the Meta property. Then,
Expand All @@ -186,11 +215,13 @@ func (i *invoker) idempotentUnary(
}

return &v1.ClientResponseResult{
ResponseHeaders: headers,
ResponseTrailers: trailers,
Payloads: payloads,
Error: protoErr,
ConnectErrorRaw: nil, // TODO
ResponseHeaders: headers,
ResponseTrailers: trailers,
Payloads: payloads,
Error: protoErr,
ActualStatusCode: actualStatusCode,
ActualHttpTrailers: actualTrailers,
ConnectErrorRaw: connectErrorRaw,
}, nil
}

Expand All @@ -212,6 +243,8 @@ func (i *invoker) serverStream(
// Add the specified request headers to the request
internal.AddHeaders(req.RequestHeaders, request.Header())

ctx, wire := WithWireCapture(ctx)

stream, err := i.client.ServerStream(ctx, request)
if err != nil {
// If an error was returned, first convert it to a Connect error
Expand Down Expand Up @@ -272,12 +305,24 @@ func (i *invoker) serverStream(
protoErr = internal.ConvertErrorToProtoError(err)
}
}
var actualStatusCode int32
var connectErrorRaw *structpb.Struct
var actualTrailers []*v1.Header
wireDetails := wire.Get()
if wireDetails != nil {
actualStatusCode = wireDetails.StatusCode
actualTrailers = wireDetails.Trailers
connectErrorRaw = wireDetails.ConnectErrorRaw
}

return &v1.ClientResponseResult{
ResponseHeaders: headers,
ResponseTrailers: trailers,
Payloads: payloads,
Error: protoErr,
ConnectErrorRaw: nil, // TODO
ResponseHeaders: headers,
ResponseTrailers: trailers,
Payloads: payloads,
Error: protoErr,
ActualStatusCode: actualStatusCode,
ActualHttpTrailers: actualTrailers,
ConnectErrorRaw: connectErrorRaw,
}, nil
}

Expand All @@ -288,6 +333,7 @@ func (i *invoker) clientStream(
ctx, cancel := context.WithCancel(ctx)
defer cancel()

ctx, wire := WithWireCapture(ctx)
stream := i.client.ClientStream(ctx)

// Add the specified request headers to the request
Expand Down Expand Up @@ -340,13 +386,24 @@ func (i *invoker) clientStream(
headers = internal.ConvertToProtoHeader(resp.Header())
trailers = internal.ConvertToProtoHeader(resp.Trailer())
}
var actualStatusCode int32
var connectErrorRaw *structpb.Struct
var actualTrailers []*v1.Header
wireDetails := wire.Get()
if wireDetails != nil {
actualStatusCode = wireDetails.StatusCode
actualTrailers = wireDetails.Trailers
connectErrorRaw = wireDetails.ConnectErrorRaw
}

return &v1.ClientResponseResult{
ResponseHeaders: headers,
ResponseTrailers: trailers,
Payloads: payloads,
Error: protoErr,
ConnectErrorRaw: nil, // TODO
ResponseHeaders: headers,
ResponseTrailers: trailers,
Payloads: payloads,
Error: protoErr,
ActualStatusCode: actualStatusCode,
ActualHttpTrailers: actualTrailers,
ConnectErrorRaw: connectErrorRaw,
}, nil
}

Expand All @@ -361,6 +418,8 @@ func (i *invoker) bidiStream(
ConnectErrorRaw: nil, // TODO
}

ctx, wire := WithWireCapture(ctx)

stream := i.client.BidiStream(ctx)
defer func() {
if result != nil {
smaye81 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -466,6 +525,19 @@ func (i *invoker) bidiStream(
result.Payloads = append(result.Payloads, msg.Payload)
}

var actualStatusCode int32
var connectErrorRaw *structpb.Struct
var actualTrailers []*v1.Header
wireDetails := wire.Get()
if wireDetails != nil {
actualStatusCode = wireDetails.StatusCode
actualTrailers = wireDetails.Trailers
connectErrorRaw = wireDetails.ConnectErrorRaw
}
result.ActualStatusCode = actualStatusCode
result.ActualHttpTrailers = actualTrailers
result.ConnectErrorRaw = connectErrorRaw

if protoErr != nil {
result.Error = protoErr
return result, nil
Expand All @@ -491,10 +563,25 @@ func (i *invoker) unimplemented(
request := connect.NewRequest(ur)
internal.AddHeaders(req.RequestHeaders, request.Header())

ctx, wire := WithWireCapture(ctx)

// Invoke the Unary call
_, err := i.client.Unimplemented(ctx, request)

var actualStatusCode int32
var connectErrorRaw *structpb.Struct
var actualTrailers []*v1.Header
wireDetails := wire.Get()
if wireDetails != nil {
actualStatusCode = wireDetails.StatusCode
actualTrailers = wireDetails.Trailers
connectErrorRaw = wireDetails.ConnectErrorRaw
}
return &v1.ClientResponseResult{
Error: internal.ConvertErrorToProtoError(err),
Error: internal.ConvertErrorToProtoError(err),
ActualStatusCode: actualStatusCode,
ActualHttpTrailers: actualTrailers,
ConnectErrorRaw: connectErrorRaw,
}, nil
}

Expand Down