chapter10 - vaultd run error
bolerap opened this issue ยท 11 comments
Hi, @matryer .
I tried to run vaultd
by cd to its folder then run command go run main.go
, then see this message errors
../../server_grpc.go:15: cannot use DecodeGRPCHashRequest (type func("golang.org/x/net/context".Context, interface {}) (interface {}, error)) as type "github.com/go-kit/kit/transport/grpc".DecodeRequestFunc in argument to "github.com/go-kit/kit/transport/grpc".NewServer
../../server_grpc.go:15: cannot use EncodeGRPCHashResponse (type func("golang.org/x/net/context".Context, interface {}) (interface {}, error)) as type "github.com/go-kit/kit/transport/grpc".EncodeResponseFunc in argument to "github.com/go-kit/kit/transport/grpc".NewServer
../../server_grpc.go:21: cannot use DecodeGRPCValidateRequest (type func("golang.org/x/net/context".Context, interface {}) (interface {}, error)) as type "github.com/go-kit/kit/transport/grpc".DecodeRequestFunc in argument to "github.com/go-kit/kit/transport/grpc".NewServer
../../server_grpc.go:21: cannot use EncodeGRPCValidateResponse (type func("golang.org/x/net/context".Context, interface {}) (interface {}, error)) as type "github.com/go-kit/kit/transport/grpc".EncodeResponseFunc in argument to "github.com/go-kit/kit/transport/grpc".NewServer
../../server_http.go:15: cannot use decodeHashRequest (type func("golang.org/x/net/context".Context, *"net/http".Request) (interface {}, error)) as type "github.com/go-kit/kit/transport/http".DecodeRequestFunc in argument to "github.com/go-kit/kit/transport/http".NewServer
../../server_http.go:15: cannot use encodeResponse (type func("golang.org/x/net/context".Context, "net/http".ResponseWriter, interface {}) error) as type "github.com/go-kit/kit/transport/http".EncodeResponseFunc in argument to "github.com/go-kit/kit/transport/http".NewServer
../../server_http.go:21: cannot use decodeValidateRequest (type func("golang.org/x/net/context".Context, *"net/http".Request) (interface {}, error)) as type "github.com/go-kit/kit/transport/http".DecodeRequestFunc in argument to "github.com/go-kit/kit/transport/http".NewServer
../../server_http.go:21: cannot use encodeResponse (type func("golang.org/x/net/context".Context, "net/http".ResponseWriter, interface {}) error) as type "github.com/go-kit/kit/transport/http".EncodeResponseFunc in argument to "github.com/go-kit/kit/transport/http".NewServer
../../service.go:81: cannot use func literal (type func("golang.org/x/net/context".Context, interface {}) (interface {}, error)) as type endpoint.Endpoint in return argument
../../service.go:92: cannot use func literal (type func("golang.org/x/net/context".Context, interface {}) (interface {}, error)) as type endpoint.Endpoint in return argument
../../service.go:92: too many errors
What wrong with me?
There is nothing wrong with your code. I bumped into the same issue. It seems that grpc uses the old context package, while go-kit uses the new context package. Trying to find a permanent solution as well.
For now just ran go fix on on the grpc package to be able to continue.
What solved this issue for me is manually editing vault.pb.go. First I imported the old context like this: import oldcontext "golang.org/x/net/context"
And then changed _Vault_Hash_Handler and _Vault_Validate_Handler to use oldcontext as follows:
func _Vault_Hash_Handler(srv interface{}, ctx oldcontext.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HashRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(VaultServer).Hash(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/pb.Vault/Hash",
}
handler := func(ctx oldcontext.Context, req interface{}) (interface{}, error) {
return srv.(VaultServer).Hash(ctx, req.(*HashRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Vault_Validate_Handler(srv interface{}, ctx oldcontext.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ValidateRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(VaultServer).Validate(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/pb.Vault/Validate",
}
handler := func(ctx oldcontext.Context, req interface{}) (interface{}, error) {
return srv.(VaultServer).Validate(ctx, req.(*ValidateRequest))
}
return interceptor(ctx, in, info, handler)
}
As @arjanvaneersel mentioned, Go kit updated new version and also dropped context.Context argument from NewServer function so I would drop ctx
argument accordingly.
Then my temporary fix was using previous version of Go kit transport/grpc package (version v.0.3.0) by using git checkout
command:
- Delete folder grpc in $GOPATH/src/github.com/go-kit/kit/transport
- Move to the directory (if you are not): cd $GOPATH/src/github.com/go-kit/kit/transport
- bash
git clone https://github.com/go-kit/kit.git
- bash
git checkout tags/v.0.3.0
(you can list tags withgit tag -l
)
@matryer Any plan to update this chapter to run with new Go kit version?
I will definitely update this in future versions. Thanks for reporting it.
Hi @matryer
When running the vaultcli from chapter 11 I get this message.
2019/01/29 12:11:50 rpc error: code = Unimplemented desc = unknown service Vault
The HTTP service worked great.
Any thoughts on what to do to fix?
Regards
in client.go
change Vault to pb.Vault
func New(conn *grpc.ClientConn) vault.Service {
var hashEndpoint = grpctransport.NewClient(
conn, "pb.Vault", "Hash",
vault.EncodeGRPCHashRequest,
vault.DecodeGRPCHashResponse,
pb.HashResponse{},
).Endpoint()
var validateEndpoint = grpctransport.NewClient(
conn, "pb.Vault", "Validate",
vault.EncodeGRPCValidateRequest,
vault.DecodeGRPCValidateResponse,
pb.ValidateResponse{},
).Endpoint()
return vault.Endpoints{
HashEndpoint: hashEndpoint,
ValidateEndpoint: validateEndpoint,
}
}
Hi @sugarme, a small correction in the workaround you have provided here :
bash git checkout tags/v0.3.0
is the correct command to check out the specified version. There is no tag named v.0.3.0
and I hope it could be a typo. Anyway thanks a lot for the temporary solution.
After done this workaround, I got the following issue and stuck here :
root@35b9627755ee:/go/gbp/goblueprints/chapter10/vault/cmd/vaultd# go run main.go
# github.com/go-kit/kit/transport/grpc
/go/src/github.com/go-kit/kit/transport/grpc/client.go:89:9: undefined: metadata.NewContext
/go/src/github.com/go-kit/kit/transport/grpc/server.go:80:12: undefined: metadata.FromContext
/go/src/github.com/go-kit/kit/transport/grpc/server.go:90:12: undefined: metadata.NewContext
/go/src/github.com/go-kit/kit/transport/grpc/server.go:109:12: undefined: metadata.NewContext
root@35b9627755ee:/go/gbp/goblueprints/chapter10/vault/cmd/vaultd#
The go binary and go-kit versions are as follows :
root@35b9627755ee:/go/gbp/goblueprints/chapter10/vault/cmd/vaultd# go version
go version go1.13.1 linux/amd64
root@35b9627755ee:/go/gbp/goblueprints/chapter10/vault/cmd/vaultd#
root@35b9627755ee:/go/gbp/goblueprints/chapter10/vault/cmd/vaultd# cd /go/src/github.com/go-kit/kit/
root@35b9627755ee:/go/src/github.com/go-kit/kit#
root@35b9627755ee:/go/src/github.com/go-kit/kit# git branch
* (HEAD detached at v0.3.0)
master
root@35b9627755ee:/go/src/github.com/go-kit/kit#
Looking for helping hands and it's very much appreciated.
Hey @skvenkat
Idk if you're still looking for the answer but NewContext and FromContext have been deprecated to avoid incoming RPC's from appearing in the outgoing - due to the similar names.
New names are: metadata.FromContext() to metadata.FromIncomingContext(). Similarly metadata.NewContext() to metadata.NewOutgoingContext().
I have refactored the project to use go.mod
as I'm on Go 1.15, and updated all the dependencies to work properly. Also, github.com/go-kit/kit/ratelimit
does not depend on github.com/juju/ratelimit
anymore, so that is updated too. If you're still interested, you can check it out here: https://github.com/akolybelnikov/vault
Thanks @akolybelnikov - Somebody needs to invent paper that we can remotely update :)
I have refactored the project to use
go.mod
as I'm on Go 1.15, and updated all the dependencies to work properly. Also,github.com/go-kit/kit/ratelimit
does not depend ongithub.com/juju/ratelimit
anymore, so that is updated too. If you're still interested, you can check it out here: https://github.com/akolybelnikov/vault
THANK YOU! You sir, deserve an award.