k6/net/grpc module provides a gRPC client for making Remote Procedure Calls (RPC) over HTTP/2.
Overview
Use this module to test gRPC services by making unary and streaming RPC calls. The module supports loading protocol buffer definitions, establishing connections, and invoking RPC methods with full support for metadata and parameters.Importing the Module
API Reference
Client Class
Creates a new gRPC client for making RPC calls to a gRPC server.
Client Methods
Makes a unary RPC call for the given service/method.Parameters:Returns:
RPC method in format
package.Service/MethodRequest message object matching the proto definition
Request-specific parameters (metadata, tags, timeout)
gRPC response object
Asynchronously makes a unary RPC call for the given service/method.Parameters:Returns:
RPC method in format
package.Service/MethodRequest message object matching the proto definition
Request-specific parameters
Promise that resolves to a gRPC Response
Closes the connection to the gRPC service.
Response Object
gRPC status code (see Constants below)
Response message from the server
Response headers/metadata
Response trailers/metadata
Error information if the call failed
Params Object
Custom metadata to send with the request as key-value pairs.
Custom metric tags for filtering results and setting thresholds.
Request timeout (e.g.,
"10s", "500ms")Use plaintext connection (no TLS). Default:
falseStatus Constants
The module provides constants to distinguish between gRPC response statuses:| Constant | Description |
|---|---|
StatusOK | Success |
StatusCanceled | Operation canceled (typically by caller) |
StatusUnknown | Unknown error |
StatusInvalidArgument | Client specified invalid argument |
StatusDeadlineExceeded | Operation expired before completion |
StatusNotFound | Requested entity not found |
StatusAlreadyExists | Entity already exists |
StatusPermissionDenied | Caller lacks permission |
StatusResourceExhausted | Resource exhausted (quota, space, etc.) |
StatusFailedPrecondition | System not in required state |
StatusAborted | Operation aborted (concurrency issue) |
StatusOutOfRange | Operation past valid range |
StatusUnimplemented | Operation not implemented or supported |
StatusInternal | Internal errors |
StatusUnavailable | Service currently unavailable (transient) |
StatusDataLoss | Unrecoverable data loss or corruption |
StatusUnauthenticated | Request lacks valid authentication |
Stream Support
For bidirectional and streaming RPCs:Creates a new gRPC stream for bidirectional or streaming calls.
Adds an event listener for stream events:
data, error, endWrites a message to the stream.
Signals to the server that the client has finished sending.
gRPC Metrics
k6 automatically collects gRPC-specific metrics:| Metric | Type | Description |
|---|---|---|
grpc_req_duration | Trend | Total request duration |
grpc_streams | Counter | Total number of streams |
grpc_streams_msgs_sent | Counter | Messages sent |
grpc_streams_msgs_received | Counter | Messages received |
Examples
Basic Unary RPC
Async Invocation
Streaming RPC
Status Code Checking
Related Resources
Response Object
gRPC response structure
Stream
Streaming RPC support
gRPC Testing Guide
Learn gRPC testing patterns
Protocol Buffers
Protocol buffer documentation