infobloxopen / atlas-cli

Apache License 2.0
14 stars 45 forks source link

Incompatible runtime package and atlas-generated code #60

Closed prakarp closed 4 years ago

prakarp commented 4 years ago

This looks like a compatibility issue with the code that is generated by atlas toolkit and the github.com/grpc-ecosystem/grpc-gateway/runtime package.

There are two errors when running the command " go run cmd/server/*.go "
(Ubuntu 16.04)

  1. runtime.CamelCaseFieldMask() this function does not exist vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/fieldmask.go

  2. runtime.FieldMaskFromRequestBody - this funciton requires an additional argument.

There are many instances of these sets of errors in pkg/pb/service.pb.gw.go (in the generated app)

~/go/src/atid2$ go run cmd/server/*.go
pkg/pb/service.pb.gw.go:148:3: undefined: runtime.CamelCaseFieldMask
pkg/pb/service.pb.gw.go:150:56: not enough arguments in call to runtime.FieldMaskFromRequestBody
        have (io.Reader)
        want (io.Reader, *descriptorpb.DescriptorProto)

How to reproduce

pj@bay:~/go/src$ atlas init-app --name=atapp9 --registry=prakarp --expand=expand.txt --db=true --helm=true --pubsub=true --gateway=true
Generating protobuf files... done!
Starting mod project... done!
Resolving imports... done!
Initializing git repo... done!
pj@bay:~/go/src$ cd atapp9
pj@bay:~/go/src/atapp9$ go run cmd/server/*.go

Expected Output

(Assuming that config.yaml has a GRPC port configured as 9099 because 9090 is used by systemd on Linux. This is from an app that has been "fixed" - see the comment below that indicates a workaround of using the 'generator' package, from bertha.cloud site).

{"level":"debug","msg":"serving internal http at \"0.0.0.0:8081\"","time":"2020-06-09T00:20:50-07:00"}
{"level":"info","msg":"serving gRPC at 0.0.0.0:9099","time":"2020-06-09T00:20:50-07:00"}
{"level":"info","msg":"serving http at 0.0.0.0:8080","time":"2020-06-09T00:20:50-07:00"}

Actual Output

pj@bay:~/go/src$ atlas init-app --name=atapp9 --registry=prakarp --expand=expand.txt --db=true --helm=true --pubsub=true --gateway=true

pj@bay:~/go/src/atapp9$ go run cmd/server/*.go
#atapp9/pkg/pb
pkg/pb/service.pb.gw.go:175:3: undefined: runtime.CamelCaseFieldMask
pkg/pb/service.pb.gw.go:177:56: not enough arguments in call to runtime.FieldMaskFromRequestBody
        have (io.Reader)
        want (io.Reader, *descriptorpb.DescriptorProto)
pkg/pb/service.pb.gw.go:389:3: undefined: runtime.CamelCaseFieldMask
pkg/pb/service.pb.gw.go:391:56: not enough arguments in call to runtime.FieldMaskFromRequestBody
        have (io.Reader)
        want (io.Reader, *descriptorpb.DescriptorProto)
pkg/pb/service.pb.gw.go:603:3: undefined: runtime.CamelCaseFieldMask
pkg/pb/service.pb.gw.go:605:56: not enough arguments in call to runtime.FieldMaskFromRequestBody
        have (io.Reader)
        want (io.Reader, *descriptorpb.DescriptorProto)
pkg/pb/service.pb.gw.go:817:3: undefined: runtime.CamelCaseFieldMask
pkg/pb/service.pb.gw.go:819:56: not enough arguments in call to runtime.FieldMaskFromRequestBody
        have (io.Reader)
        want (io.Reader, *descriptorpb.DescriptorProto)
pkg/pb/service.pb.gw.go:1031:3: undefined: runtime.CamelCaseFieldMask
pkg/pb/service.pb.gw.go:1033:56: not enough arguments in call to runtime.FieldMaskFromRequestBody
        have (io.Reader)
        want (io.Reader, *descriptorpb.DescriptorProto)
pkg/pb/service.pb.gw.go:1033:56: too many errors
pj@bay:~/go/src/atapp9$

Apply a patch (manually)

Patch is available from: https://gitlab.bertha.cloud/partitio/lab/micro-gateway/-/blob/atlas-patch/runtime/fieldmask.go

(Edit the file fieldmask.go.... I have a copy of the file fieldmask.go that has been edited and simply copy over to the generated app like below.

pj@bay:~/go/src/atapp9$ cp ~/fieldmask.go vendor/github.com/grpc-ecosystem/grpc-gateway/runtime
/fieldmask.go

Run the App again

This time the app runs successfully.. the configuration values for the Postgres database are wrong and so the app exits.. That is not related to the issue.

pj@bay:~/go/src/atapp9$ go run cmd/server/*.go
WARNING: Package "github.com/golang/protobuf/protoc-gen-go/generator" is deprecated.
        A future release of golang/protobuf will delete this package,
        which has long been excluded from the compatibility promise.

2020/06/09 12:31:47 Serving from default values, environment variables, and/or flags
{"level":"info","msg":"pubsub: subscribing to server at pubsub.atlas:5555 with topic \"example_hello\" and subscription ID \"example_hello_subscriberid\"","time":"2020-06-09T12:31:47-07:00"}
{"level":"debug","msg":"serving internal http at \"0.0.0.0:8081\"","time":"2020-06-09T12:31:47-07:00"}
{"level":"fatal","msg":"pq: password authentication failed for user \"postgres\"","time":"2020-06-09T12:31:47-07:00"}
exit status 1
pj@bay:~/go/src/atapp9$

Ubuntu 16.04

prakarp commented 4 years ago

https://gitlab.bertha.cloud/partitio/lab/micro-gateway/-/blob/atlas-patch/runtime/fieldmask.go There is a patch available that uses the 'generator' package and at least the build process completes.

The generated application runs, but it remains to be seen if there are semantic differences because of the descriptorpb package isn't used in the patch. Also the use of 'generator' package results in a warning as 'generator' package is supposed to be a private one, and not for public use. But you can move to the next step with the patch above until the proper fix is applied.

seizadi commented 4 years ago

We either need to revert to an older release or update the code generated to conform to the new interface. To fix this you can revert to the older release, until the code is updated:

diff --git a/go.mod b/go.mod
index 46adf47..0c3ad71 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
        github.com/golang/protobuf v1.4.2
        github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
        github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
-       github.com/grpc-ecosystem/grpc-gateway v1.14.6
+       github.com/grpc-ecosystem/grpc-gateway v1.9.6
        github.com/infobloxopen/atlas-app-toolkit v0.21.1

It should compile:

go mod vendor
go build cmd/server/*.go
prakarp commented 4 years ago

https://github.com/infobloxopen/atlas-cli/issues/60#issuecomment-644542690

Closing the issue.