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

mountebank-grpc:imposter load - failed @ protobufjs/src/root.js #3

Closed
mukrisp opened this issue Jan 29, 2020 · 2 comments
Closed

mountebank-grpc:imposter load - failed @ protobufjs/src/root.js #3

mukrisp opened this issue Jan 29, 2020 · 2 comments

Comments

@mukrisp
Copy link

mukrisp commented Jan 29, 2020

Hi,

I am using mountebank with grpc provided in this git

https://github.com/cbrz/mountebank-grpc

Loading imposter is failing with error in mb console. Please find below the error output,

MB_CONSOLE_LOG:
[ root@86a565a751fb:/usr/lib/node_modules/mountebank/mountebank-grpc {master } ]$ mb start --protofile protocols.json --loglevel debug
info: [mb:2525] Loaded custom protocol grpc
info: [mb:2525] mountebank v2.1.2 now taking orders - point your browser to http://localhost:2525/ for help
debug: [mb:2525] config: {"options":{"protofile":"protocols.json","loglevel":"debug","port":2525,"noParse":false,"no-parse":false,"pidfile":"mb.pid","nologfile":false,"logfile":"mb.log","allowInjection":false,"allow-injection":false,"localOnly":false,"local-only":false,"ipWhitelist":["
"],"ip-whitelist":"*","mock":false,"debug":false,"heroku":false},"process":{"nodeVersion":"v13.7.0","architecture":"x64","platform":"linux"}}
info: [mb:2525] POST /imposters
debug: [mb:2525] ::ffff:127.0.0.1:43380 => {"protocol":"grpc","port":4545,"loglevel":"debug","recordRequests":true,"services":{"_note":"need the name of the service and protofile location for this to load","example.ExampleService":{"file":"/usr/lib/node_modules/mountebank/mountebank-grpc/src/protos/example.proto"}},"options":{"protobufjs":{"_note":"any options to protobufjs","includeDirs":["/usr/lib/node_modules/mountebank/mountebank-grpc/src/protos"]}},"stubs":[{"predicates":[{"matches":{"path":"UnaryUnary"},"caseSensitive":false}],"responses":[{"is":{"value":{"_note":"gRPC mock unary call response","_note_streaming":"this is a unary/unary call, streaming requests need the value to be an array","id":100,"data":"mock response"},"metadata":{"_note":"gRPC mock initial/trailing metadata response","initial":{"metadata-initial-key":"metadata-initial-value"},"trailing":{"metadata-trailing-key":"metadata-trailing-value"}},"error":{"_note":"gRPC mock error","status":"OUT_OF_RANGE","message":"invalid message"}}}]}]}
info: [grpc:4545] Open for business...
error: [grpc:4545] /usr/lib/node_modules/mountebank/mountebank-grpc/node_modules/protobufjs/src/root.js:193
for (var i = 0, resolved; i < filename.length; ++i)
^

TypeError: Cannot read property 'length' of undefined
at Root.load (/usr/lib/node_modules/mountebank/mountebank-grpc/node_modules/protobufjs/src/root.js:193:44)
at Root.loadSync (/usr/lib/node_modules/mountebank/mountebank-grpc/node_modules/protobufjs/src/root.js:236:17)
at Object.loadSync (/usr/lib/node_modules/mountebank/mountebank-grpc/node_modules/@grpc/proto-loader/build/src/index.js:221:27)
at Object.getServiceDefinition (/usr/lib/node_modules/mountebank/mountebank-grpc/src/grpc/service.js:38:36)
at /usr/lib/node_modules/mountebank/mountebank-grpc/src/mock.js:35:41
at Array.forEach ()
at Object.getServerInstance (/usr/lib/node_modules/mountebank/mountebank-grpc/src/mock.js:32:37)
at Server. (/usr/lib/node_modules/mountebank/mountebank-grpc/src/index.js:23:41)
at Object.onceWrapper (events.js:427:28)
at Server.emit (events.js:321:20)

error: [grpc:4545] Uh oh! I've crashed! Expect subsequent requests to fail.

IMPOSTER_LOAD_COMMAND:

[ root@86a565a751fb:/usr/lib/node_modules/mountebank/mountebank-grpc {master *} ]$ curl -X POST -d @mb_grpc_templates.ejs http://localhost:2525/imposters --header "Content-Type:application/json"
{
"errors": [
{
"code": "cannot start server",
"message": ""grpc" start command failed (exit code 1)",
"source": "node /usr/lib/node_modules/mountebank/mountebank-grpc/src/index.js",
"domainThrown": true
}
]
}[ root@86a565a751fb:/usr/lib/node_modules/mountebank/mountebank-grpc {master *} ]$

Tried to add debug in protobufjs/src/root.js by adding arguments print in console, mountebank is crashing during imposter load now.
error: [grpc:4545] /usr/lib/node_modules/mountebank/mountebank-grpc/node_modules/protobufjs/src/root.js:193

Root.prototype.load = function load(filename, options, callback) {
console.log(arguments); << added this line for debugging
if (typeof options === "function") {

IMPOSTER_CONTENT:

[ root@86a565a751fb:/usr/lib/node_modules/mountebank/mountebank-grpc {master *} ]$ cat /usr/lib/node_modules/mountebank/mountebank-grpc/mb_grpc_templates.ejs
{
"protocol": "grpc",
"port": 4545,
"loglevel": "debug",
"recordRequests": true,
"services": {
"_note": "need the name of the service and protofile location for this to load",
"example.ExampleService": {
"file": "/usr/lib/node_modules/mountebank/mountebank-grpc/src/protos/example.proto"
}
},
"options": {
"protobufjs": {
"_note": "any options to protobufjs",
"includeDirs": ["/usr/lib/node_modules/mountebank/mountebank-grpc/src/protos"]
}
},
"stubs": [{
"predicates": [
{
"matches": { "path": "UnaryUnary" },
"caseSensitive": false
}
],
"responses": [
{
"is": {
"value": {
"_note": "gRPC mock unary call response",
"_note_streaming": "this is a unary/unary call, streaming requests need the value to be an array",
"id": 100,
"data": "mock response"
},
"metadata": {
"_note": "gRPC mock initial/trailing metadata response",
"initial": {
"metadata-initial-key": "metadata-initial-value"
},
"trailing": {
"metadata-trailing-key": "metadata-trailing-value"
}
},
"error": {
"_note": "gRPC mock error",
"status": "OUT_OF_RANGE",
"message": "invalid message"
}
}
}
]
}]
}
[ root@86a565a751fb:/usr/lib/node_modules/mountebank/mountebank-grpc {master *} ]$

MOUNTEBANK_GRPC_PRTOCOLS_FILE_CONTENT:
[ root@86a565a751fb:/usr/lib/node_modules/mountebank/mountebank-grpc {master *} ]$ cat /usr/lib/node_modules/mountebank/mountebank-grpc/protocols.json
{
"grpc": {
"createCommand": "node /usr/lib/node_modules/mountebank/mountebank-grpc/src/index.js"
}
}
[ root@86a565a751fb:/usr/lib/node_modules/mountebank/mountebank-grpc {master *} ]$

/usr/lib/node_modules/mountebank/mountebank-grpc/src/index.js << content https://github.com/cbrz/mountebank-grpc/blob/master/src/index.js

Thanks and Regards,
Muthukrishnan.P

@cbrz
Copy link
Owner

cbrz commented Jan 30, 2020

Hi @mukrisp ,

I see the problem. I'll comment on a few things though since it looks like you're trying to get this to work 😄.

  1. You mentioned that you put in a print statement and it caused mountebank to crash. I believe it's by design. From the http protocol it looks like you're supposed to print a JSON object to the console so mountebank knows the service loaded successfully. If you were using console.log(...) to print something before that, I could see a crash happening.

  2. The error you're seeing is due to my bad documentation. If you remove the comment under _note: ... under services, the protocol/service should load. When testing this I sent this body to the imposters endpoint via postman:

{
    "protocol": "grpc",
    "port": 4545,
    "loglevel": "debug",
    "recordRequests": true,
    "services": {
        "example.ExampleService": {
            "file": "example.proto"
        }
    },
    "options": {
        "protobufjs": {
            "_note": "any options to protobufjs",
            "includeDirs": ["/mountebank-grpc/src/protos"]
        }
    },
...
}

That property was accidentally being sent to root.js.

  1. You should be able to send a client request to UnaryUnary after that. If you're using the JSON from the doc, you'll want to remove the stubs.responses[0].is.error since that will override the response in value.

Let me know if you have any other problems. There are some limitations with this implementation with the WellKnownTypes, but if you don't need those these are good for a quick mock.

@mukrisp
Copy link
Author

mukrisp commented Jan 30, 2020

Hi,

Thanks for looking into this. As per your suggestion updated the imposter config by excluding the "_note" param.
It worked. Thanks again.
I am exploring on this. Will post here if any info is needed.

Regards,
Muthukrishnan.P

@mukrisp mukrisp closed this as completed Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants