protocol

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package protocol defines the shared interface every wire protocol driver (HTTP/1.1, HTTP/2, gRPC, WebSocket, TCP, UDP) implements, plus the request and result types they exchange with the engine.

This package, and the driver packages beneath it, are the only places in VegaLoad that know what HTTP, gRPC, or a WebSocket handshake actually look like on the wire. internal/engine calls a driver's Do method through this interface and otherwise knows nothing protocol-specific — see AGENTS.md's module boundaries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Protocol

type Protocol interface {
	// Name identifies the driver, e.g. "http1", "grpc".
	Name() string

	// Do performs one iteration against the configured target. Return
	// a non-nil error only for a failure that should stop the whole
	// run, such as a misconfigured target — a failed individual
	// request is a Result with Success: false and Err set, not a
	// returned error.
	Do(ctx context.Context) (Result, error)

	// Close releases any resources the driver holds (connections,
	// clients). Called once, after every VU using this driver instance
	// has stopped.
	Close() error
}

Protocol is implemented by each wire protocol driver. The engine package calls Do once per iteration and Close once the driver is no longer needed; it holds no protocol-specific knowledge of its own.

type Result

type Result struct {
	// Success is whether this iteration counts as a pass. A driver
	// decides this itself: the HTTP drivers treat 2xx/3xx as success
	// unless configured otherwise.
	Success bool
	// StatusCode is protocol-specific (HTTP status, gRPC status code,
	// ...). Zero if not applicable.
	StatusCode int
	// BytesSent and BytesReceived are best-effort byte counts for the
	// iteration. Zero if a driver doesn't track them.
	BytesSent     int64
	BytesReceived int64
	// Err describes why Success is false. It is informational only —
	// unlike Do's returned error, a non-nil Err does not stop the run.
	Err error
}

Result is what a driver reports after one Do call — enough detail for internal/report (Phase 1) to build percentiles and pass/fail counts without needing to know which protocol produced it.

type Target

type Target struct {
	// URL is the target address: an http(s):// URL for the HTTP
	// drivers, a ws(s):// URL for WebSocket, or a host:port for gRPC.
	URL string
	// Method is the HTTP verb (GET, POST, ...) for the HTTP drivers,
	// defaulting to GET if empty; for the gRPC driver it is instead the
	// full RPC method, e.g. "/package.Service/Method", which has no
	// default and must be set. Ignored by WebSocket.
	Method string
	// Headers are sent as request headers (HTTP) or connection
	// metadata (gRPC), depending on the driver.
	Headers map[string]string
	// Body is the request payload, if any.
	Body []byte
	// InsecureSkipVerify disables TLS certificate verification for
	// drivers that speak TLS. It exists for testing against targets
	// with self-signed or internal-CA certificates; it is false (verify
	// normally) by default and a scenario author has to opt in.
	InsecureSkipVerify bool
	// Options carries settings that only one driver understands, as
	// text key=value pairs, for example a TCP driver's "read" size or a
	// message queue driver's "topic". They come from repeated -opt
	// flags (or the MCP "options" argument). A driver reads the keys it
	// knows through the Option helpers below. Every driver must list the
	// keys it knows, and RejectUnknownOptions turns any other key into an
	// error, so a typo is never silently ignored. It is nil when none
	// were given.
	Options map[string]string
}

Target describes what a driver connects to and how, in terms generic enough to cover every wire protocol VegaLoad supports. Each driver interprets the fields relevant to it and ignores the rest — for example Method is meaningless to the WebSocket and gRPC drivers.

func (Target) Option added in v0.6.0

func (t Target) Option(key, def string) string

Option returns the value of an option key, or def if it was not set.

func (Target) OptionBool added in v0.6.0

func (t Target) OptionBool(key string, def bool) (bool, error)

OptionBool returns an option as a boolean ("true" or "false"), or def if it was not set.

func (Target) OptionDuration added in v0.6.0

func (t Target) OptionDuration(key string, def time.Duration) (time.Duration, error)

OptionDuration returns an option as a duration such as "250ms" or "2s", or def if it was not set.

func (Target) OptionInt added in v0.6.0

func (t Target) OptionInt(key string, def int) (int, error)

OptionInt returns an option as an integer, or def if it was not set. A value that is not a whole number is an error, so a typo is reported instead of silently using the default.

func (Target) RejectUnknownOptions added in v0.6.0

func (t Target) RejectUnknownOptions(allowed ...string) error

RejectUnknownOptions returns an error if the target has an option key that is not in allowed. A driver that takes no options passes none, and any option is then refused. The error lists the keys that are accepted.

Directories

Path Synopsis
Package grpc implements a protocol.Protocol driver for gRPC.
Package grpc implements a protocol.Protocol driver for gRPC.
grpctest
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.
Package http1 implements a protocol.Protocol driver that speaks plain HTTP/1.1.
Package http1 implements a protocol.Protocol driver that speaks plain HTTP/1.1.
Package http2 implements a protocol.Protocol driver that speaks HTTP/2, over TLS (the normal case, negotiated via ALPN) or over plain TCP ("h2c") when the target is an http:// URL — many internal services run h2c precisely to skip TLS termination, and a load tester that only understood h2-over-TLS would be unable to test them at all.
Package http2 implements a protocol.Protocol driver that speaks HTTP/2, over TLS (the normal case, negotiated via ALPN) or over plain TCP ("h2c") when the target is an http:// URL — many internal services run h2c precisely to skip TLS termination, and a load tester that only understood h2-over-TLS would be unable to test them at all.
Package kafka implements the "kafka" protocol.Protocol driver, for load testing an Apache Kafka cluster (or any broker that speaks the Kafka protocol).
Package kafka implements the "kafka" protocol.Protocol driver, for load testing an Apache Kafka cluster (or any broker that speaks the Kafka protocol).
kafkatest
Package kafkatest is a small fake Kafka broker for tests, so the Kafka driver and the scripting layer can be tested without Docker.
Package kafkatest is a small fake Kafka broker for tests, so the Kafka driver and the scripting layer can be tested without Docker.
Package mqtt implements the "mqtt" protocol.Protocol driver, for load testing an MQTT 3.1.1 broker.
Package mqtt implements the "mqtt" protocol.Protocol driver, for load testing an MQTT 3.1.1 broker.
mqtttest
Package mqtttest is a very small MQTT 3.1.1 broker for tests in other packages, so scripts can be tested without a real broker.
Package mqtttest is a very small MQTT 3.1.1 broker for tests in other packages, so scripts can be tested without a real broker.
Package socket implements the "tcp" and "udp" protocol.Protocol drivers: raw sockets, for a service that speaks its own wire protocol (a custom binary protocol, SMTP, Redis, a syslog or DNS port) and has no driver of its own.
Package socket implements the "tcp" and "udp" protocol.Protocol drivers: raw sockets, for a service that speaks its own wire protocol (a custom binary protocol, SMTP, Redis, a syslog or DNS port) and has no driver of its own.
Package websocket implements a protocol.Protocol driver for WebSocket.
Package websocket implements a protocol.Protocol driver for WebSocket.

Jump to

Keyboard shortcuts

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