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…