Documentation
¶
Overview ¶
Package grpcx is Stampede's gRPC driver. It calls unary and server-streaming methods without generated code: method descriptors come from server reflection or from .protoset/.proto files, messages are built from JSON with protojson, and responses are rendered back to JSON so checks and extractors work as they do for HTTP.
Index ¶
- Variables
- func CodeByName(name string) (codes.Code, bool)
- func CodeName(c codes.Code) string
- func CompileSources(ctx context.Context, sources map[string][]byte, importPaths []string) (*protoregistry.Files, error)
- func FindMethod(files *protoregistry.Files, service, method string) (protoreflect.MethodDescriptor, error)
- func FullMethod(m protoreflect.MethodDescriptor) string
- func NewRequest(m protoreflect.MethodDescriptor, js []byte) (*dynamicpb.Message, error)
- func Reflect(ctx context.Context, conn grpc.ClientConnInterface, service string) (*protoregistry.Files, error)
- type Descriptors
- type Pool
- type PoolOptions
- type Result
- type Source
- type Target
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidMessage = errors.New("message does not match the method's input type")
ErrInvalidMessage wraps a request message that does not fit the method's input type.
var ErrUnknownMethod = errors.New("unknown gRPC method")
ErrUnknownMethod wraps lookups of a service or method the descriptors do not define, or of a kind of method that cannot be called.
Functions ¶
func CodeByName ¶
CodeByName maps a status code name to its code. Names are matched without regard to case or underscores, so NOT_FOUND, NotFound and not_found all work.
func CompileSources ¶
func CompileSources(ctx context.Context, sources map[string][]byte, importPaths []string) (*protoregistry.Files, error)
CompileSources compiles .proto sources held in memory, keyed by the file name imports use. Imports not among the sources are the built-in well-known types or, when importPaths is set, files found under those directories.
func FindMethod ¶
func FindMethod(files *protoregistry.Files, service, method string) (protoreflect.MethodDescriptor, error)
FindMethod finds a callable method (unary or server streaming) in compiled descriptors.
func FullMethod ¶
func FullMethod(m protoreflect.MethodDescriptor) string
FullMethod is the method's path on the wire: /package.Service/Method.
func NewRequest ¶
func NewRequest(m protoreflect.MethodDescriptor, js []byte) (*dynamicpb.Message, error)
NewRequest builds the method's input message from JSON.
func Reflect ¶
func Reflect(ctx context.Context, conn grpc.ClientConnInterface, service string) (*protoregistry.Files, error)
Reflect fetches the files defining service, and everything they import, from the server's reflection service (v1, falling back to v1alpha).
Types ¶
type Descriptors ¶
type Descriptors struct {
// contains filtered or unexported fields
}
Descriptors resolves and caches method descriptors for a run.
func (*Descriptors) LoadFiles ¶
func (d *Descriptors) LoadFiles(ctx context.Context, src Source) error
LoadFiles loads a source's descriptor files, for validating them before a run.
func (*Descriptors) Method ¶
func (d *Descriptors) Method(ctx context.Context, conn grpc.ClientConnInterface, t Target, src Source, service, method string) (protoreflect.MethodDescriptor, error)
Method finds a method by service full name and method name. File sources are loaded once; reflection asks the target the first time a service is used. Client and bidirectional streaming methods are rejected, as only unary and server streaming calls are supported.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool holds client connections shared by every virtual user, as a service's gRPC client would.
func NewPool ¶
func NewPool(o PoolOptions) *Pool
NewPool creates an empty pool; connections open on first use.
type PoolOptions ¶
type PoolOptions struct {
// Dial replaces the network dialer (DNS cache, tests).
Dial func(ctx context.Context, network, addr string) (net.Conn, error)
InsecureSkipVerify bool
UserAgent string
// PerTarget is how many HTTP/2 connections are opened to each target
// (default 4). Users are spread over them, so one connection's
// concurrent-stream limit does not cap the load.
PerTarget int
}
PoolOptions configures client connections.
type Result ¶
type Result struct {
Start, End time.Time
Code codes.Code
// Body is the response as protojson; a server stream's messages are
// a JSON array.
Body []byte
// Header and Trailer are the response metadata.
Header, Trailer metadata.MD
// Messages counts received messages; First is when the first arrived.
Messages int
First time.Time
BytesIn int64
BytesOut int64
// Err is the call's error, if any; Code is its status code.
Err error
}
Result is a completed call.
func Invoke ¶
func Invoke(ctx context.Context, conn *grpc.ClientConn, m protoreflect.MethodDescriptor, req proto.Message, md metadata.MD, maxBody int64) *Result
Invoke calls a unary or server-streaming method. Up to maxBody bytes of response JSON are kept.
type Source ¶
Source says where a method's descriptor comes from: files when Protoset or Proto is set, otherwise the server's reflection service.
type Target ¶
Target is where calls go: a host:port and whether to use TLS.
func ParseTarget ¶
ParseTarget reads grpc://host:port (plaintext, HTTP/2 prior knowledge) or grpcs://host:port (TLS). An http(s) base URL is accepted too, so a scenario's target.baseURL can serve gRPC steps. A missing port means 443 with TLS and 80 without.