How to send grpc request containing any using k6

this is my proto


/*
 * Copyright 1999-2020 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto3";

import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";

option java_multiple_files = true;
option java_package = "com.alibaba.nacos.api.grpc.auto";

message Metadata {
  string type = 3;
  string clientIp = 8;
  map<string, string> headers = 7;
}

message Payload {
  Metadata metadata = 2;
  google.protobuf.Any body = 3;
}

service Request {
  // Sends a commonRequest
  rpc request (Payload) returns (Payload) {
  }
}

service BiRequestStream {
  // Sends a commonRequest
  rpc requestBiStream (stream Payload) returns (stream Payload) {
  }
}

this is my js

import grpc from 'k6/net/grpc';
import { check, sleep } from 'k6';

const client = new grpc.Client();
client.load(['D:/developtools/k6-v0.38.3-windows-amd64'], 'nacos_grpc_service.proto');

export default () => {
  client.connect('127.0.0.1:29600', {
     plaintext: true
  });
  const data = { 
    metadata: {
        type: 'ConfigBatchListenRequest',
        clientIp: '10.136.97.42',
        headers: {}
    },
    body: {
        "@type": "Payload.body",
        headers: {},
        listen:true,
        configListenContexts:[
            {group:'json',
             md5:'466deec76ecdf5fca6d38571f6324d54',
             dataId:'json',
             tenant:'json'}
        ],
        module:'config'
    }
    };
  const response = client.invoke('Request/request', data);

  check(response, {
    'status is OK': (r) => r && r.status === grpc.StatusOK,
  });

  console.log(JSON.stringify(response.message));

  client.close();
  sleep(1);
};

this is error

GoError: unable to serialise request object to protocol buffer: proto: (line 1:104): unable to resolve "Payload.body": "not found"

I donā€™t understand what this means, can you provide an example based on my proto

Hi @k8spaas,
welcome to the community forum :tada:

Unfortunately, the Any type is not supported in k6 v0.38.x but the good news is that the support will arrive with k6 v0.39.0 and it is already merged in k6 master branch.

If you want to try it without waiting for the official release, you could build the k6 master from the source code. We explain how to do it, here.

Let me know if it helps.

1 Like

hey bro ļ¼thanks a lotļ¼ it worked