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