-
Notifications
You must be signed in to change notification settings - Fork 36
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
Rework adapters #543
Rework adapters #543
Conversation
@@ -224,7 +224,7 @@ func (f *updateTokenServerSuite) TestChain() { | |||
|
|||
got, err := server.Request(context.Background(), request) | |||
require.Equal(t, 3, len(got.Path.PathSegments)) | |||
require.Equal(t, 2, int(got.Path.Index)) | |||
require.Equal(t, 0, int(got.Path.Index)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context:
sdk/pkg/networkservice/common/updatetoken/server_test.go
Lines 214 to 227 in 217f0e0
elements := []networkservice.NetworkServiceServer{ | |
adapters.NewClientToServer(next.NewNetworkServiceClient(updatepath.NewClient("nsc-1"), updatetoken.NewClient(TokenGenerator))), | |
updatepath.NewServer("local-nsm-1"), | |
updatetoken.NewServer(TokenGenerator), | |
adapters.NewClientToServer(next.NewNetworkServiceClient(updatepath.NewClient("local-nsm-1"), updatetoken.NewClient(TokenGenerator))), | |
updatepath.NewServer("remote-nsm-1"), | |
updatetoken.NewServer(TokenGenerator), | |
adapters.NewClientToServer(next.NewNetworkServiceClient(updatepath.NewClient("remote-nsm-1"), updatetoken.NewClient(TokenGenerator)))} | |
server := next.NewNetworkServiceServer(elements...) | |
got, err := server.Request(context.Background(), request) | |
require.Equal(t, 3, len(got.Path.PathSegments)) | |
require.Equal(t, 0, int(got.Path.Index)) |
Path.Index
is now restored by updatetoken on line 215.
This is changed because of the restored nesting order.
return next.Client(ctx).Close(ctx, in, opts...) | ||
} | ||
|
||
func appendContext(ctxPtr *context.Context, prefix, str string) func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think strings.Builder
could reduce strings copying for these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests run in 0.038s
on CI, so I think it doesn't worth optimizing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I can see these test run in 1s on windows
github.com/networkservicemesh/sdk/pkg/networkservice/core/adapters 1.044s
It is not super critical but It could be faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On windows, every test run in at least one second, even such simple as clienturl
. It looks like every test on windows delayed exactly by 1 second (or time measured incorrectly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think we should apply the same patch for registry chains https://github.com/networkservicemesh/sdk/tree/master/pkg/registry/core/adapters.
Ready to merge. Applying the same patch for registry chains (#543 (review)) isn't straightforward because we have to deal with gRPC streams in the |
Update: slightly reworked, now adapters use Reason: make adapters resistant to context clearing. I.e. the following code works fine now: next.Client(ctx).Request(context.Background() /* ← note this */, request, args...) |
Oh... that's slick :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I like these changes.
I think also we can add a few simple benchmark tests to track the performance of adapters.
Benchmarks on my machine, comparing the old and new implementations.
Times in ns/op. |
@xzfc could you add the current benchmark result into README.md of pkg? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -0,0 +1,9 @@ | |||
This package provides adapters to translate between `NetworkServiceServer` and `NetworkServiceClient` interfaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xzfc Could you add the same README.md file for registry adapters?
@@ -0,0 +1,9 @@ | |||
This package provides adapters to translate between `NetworkServiceServer` and `NetworkServiceClient` interfaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package provides adapters to translate between `NetworkServiceServer` and `NetworkServiceClient` interfaces. | |
## Intro | |
This package provides adapters to translate between `NetworkServiceServer` and `NetworkServiceClient` interfaces. |
Signed-off-by: Albert Safin <albert.safin@xored.com>
Signed-off-by: Albert Safin <albert.safin@xored.com>
Signed-off-by: Albert Safin <albert.safin@xored.com>
Signed-off-by: Albert Safin <albert.safin@xored.com>
…k@master networkservicemesh/sdk#543 networkservicemesh/sdk PR link: networkservicemesh/sdk#543 networkservicemesh/sdk commit message: commit dfb11c96a95752aee842105d70c7f4dbe0dc7c60 Author: xzfc <xzfc@users.noreply.github.com> Date: Wed Oct 28 06:31:10 2020 +0000 Rework adapters (#543) * NS adapters: rework, update tests, add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> * NS adapters: use next instead of context Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: rework Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#543 networkservicemesh/sdk PR link: networkservicemesh/sdk#543 networkservicemesh/sdk commit message: commit dfb11c96a95752aee842105d70c7f4dbe0dc7c60 Author: xzfc <xzfc@users.noreply.github.com> Date: Wed Oct 28 06:31:10 2020 +0000 Rework adapters (#543) * NS adapters: rework, update tests, add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> * NS adapters: use next instead of context Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: rework Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#543 networkservicemesh/sdk PR link: networkservicemesh/sdk#543 networkservicemesh/sdk commit message: commit dfb11c96a95752aee842105d70c7f4dbe0dc7c60 Author: xzfc <xzfc@users.noreply.github.com> Date: Wed Oct 28 06:31:10 2020 +0000 Rework adapters (#543) * NS adapters: rework, update tests, add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> * NS adapters: use next instead of context Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: rework Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#543 networkservicemesh/sdk PR link: networkservicemesh/sdk#543 networkservicemesh/sdk commit message: commit dfb11c96a95752aee842105d70c7f4dbe0dc7c60 Author: xzfc <xzfc@users.noreply.github.com> Date: Wed Oct 28 06:31:10 2020 +0000 Rework adapters (#543) * NS adapters: rework, update tests, add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> * NS adapters: use next instead of context Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: rework Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#543 networkservicemesh/sdk PR link: networkservicemesh/sdk#543 networkservicemesh/sdk commit message: commit dfb11c96a95752aee842105d70c7f4dbe0dc7c60 Author: xzfc <xzfc@users.noreply.github.com> Date: Wed Oct 28 06:31:10 2020 +0000 Rework adapters (#543) * NS adapters: rework, update tests, add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> * NS adapters: use next instead of context Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: rework Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#543 networkservicemesh/sdk PR link: networkservicemesh/sdk#543 networkservicemesh/sdk commit message: commit dfb11c96a95752aee842105d70c7f4dbe0dc7c60 Author: xzfc <xzfc@users.noreply.github.com> Date: Wed Oct 28 06:31:10 2020 +0000 Rework adapters (#543) * NS adapters: rework, update tests, add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> * NS adapters: use next instead of context Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: rework Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
…k@master networkservicemesh/sdk#543 networkservicemesh/sdk PR link: networkservicemesh/sdk#543 networkservicemesh/sdk commit message: commit dfb11c96a95752aee842105d70c7f4dbe0dc7c60 Author: xzfc <xzfc@users.noreply.github.com> Date: Wed Oct 28 06:31:10 2020 +0000 Rework adapters (#543) * NS adapters: rework, update tests, add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> * NS adapters: use next instead of context Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: rework Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
* NS adapters: rework, update tests, add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> * NS adapters: use next instead of context Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: rework Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
* NS adapters: rework, update tests, add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> * NS adapters: use next instead of context Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: rework Signed-off-by: Albert Safin <albert.safin@xored.com> * Registry adapters: add benchmarks and readme Signed-off-by: Albert Safin <albert.safin@xored.com> Signed-off-by: Sergey Ershov <sergey.ershov@xored.com>
This PR fixes several problems in adapters:
In nested adapters case, the old adapter may run some requests (a) in the wrong order, or (b) repeat them twice or more. See Rework adapters to prevent calling chain elements twice #535 (comment)
Nesting order. Adapters are now nest requests in the same way as
chain
andnext
do. See Rework adapters to prevent calling chain elements twice #535 (comment)Adapters are now thread-safe.
Tests contain two checks that look similar but serve different purposes:
Closes #535.