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

encoding/thrift: Add mechanisms to perform outbound requests via thriftrw's "nowire" implementation #2088

Merged
merged 12 commits into from
Aug 30, 2021

Conversation

witriew
Copy link
Collaborator

@witriew witriew commented Aug 4, 2021

thriftrw's 'nowire' implementation (known as 'streaming' in the thriftrw
context) is an alternative wire-compatible implementation of the Thrift
protocol that bypasses the intermediate 'thriftrw.Wire' representation and
'streams' the protocol directly to the related objects.

This provides a no-wire compatible Client that can perform requests using
thriftrw's 'nowire' implementation. Much of this code is similar to the
existing Clients that use the 'wire' implementation of thriftrw, except that the
new no-wire Client provides an additional method Enabled() that returns
whether or not this client should be used, if set as an incoming option.
Additionally, the response's body is passed in to properly perform the
'Decode'ing of the protocol into the struct itself.

@CLAassistant
Copy link

CLAassistant commented Aug 4, 2021

CLA assistant check
All committers have signed the CLA.

@witriew
Copy link
Collaborator Author

witriew commented Aug 4, 2021

An alternative to creating a new Client interface and corresponding struct for implementing the "no-wire" representation would be to have the existing thriftClient implement the new NoWireClient, but this would create a bit of stuttering and, I feel, poor form in the names of the methods in the NoWireClient interface.

Since Go doesn't allow for multiple names of the same method defined in a struct, the names of the methods would likely have a separate verb. While generally this is probably fine, having the same struct implement two different 'verbages' to satisfy wire and no-wire ThriftRW compatibility feels really awkward. My preference here was to use the same verbage and create a completely independent client.

@Dogild Dogild changed the title encoding/thrift: Add mechanisms to perform requests via thriftrw's "nowire" implementation encoding/thrift: Add mechanisms to perform outbound requests via thriftrw's "nowire" implementation Aug 12, 2021
@witriew witriew force-pushed the wit/inbounds_nowire_options branch from 2f25e2f to 55d69a5 Compare August 17, 2021 21:35
@witriew witriew force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from db3ee9c to aeef276 Compare August 17, 2021 21:36
encoding/thrift/envelope.go Outdated Show resolved Hide resolved
internal/prototest/examplepb/example.pb.go Outdated Show resolved Hide resolved
encoding/thrift/outbound_nowire.go Outdated Show resolved Hide resolved
encoding/thrift/outbound_nowire.go Show resolved Hide resolved
encoding/thrift/outbound_nowire.go Show resolved Hide resolved
encoding/thrift/outbound_nowire.go Outdated Show resolved Hide resolved
encoding/thrift/outbound_nowire.go Show resolved Hide resolved
encoding/thrift/outbound_nowire.go Outdated Show resolved Hide resolved
encoding/thrift/envelope.go Outdated Show resolved Hide resolved
encoding/thrift/register.go Outdated Show resolved Hide resolved
encoding/thrift/envelope.go Outdated Show resolved Hide resolved
encoding/thrift/multiplex.go Outdated Show resolved Hide resolved
encoding/thrift/multiplex.go Show resolved Hide resolved
@abhinav abhinav force-pushed the wit/inbounds_nowire_options branch from 4e531d3 to fbf7088 Compare August 18, 2021 22:00
@abhinav abhinav force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from 4ef59db to 6940740 Compare August 18, 2021 22:00
@abhinav abhinav force-pushed the wit/inbounds_nowire_options branch from fbf7088 to 4ec75e3 Compare August 18, 2021 22:17
@abhinav abhinav force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from 6940740 to 3a44234 Compare August 18, 2021 22:17
@abhinav abhinav force-pushed the wit/inbounds_nowire_options branch from 4ec75e3 to ffab08c Compare August 18, 2021 22:35
@abhinav abhinav force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from 3a44234 to 2db2c4d Compare August 18, 2021 22:43
@witriew witriew requested a review from Dogild August 23, 2021 22:17
@codecov
Copy link

codecov bot commented Aug 23, 2021

Codecov Report

Merging #2088 (2e703cb) into nowiredev (6828a09) will increase coverage by 0.05%.
The diff coverage is 91.36%.

Impacted file tree graph

@@              Coverage Diff              @@
##           nowiredev    #2088      +/-   ##
=============================================
+ Coverage      87.56%   87.62%   +0.05%     
=============================================
  Files            248      249       +1     
  Lines          13794    13933     +139     
=============================================
+ Hits           12079    12209     +130     
- Misses          1331     1335       +4     
- Partials         384      389       +5     
Impacted Files Coverage Δ
encoding/thrift/outbound.go 84.61% <ø> (ø)
encoding/thrift/thriftrw-plugin-yarpc/client.go 100.00% <ø> (ø)
encoding/thrift/outbound_nowire.go 88.78% <88.78%> (ø)
encoding/thrift/envelope.go 100.00% <100.00%> (ø)
encoding/thrift/inject.go 100.00% <100.00%> (ø)
encoding/thrift/multiplex.go 100.00% <100.00%> (ø)
transport/tchannel/peer.go 94.73% <0.00%> (+1.31%) ⬆️
encoding/thrift/options.go 92.30% <0.00%> (+7.69%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6828a09...2e703cb. Read the comment docs.

encoding/thrift/envelope.go Outdated Show resolved Hide resolved
encoding/thrift/multiplex.go Show resolved Hide resolved
encoding/thrift/outbound_nowire.go Show resolved Hide resolved
encoding/thrift/outbound_nowire.go Outdated Show resolved Hide resolved
encoding/thrift/outbound_nowire.go Show resolved Hide resolved
@witriew witriew force-pushed the wit/inbounds_nowire_options branch from 541cca5 to 6b9876d Compare August 25, 2021 06:37
@witriew witriew force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from bde05d3 to 102ab1e Compare August 25, 2021 06:38
@witriew witriew force-pushed the wit/inbounds_nowire_options branch from 6b9876d to 72ec1ab Compare August 25, 2021 06:45
@witriew witriew force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from 102ab1e to 69776f9 Compare August 25, 2021 06:46
encoding/thrift/outbound_nowire.go Outdated Show resolved Hide resolved
Comment on lines 126 to 130
if c.nwc != nil && c.nwc.Enabled() {
err = c.nwc.Call(ctx, args, &result, opts...)
if err != nil {
return
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this if-else but I don't see any other straightforward way to make this an opt-in flag so I can live with this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine I think. Only other way would be to duplicate the last return and have something like this:

	var result test.TestService_Call_Result
 	args := test.TestService_Call_Helper.Args(_Key)

 	if c.nwc != nil && c.nwc.Enabled() {
 		if err = c.nwc.Call(ctx, args, &result, opts...); err != nil {
 			return
 		}
 		
 		success, err = test.TestService_Call_Helper.UnwrapResponse(&result)
	        return
 	} 
 	
        var body wire.Value
 	body, err = c.c.Call(ctx, args, opts...)
 	if err != nil {
 		return
 	}

 	if err = result.FromWire(body); err != nil {
 		return
 	}

        success, err = test.TestService_Call_Helper.UnwrapResponse(&result)
        return

This improves the readability IMO but this is fine to have the else - up to you @witriew
nit: err can be inline

@witriew witriew requested a review from Dogild August 26, 2021 12:27
Comment on lines 126 to 130
if c.nwc != nil && c.nwc.Enabled() {
err = c.nwc.Call(ctx, args, &result, opts...)
if err != nil {
return
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine I think. Only other way would be to duplicate the last return and have something like this:

	var result test.TestService_Call_Result
 	args := test.TestService_Call_Helper.Args(_Key)

 	if c.nwc != nil && c.nwc.Enabled() {
 		if err = c.nwc.Call(ctx, args, &result, opts...); err != nil {
 			return
 		}
 		
 		success, err = test.TestService_Call_Helper.UnwrapResponse(&result)
	        return
 	} 
 	
        var body wire.Value
 	body, err = c.c.Call(ctx, args, opts...)
 	if err != nil {
 		return
 	}

 	if err = result.FromWire(body); err != nil {
 		return
 	}

        success, err = test.TestService_Call_Helper.UnwrapResponse(&result)
        return

This improves the readability IMO but this is fine to have the else - up to you @witriew
nit: err can be inline

encoding/thrift/envelope.go Outdated Show resolved Hide resolved
encoding/thrift/envelope.go Outdated Show resolved Hide resolved
encoding/thrift/envelope_test.go Show resolved Hide resolved
encoding/thrift/envelope_test.go Outdated Show resolved Hide resolved
encoding/thrift/outbound_nowire_test.go Show resolved Hide resolved
encoding/thrift/outbound_nowire_test.go Outdated Show resolved Hide resolved
encoding/thrift/outbound_nowire_test.go Outdated Show resolved Hide resolved
encoding/thrift/outbound_nowire_test.go Outdated Show resolved Hide resolved
encoding/thrift/outbound_nowire_test.go Show resolved Hide resolved
@witriew witriew force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from d3d4c41 to ddc6103 Compare August 26, 2021 23:38
@witriew witriew requested a review from Dogild August 27, 2021 03:38
@witriew witriew force-pushed the wit/inbounds_nowire_options branch from 72ec1ab to 2ca90f6 Compare August 27, 2021 20:51
@witriew witriew force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from 294040e to a191e01 Compare August 27, 2021 20:52
@witriew witriew force-pushed the wit/inbounds_nowire_options branch from 2ca90f6 to e7c0ab5 Compare August 30, 2021 19:36
@witriew witriew force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from a191e01 to 1f3d2b4 Compare August 30, 2021 19:36
@witriew witriew force-pushed the wit/inbounds_nowire_options branch from e7c0ab5 to 40fc262 Compare August 30, 2021 19:45
Base automatically changed from wit/inbounds_nowire_options to nowiredev August 30, 2021 19:51
usmyth and others added 12 commits August 30, 2021 12:52
…yStreamHandler" to support thriftrw streaming protocol
… yarpc client code

@smyth provided the initial logic for making oubounds thrift calls using the
thriftrw 'no-wire' (read: streaming) implementation.  Leverage this logic in
the generated yarpc client code.

This is done through generating a completely independent client and leveraging
that code path iff the new no-wire client was generated and if it was enabled.
@witriew witriew force-pushed the witriew/usmyth/thriftrw-stream-client-impl branch from 1f3d2b4 to 2e703cb Compare August 30, 2021 19:53
@witriew witriew merged commit e5b3f1a into nowiredev Aug 30, 2021
@witriew witriew deleted the witriew/usmyth/thriftrw-stream-client-impl branch August 30, 2021 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants