Menu
Open source
grpc
Caution
Starting on k6
v0.49
, the experimental modulek6/experimental/grpc
has been graduated, and its functionality is now available in thek6/net/grpc
module. Thek6/experimental/grpc
is deprecated and will be removed inv0.51.0
.To migrate your scripts, replace all
k6/experimental/grpc
imports withk6/net/grpc
.
The k6/experimental/grpc
module is an extension of the k6/net/grpc
. It provides a gRPC client for Remote Procedure Calls (RPC) over HTTP/2.
Starting on k6 v0.49, the k6/net/grpc
module provides streaming support. We recommend using the k6/net/grpc
module instead of k6/experimental/grpc
.
Class/Method | Description |
---|---|
Client | gRPC client used for making RPC calls to a gRPC Server. |
Client.load(importPaths, …protoFiles) | Loads and parses the given protocol buffer definitions to be made available for RPC requests. |
Client.connect(address [,params]) | Connects to a given gRPC service. |
Client.invoke(url, request [,params]) | Makes a unary RPC for the given service/method and returns a Response. |
Client.close() | Close the connection to the gRPC service. |
Params | RPC Request specific options. |
Response | Returned by RPC requests. |
Constants | Define constants to distinguish between gRPC Response statuses. |
Stream | Creates a new GRPC stream. |
Stream.on(event, handler) | Adds a new listener to one of the possible stream event’s. |
Stream.write(message) | Writes a message to the stream. |
Stream.end() | Signals to server that client finished sending. |
Metrics
k6 takes specific measurements for gRPC requests. For the complete list, refer to the Metrics reference.
Example
JavaScript
import grpc from 'k6/experimental/grpc';
import { check, sleep } from 'k6';
const client = new grpc.Client();
client.load(['definitions'], 'hello.proto');
export default () => {
client.connect('grpcbin.test.k6.io:9001', {
// plaintext: false
});
const data = { greeting: 'Bert' };
const response = client.invoke('hello.HelloService/SayHello', data);
check(response, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});
console.log(JSON.stringify(response.message));
client.close();
sleep(1);
};
Was this page helpful?
Related documentation
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video
Performance testing and observability in Grafana Cloud
In this webinar, learn how Grafana Cloud k6 offers you the best developer experience for performance testing.
User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.