grpc

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FailureClassOOM means the platform killed the sandbox for exceeding its
	// configured memory limit.
	FailureClassOOM = "oom"
	// FailureClassTimeout means the platform killed the sandbox for exceeding
	// its configured execution timeout, or the function's own context deadline
	// was exhausted mid-invoke.
	FailureClassTimeout = "timeout"
	// FailureClassUnhandled means the runtime crashed (panic, non-zero exit)
	// for a reason we could not narrow further.
	FailureClassUnhandled = "unhandled"
	// FailureClassHandled means the function returned an error response through
	// the runtime API rather than crashing.
	FailureClassHandled = "handled"
)

Failure classes for a Lambda invoke that came back with a FunctionError set.

The AWS platform reports a runtime crash as FunctionError: "Unhandled" with StatusCode 200 regardless of why the sandbox died, so the class has to be recovered from the tail log and the error payload. Callers use it to tell an out-of-memory kill apart from a platform timeout or an ordinary connector error without needing CloudWatch access.

Variables

View Source
var ErrIllegalHeaderWrite = status.Errorf(codes.Internal, "transport: SetHeader/SetTrailer called after headers were sent")
View Source
var ErrIllegalSendHeader = status.Errorf(codes.Internal, "transport: SendHeader called multiple times")

Functions

func Convert

func Convert[T any, R any](slice []T, f func(in T) R) []R

Convert accepts a list of T and returns a list of R based on the input func.

func MarshalMetadata

func MarshalMetadata(md metadata.MD) (*structpb.Struct, error)

func MetadataForRequest

func MetadataForRequest(req *Request) metadata.MD

func NewClientConn added in v0.2.76

func NewClientConn(transport ClientTransport) grpc.ClientConnInterface

func PeerForRequest

func PeerForRequest(req *Request) *peer.Peer

TODO(morgabra): The transport impl has to give this to us I suppose.

func TimeoutForRequest

func TimeoutForRequest(req *Request) (time.Duration, bool, error)

func UnmarshalMetadata

func UnmarshalMetadata(s *structpb.Struct) metadata.MD

UnmarshalMetadata converts a *structpb.Struct to a metadata.MD. Only keys with []string values are converted. Empty string values are ignored.

Types

type ClientTransport

type ClientTransport interface {
	RoundTrip(context.Context, *Request) (*Response, error)
}

func NewLambdaClientTransport added in v0.2.76

func NewLambdaClientTransport(ctx context.Context, client *lambda.Client, functionName string) (ClientTransport, error)

NewLambdaClientTransport returns a new client transport that invokes a lambda function.

type LambdaInvokeFailure added in v0.22.1

type LambdaInvokeFailure struct {
	// FailureClass is one of the FailureClass* constants.
	FailureClass string
	// RequestID is the AWS request ID, usable to jump straight to the matching
	// CloudWatch log stream.
	RequestID string
	// ErrorType is the runtime error type, from the REPORT line's Error Type
	// field when present, else from the error payload's errorType.
	ErrorType string
	// ErrorMessage is the error payload's errorMessage. It can carry connector
	// output, so it is treated as untrusted for customer-visible strings.
	ErrorMessage string
	// MemorySizeMB is the memory ceiling configured on the function.
	MemorySizeMB int
	// MaxMemoryUsedMB is the peak memory the platform observed for the invoke.
	MaxMemoryUsedMB int
	// DurationMS is the wall-clock duration the platform measured.
	DurationMS float64
	// BilledDurationMS is the rounded duration AWS billed.
	BilledDurationMS int
	// FunctionError is the raw AWS FunctionError value ("Unhandled"/"Handled").
	FunctionError string
	// StatusCode is the raw AWS invoke status code. It is 200 even for a
	// runtime crash, so it is recorded but never used for classification.
	StatusCode int32
	// LogSummary holds the filtered application log lines, with the same
	// semantics as before: platform bookkeeping and structured JSON lines
	// removed. It can carry connector output, so it must be logged rather than
	// returned to a customer.
	LogSummary string
}

LambdaInvokeFailure is a structured description of a failed Lambda invoke.

Every field is derived from data the invoke already returns: the base64 tail log (which always ends with the platform REPORT line), the error payload, and the FunctionError / StatusCode pair. Nothing here requires extra instrumentation or an additional API call.

The memory and duration fields are zero when the REPORT line was absent from the tail window, so treat zero as "unknown" rather than "zero bytes used".

func (*LambdaInvokeFailure) Code added in v0.22.1

func (e *LambdaInvokeFailure) Code() codes.Code

Code returns the gRPC code this failure maps to.

Timeouts stay codes.DeadlineExceeded because the sync framework relies on that code to retry and checkpoint. An OOM is codes.ResourceExhausted: retrying an OOM lands on a fresh sandbox with the same memory ceiling, so it fails again for the same reason every time until the connector or the Lambda memory configuration changes. Retrying it is not useful work, so it is treated as terminal rather than transient. Anything we could not classify keeps codes.Unknown, which is what the untyped errors this replaces already produced.

func (*LambdaInvokeFailure) Error added in v0.22.1

func (e *LambdaInvokeFailure) Error() string

Error renders the failure.

The string deliberately keeps both the "lambda_transport:" prefix and the "logSummary:" separator on every path. Downstream sanitizers key off those markers to strip the log summary before it can reach a customer-visible field such as a connector sync status last_error, and a path that omitted them used to slip raw log text past that check.

func (*LambdaInvokeFailure) GRPCStatus added in v0.22.1

func (e *LambdaInvokeFailure) GRPCStatus() *status.Status

GRPCStatus lets status.Code and status.FromError see the mapped code while callers can still recover the struct with errors.As.

func (*LambdaInvokeFailure) MemoryUtilizationPct added in v0.22.1

func (e *LambdaInvokeFailure) MemoryUtilizationPct() int

MemoryUtilizationPct returns peak memory as a percentage of the configured ceiling, or 0 when the REPORT line did not supply both numbers.

type Request

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

func NewRequest

func NewRequest(method string, req proto.Message, headers metadata.MD) (*Request, error)

func (*Request) Headers

func (f *Request) Headers() metadata.MD

func (*Request) MarshalJSON

func (f *Request) MarshalJSON() ([]byte, error)

MarshalJSON dual-encodes the request: the legacy protojson fields and the v2 wire frame share one JSON object, so legacy connectors keep working (they discard the unknown frame fields) while v2 connectors decode the frame and see annotations whose types this process cannot resolve. When no legacy view can be produced — protojson cannot represent an Any whose type is not linked into this process — the frame is sent alone: a legacy connector would have failed on that payload anyway. Oversized dual payloads fall back to legacy-only to stay under the Lambda invoke limit; v2 connectors accept those too.

func (*Request) Method

func (f *Request) Method() string

func (*Request) UnmarshalJSON

func (f *Request) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON into a Request. v2 wire frames decode losslessly; legacy payloads are protojson, discarding unknown fields and filtering annotations with unresolvable types. See unmarshalTransportJSON.

func (*Request) UnmarshalRequest

func (f *Request) UnmarshalRequest(req any) error

type Response

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

func ErrorResponse

func ErrorResponse(err error) *Response

ErrorResponse converts a given error to a status.Status and returns a *pbtransport.Response. status.FromError(err) must unwrap a status.Status for this to work. Non-status errors are mapped through Baton lambda's application error classification before falling back to codes.Unknown.

func (*Response) Headers

func (f *Response) Headers() metadata.MD

func (*Response) MarshalJSON

func (f *Response) MarshalJSON() ([]byte, error)

MarshalJSON encodes a v2 wire frame when the invoker proved it reads them (see wireV2), preserving annotations whose types this process cannot resolve. Legacy invokers get plain protojson, which fails on an Any whose type is not linked into this process — deliberately: the sender's registry is no authority on what the receiver understands or needs, so degrading the payload by silently dropping data is worse than failing loudly.

func (*Response) Status

func (f *Response) Status() (*status.Status, error)

func (*Response) Trailers

func (f *Response) Trailers() metadata.MD

func (*Response) UnmarshalJSON

func (f *Response) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON into a Response. v2 wire frames decode losslessly with no type resolution. Legacy payloads are protojson, discarding unknown fields and filtering annotations with unresolvable types: responses carry annotations at the response level and nested inside rows (grants embed resources, etc.), so this protects an invoker from annotation types it does not know about — for example an older invoker receiving annotations from a connector built with a newer SDK. See unmarshalTransportJSON.

func (*Response) UnmarshalResponse

func (f *Response) UnmarshalResponse(resp any) error

type Server

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

func NewServer

func NewServer(unaryInterceptor grpc.UnaryServerInterceptor,
) *Server

func (*Server) Handler

func (s *Server) Handler(ctx context.Context, req *Request) (*Response, error)

Handler serves one transport request. The response echoes the request's wire version so v2 invokers get lossless frames and legacy invokers get protojson (see Response.MarshalJSON).

func (*Server) RegisterService

func (s *Server) RegisterService(sd *grpc.ServiceDesc, ss any)

RegisterService registers a service and its implementation to the gRPC server. This is lifted from grpc.Server.

func (*Server) ReplaceServiceImplementation added in v0.8.30

func (s *Server) ReplaceServiceImplementation(oldImpl any, newImpl any) (int, <-chan struct{}, error)

ReplaceServiceImplementation swaps all services currently registered with oldImpl to newImpl and returns a channel that closes when requests using oldImpl have drained. It is intended for lambda connector generation reloads where the service descriptors stay fixed but connector-owned state must be discarded wholesale.

type TransportStream

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

func NewTransportStream

func NewTransportStream(method *grpc.MethodDesc) *TransportStream

func (*TransportStream) Method

func (r *TransportStream) Method() string

func (*TransportStream) Response

func (r *TransportStream) Response() (*Response, error)

func (*TransportStream) SendHeader

func (r *TransportStream) SendHeader(md metadata.MD) error

func (*TransportStream) SetHeader

func (r *TransportStream) SetHeader(md metadata.MD) error

func (*TransportStream) SetResponse

func (r *TransportStream) SetResponse(resp any) error

func (*TransportStream) SetStatus

func (r *TransportStream) SetStatus(st *status.Status)

func (*TransportStream) SetTrailer

func (r *TransportStream) SetTrailer(md metadata.MD) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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