-
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
Fix metadata, add helper generator #612
Conversation
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
845b310
to
7fd7356
Compare
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
0f92803
to
380faf5
Compare
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
380faf5
to
51d92ba
Compare
@@ -37,12 +37,16 @@ func NewClient() networkservice.NetworkServiceClient { | |||
} | |||
|
|||
func (m *metaDataClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { | |||
ctx = store(ctx, request.GetConnection().GetId(), &m.Map) | |||
connID := request.GetConnection().GetId() |
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.
Good catch!
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.
Although... it should always be true that the conn..GetId() below is the same as the request.GetConnection().GetId() ... its good defensive coding what you've done here, but an issue here would have been a sign of a bug in updatetoken ...
```go | ||
package connect | ||
|
||
//go:generate genny -in=../../utils/metadata/helper/meta_data.template.go -out=client_meta_data.gen.go -pkg=connect gen "prefix=client valueType=networkservice.NetworkServiceClient" |
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.
Is there a way to reference the meta_data_template.go file that doesn't involve file system? I ask, because this is all fine for using metadata inside the sdk repo... but would not work at all from the sdk-vpp repo...
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 have added scripts/genny.sh
, so now we can get template by package + file name:
//go:generate bash ../../../scripts/genny.sh -in=github.com/networkservicemesh/sdk/pkg/tools/metadatahelper/meta_data.template.go -out=int_meta_data.gen.go gen "prefix=Int valueType=int"
such script can be copied to other repositories.
UPD: we can use go list -f '{{.Dir}}' package-name
to find imported package in file system. And it is actually imported, because we are dependent on module containing such package.
//go:generate bash -c "genny -in=$(go list -f '{{.Dir}} github.com/networkservicemesh/sdk/pkg/tools/metadatahelper)/meta_data.template.go -out=client_meta_data.gen.go -pkg=$GOPACKAGE gen 'prefix=client valueType=networkservice.NetworkServiceClient'"
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.
Clever solution :)
82a048f
to
8250474
Compare
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
8250474
to
a60478b
Compare
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
a60478b
to
ddf7cd1
Compare
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 very like the idea to use genny :)
But I feel we still able to not use it because actually, we can solve this via exist sync map generator.
Example
import (
"sync"
"testing"
"github.com/networkservicemesh/api/pkg/api/registry"
"github.com/networkservicemesh/sdk/pkg/registry/memory"
"github.com/stretchr/testify/require"
)
func TestCastSyncMapToTypedMap(t *testing.T) {
var metaDataMap sync.Map // == metadata.Map(...)
metaDataMap.Store("key", ®istry.NetworkServiceEndpoint{})
memoryMap := (*memory.NetworkServiceEndpointSyncMap)(&metaDataMap)
val, _ := memoryMap.Load("key")
require.NotNil(t, val)
}
Note: by registry.NetworkServiceEndpoint
can be used any other generated syncmap :)
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
I like the idea of using a simpler approach via syncmap... but don't quite follow your proposal above... |
@edwarnicke I guess we can try to use generated sync maps to cast map from metadata to typed sync.Map (look at code suggestion #612 (review)) |
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
c9e894a
to
66baa06
Compare
@edwarnicke
Here is the thing we need to use in chain element: type keyType struct{}
func storeConnInfo(ctx context.Context, connInfo *connectionInfo) {
metadata.Map(ctx, false).Store(keyType{}, connInfo)
}
func loadConnInfo(ctx context.Context) (*connectionInfo, bool) {
if raw, ok := metadata.Map(ctx, false).Load(keyType{}); ok {
return raw.(*connectionInfo), true
}
return nil, false
} and we don't want to create a template for it, because it is too small and making a template would affect our ability to give good names for such So I am closing this PR and opening another one to fix issues, add testing and add metadata chain elements into the client, endpoint chains #621. |
Issues
next.Server()
on requestsync.Map
with no typesSolution
gen.go:
client_meta_data.gen.go: