middleware

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	WorkloadAPIServiceName             = "SpiffeWorkloadAPI"
	WorkloadAPIServiceShortName        = "WorkloadAPI"
	EnvoySDSv3ServiceName              = "envoy.service.secret.v3.SecretDiscoveryService"
	EnvoySDSv3ServiceShortName         = "SDS.v3"
	HealthServiceName                  = "grpc.health.v1.Health"
	HealthServiceShortName             = "Health"
	LoggerServiceName                  = "logger.v1.Logger"
	LoggerServiceShortName             = "Logger"
	DelegatedIdentityServiceName       = "spire.api.agent.delegatedidentity.v1.DelegatedIdentity"
	DelegatedIdentityServiceShortName  = "DelegatedIdentity"
	ServerReflectionServiceName        = "grpc.reflection.v1.ServerReflection"
	ServerReflectionV1AlphaServiceName = "grpc.reflection.v1alpha.ServerReflection"
	SubscribeToX509SVIDsMethodName     = "SubscribeToX509SVIDs"
	SubscribeToX509SVIDsMetricKey      = "subscribe_to_x509_svids"
)

Variables

This section is empty.

Functions

func LogMisconfiguration

func LogMisconfiguration(ctx context.Context, msg string)

LogMisconfiguration logs a misconfiguration for the RPC. It assumes that the context has been embellished with the names for the RPC. This method should not be called under normal operation and only when there is an implementation bug. As such there is no attempt at a time/space efficient implementation. In any case, the number of distinct misconfiguration messages intersected with the number of RPCs should not produce any amount of real memory use. Contention on the global mutex should also be reasonable.

func StreamInterceptor

func StreamInterceptor(middleware Middleware) grpc.StreamServerInterceptor

func UnaryInterceptor

func UnaryInterceptor(middleware Middleware) grpc.UnaryServerInterceptor

Types

type Middleware

type Middleware interface {
	// Preprocess is invoked before the gRPC handler is called. It returns a
	// (possibly modified) context that is passed into the handler, which
	// should either be the context passed into the function or one derived
	// from it. If the function returns an error, the gRPC method fails.
	// req passes the request object for unary interceptors and nil for
	// stream interceptors
	Preprocess(ctx context.Context, fullMethod string, req any) (context.Context, error)

	// Postprocess is invoked after the handler is called, or if downstream
	// middleware returns an error from Preprocess. The function is passed an
	// error that was returned from the handler or a downstream middleware
	// during preprocessing. The handlerInvoked boolean, if true, indicates
	// that the handler was executed. If false, then the call failed during
	// preprocessing.
	Postprocess(ctx context.Context, fullMethod string, handlerInvoked bool, rpcErr error)
}

func Chain

func Chain(middleware ...Middleware) Middleware

Chain chains together a series of middleware. The middleware is called in order during preprocessing and in reverse order for postprocessing. The context returned by each Middleware during preprocessing is passed into subsequent middlewares

func Funcs

func Funcs(preprocess PreprocessFunc, postprocess PostprocessFunc) Middleware

Funcs constructs a Middleware from a pair of functions, one for preprocessing, one for postprocessing.

func Postprocess

func Postprocess(fn PostprocessFunc) Middleware

Postprocess creates a middleware from a function that does postprocessing only.

func Preprocess

func Preprocess(fn PreprocessFunc) Middleware

Preprocess creates a middleware from a function that does preprocessing only.

func WithLogger

func WithLogger(log logrus.FieldLogger) Middleware

WithLogger returns logging middleware that provides a per-rpc logger with some initial fields set. If unset, it also provides name metadata to the handler context.

func WithMetrics

func WithMetrics(metrics telemetry.Metrics) Middleware

WithMetrics adds per-call metrics to each RPC call. It emits both a call counter and sample with the call timing. RPC handlers can add their own labels to be attached to the per-call metrics via the rpccontext.AddMetricsLabel function. If unset, it also provides name metadata on to the handler context.

type PostprocessFunc

type PostprocessFunc = func(ctx context.Context, fullMethod string, handlerInvoked bool, rpcErr error)

type PreprocessFunc

type PreprocessFunc = func(ctx context.Context, fullMethod string, req any) (context.Context, error)

Jump to

Keyboard shortcuts

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