gRPC: Import nested proto files

Greetings!

I try to use gRPC client like this:

const client = new grpc.Client();
client.load(
    [PROTO_PATH] // some global path
    , "service.proto"
);

<...>

export default () => {
    client.connect(`${HOST}:${GRPC_PORT}`, {
        plaintext: true
    });

    const response = client.invoke("<req_name>", {
        <data>
    });
    check(response, {
        'status is OK': (r) => r && r.status === grpc.StatusOK,
    });

    log(JSON.stringify(response));

    client.close();
}

But getting error:

ERRO[0000] GoError: method "/<req_name>" not found in file descriptors
	at reflect.methodValueCall (native)
	at O (webpack://k6-test/./src/main.js:49:22(27))
	at native  executor=shared-iterations scenario=default source=stacktrace

And I canā€™t get why I got this error. My proto file split into several, may it cause problem? Does k6 support import in proto?

Hi @BratSinot !

Sorry for the delay.

Do all your proto files located in the PROTO_PATH:

:thinking:

Could you maybe provide more details on how you use imports?

Thanks,
Cheers!

Hi @olegbespalov ,

I have tried to use the GRPC client same way used by @BratSinot and i have given the [PROTO_PATH] also but its not working giving the same error.

To execute the js file iā€™m using grafana/k6 .

docker run --rm -i -v ā€œ$PWD:/srcā€ grafana/k6 run /src/grpcAi.js

ERROR after this.

level=error msg=ā€œGoError: connection error: desc = "transport: error while dialing: dial tcp 127.0.0.1:50051: connect: connection refused"\n\tat reflect.methodValueCall (native)\n\tat file:///src/grpcAi.js:9:36(6)\n\tat native\nā€ executor=per-vu-iterations scenario=default source=stacktrace

Hi @Amit00p !

As I can see from the log record that youā€™ve provided, an error is different:

transport: error while dialing: dial tcp 127.0.0.1:50051: connect: connection refused

The k6 from inside docker canā€™t reach the target service at the 127.0.0.1:50051

Cheers

Hi @olegbespalov ,

Can you please help me to understand how can we connect to IP address outside the docker from the inside for the given case.

Hey @Amit00p !

You better have a look at a docker documentation, like docker run | Docker Documentation

But I guess something like:

 docker run --rm -i \
  --add-host=test.localhost:host-gateway \
  -v "$PWD:/src" grafana/k6 run /src/grpcAi.js

It could probably work, and then from inside the scripts, you can try to request test.localhost:50051

Cheers

1 Like

Hey there!

I landed on that topic looking for solution of loading nested protofiles, so iā€™ll just ask haha.

Iā€™ve got a custom test.proto file

`import ā€œgoogle/api/annotations.protoā€;

message Test {
string a = 1;
}

service TestMethods {
rpc Test(Test) returns (Test) {
option (google.api.http) = {
post: ā€œā€¦ā€
body: ā€œ*ā€
};
}

and a test.js k6 script file:

import grpc from ā€˜k6/net/grpcā€™;

const client = new grpc.Client();
client.load([ā€˜ā€¦/ā€¦/ā€¦/protoā€™], ā€˜/test.protoā€™);

but i found no way loading google/api/annotations.proto into my file, it keep complaining about ā€˜annotations.protoā€™ no such file or directory

How can i load annotations.proto in my file when its not part of my ā€˜ā€¦/ā€¦protoā€™ directory.
Thanks in advance !

Iā€™ve the same problem. Did you solve the problem? Maybe by copying th google files relative to your files? (I was not successful with that try)

Hey, no, i havent solved the problem, i just copied the same file form y repo into my x repo and i removed the import and the usage of the import, and this is how i use it atm. Couldnt find solution for too long, to continue loosing more timeā€¦
Probably with copying the google files might do the job but version incompatibility would be a nightmare to manageā€¦