grpc

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package grpc implements a protocol.Protocol driver for gRPC.

VegaLoad has no compiled proto stubs for whatever service a scenario targets — asking an author to generate and vendor them just to load test a service would fight the "every test is a file" principle in AGENTS.md. Instead this driver sends target.Body as an already-encoded message verbatim and hands back the response the same way, using a pass-through codec instead of protobuf's. The scripting layer (built later in Phase 0) is what will give a scenario author a convenient way to produce those bytes; this driver only needs to move them.

Index

Constants

View Source
const (
	EncodingJSON   = "json"
	EncodingBase64 = "base64"
)

Encodings of a script call's body and reply.

Variables

This section is empty.

Functions

func ResultOf added in v0.6.0

func ResultOf(r Reply) protocol.Result

ResultOf turns a Reply into a protocol.Result.

Types

type Call added in v0.6.0

type Call struct {
	// Method is the full method, "/pkg.Service/Method" (the leading slash
	// is optional).
	Method string
	// Body is the request: JSON text, or base64 of the encoded message when
	// Encoding is "base64". Empty JSON means an empty message.
	Body []byte
	// Encoding is "json" (the default) or "base64".
	Encoding string
	// Headers are sent as gRPC metadata.
	Headers map[string]string
	// Timeout bounds the whole call, reflection included. Zero means none.
	Timeout time.Duration
}

Call is one unary call from a script.

type Conn added in v0.6.0

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a gRPC client for scripts. It dials lazily, keeps one connection for every call, and remembers each method's message types. It is safe for concurrent use.

func NewConn added in v0.6.0

func NewConn(target string, insecureSkipVerify bool) (*Conn, error)

NewConn returns a Conn for target (a bare host:port, grpc:// or grpcs://). It never fails because the server is unreachable, only for a bad target.

func (*Conn) Close added in v0.6.0

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Do added in v0.6.0

func (c *Conn) Do(ctx context.Context, call Call) (Reply, error)

Do makes the call. It returns an error only when the call is set up wrongly: a bad method name, an unknown method, a streaming method, a body that is not valid for the method's message, or a server that offers no reflection while the body is JSON. Everything the network or the server does is in the Reply.

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is a gRPC protocol.Protocol. It dials once in New and reuses the same *grpc.ClientConn (and the HTTP/2 connection underneath it) across every call to Do.

func New

func New(target protocol.Target, timeout time.Duration) (*Driver, error)

New returns a ready-to-use Driver for target. target.URL is a bare "host:port", or "grpc://host:port" for the same thing written explicitly, or "grpcs://host:port" to dial over TLS. target.Method must be set to the full RPC method (e.g. "/package.Service/Method") — unlike the HTTP drivers there is no sensible default. timeout bounds each individual call.

New returns an error for anything that is a configuration problem (a missing Method, an unparseable target, an unsupported scheme) — never for the target being unreachable, which Do reports per call instead, since dialing is lazy.

func (*Driver) Close

func (d *Driver) Close() error

Close implements protocol.Protocol.

func (*Driver) Do

func (d *Driver) Do(ctx context.Context) (protocol.Result, error)

Do implements protocol.Protocol.

func (*Driver) Name

func (d *Driver) Name() string

Name implements protocol.Protocol.

type Reply added in v0.6.0

type Reply struct {
	// Code is the gRPC status code (0, OK, when the call worked).
	Code codes.Code
	// Body is the reply: JSON text, or base64 when Encoding was "base64".
	// It is empty when the call failed.
	Body          []byte
	Err           error
	BytesSent     int64
	BytesReceived int64
}

Reply is what a call got back. A call the server answered with an error status, or that failed on the network, is a Reply with Err set, not a Go error: a script is expected to look at it.

Directories

Path Synopsis
Package grpctest runs a small in-process gRPC server for tests in other packages.
Package grpctest runs a small in-process gRPC server for tests in other packages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL