Documentation ¶
Overview ¶
Package grpcbp provides Baseplate specific gRPC related helpers.
Clients ¶
On the client side, this package provides middlewares to support tracing propagation or initialization as well as forwarding EdgeRequestContext according to the Baseplate specification.
Servers ¶
On the server side, this package provides middleware implementations for EdgeRequestContext handling and tracing propagation according to Baseplate specification.
Index ¶
- func AttachEdgeRequestContext(ctx context.Context, ecImpl ecinterface.Interface) context.Context
- func CreateGRPCContextFromSpan(ctx context.Context, span *tracing.Span) context.Context
- func ForwardEdgeContextStreaming(ecImpl ecinterface.Interface) grpc.StreamClientInterceptor
- func ForwardEdgeContextUnary(ecImpl ecinterface.Interface) grpc.UnaryClientInterceptor
- func GetHeader(md metadata.MD, key string) (string, bool)
- func InitializeEdgeContext(ctx context.Context, impl ecinterface.Interface) context.Context
- func InjectEdgeContextInterceptorStreaming(impl ecinterface.Interface) grpc.StreamServerInterceptor
- func InjectEdgeContextInterceptorUnary(impl ecinterface.Interface) grpc.UnaryServerInterceptor
- func InjectPrometheusStreamServerInterceptor(serverSlug string) grpc.StreamServerInterceptor
- func InjectPrometheusUnaryServerInterceptor() grpc.UnaryServerInterceptor
- func InjectServerSpanInterceptorStreaming() grpc.StreamServerInterceptor
- func InjectServerSpanInterceptorUnary() grpc.UnaryServerInterceptor
- func MonitorInterceptorStreaming(args MonitorInterceptorArgs) grpc.StreamClientInterceptor
- func MonitorInterceptorUnary(args MonitorInterceptorArgs) grpc.UnaryClientInterceptor
- func PrometheusStreamClientInterceptor(serverSlug string) grpc.StreamClientInterceptor
- func PrometheusUnaryClientInterceptor(serverSlug string) grpc.UnaryClientInterceptor
- func StartSpanFromGRPCContext(ctx context.Context, name string) (context.Context, *tracing.Span)
- type MonitorInterceptorArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttachEdgeRequestContext ¶
AttachEdgeRequestContext returns a context that has the header of the edge context attached to ctx object set to forward using the "Edge-Request" header on any gRPC calls made with that context object.
func CreateGRPCContextFromSpan ¶
CreateGRPCContextFromSpan injects span info into a context object that can be used in gRPC client code.
func ForwardEdgeContextStreaming ¶
func ForwardEdgeContextStreaming(ecImpl ecinterface.Interface) grpc.StreamClientInterceptor
ForwardEdgeContextStreaming is a client middleware that forwards the EdgeRequestContext set on the context object to the gRPC service being called if one is set.
This is not implemented yet.
func ForwardEdgeContextUnary ¶
func ForwardEdgeContextUnary(ecImpl ecinterface.Interface) grpc.UnaryClientInterceptor
ForwardEdgeContextUnary is a client middleware that forwards the EdgeRequestContext set on the context object to the gRPC service being called if one is set.
func GetHeader ¶
GetHeader retrieves the header value for a given key. Since metadata.MD headers are mapped to a list of strings this function checks if there is at least one value present.
func InitializeEdgeContext ¶
InitializeEdgeContext sets an edge request context created from the gRPC headers set on the context onto the context and configures gRPC to forward the edge requent context header on any gRPC calls made by the server.
func InjectEdgeContextInterceptorStreaming ¶
func InjectEdgeContextInterceptorStreaming(impl ecinterface.Interface) grpc.StreamServerInterceptor
InjectEdgeContextInterceptorStreaming is a server middleware that injects an edge request context created from the gRPC headers set on the context.
This is not implemented yet.
func InjectEdgeContextInterceptorUnary ¶
func InjectEdgeContextInterceptorUnary(impl ecinterface.Interface) grpc.UnaryServerInterceptor
InjectEdgeContextInterceptorUnary is a server middleware that injects an edge request context created from the gRPC headers set on the context.
func InjectPrometheusStreamServerInterceptor ¶ added in v0.9.2
func InjectPrometheusStreamServerInterceptor(serverSlug string) grpc.StreamServerInterceptor
InjectPrometheusStreamServerInterceptor is a server middleware that tracks Prometheus metrics.
This is not implemented yet.
func InjectPrometheusUnaryServerInterceptor ¶ added in v0.9.2
func InjectPrometheusUnaryServerInterceptor() grpc.UnaryServerInterceptor
InjectPrometheusUnaryServerInterceptor is a server middleware that tracks Prometheus metrics.
It emits the following metrics:
* grpc_server_active_requests gauge with labels:
- grpc_service: the fully qualified name of the gRPC service
- grpc_method: the name of the method called on the gRPC service
* grpc_server_latency_seconds histogram with labels:
- all above labels plus
- grpc_success: "true" if status is OK, "false" otherwise
- grpc_type: type of request, i.e unary
* grpc_server_requests_total counter with labels
- all above labels plus
- grpc_code: the human-readable status code, e.g. OK, Internal, etc
func InjectServerSpanInterceptorStreaming ¶
func InjectServerSpanInterceptorStreaming() grpc.StreamServerInterceptor
InjectServerSpanInterceptorStreaming is a server middleware that injects a server span into the `next` context.
If "User-Agent" (transport.HeaderUserAgent) header is set, the created server span will also have "peer.service" (tracing.TagKeyPeerService) tag set to its value.
This is not implemented yet.
func InjectServerSpanInterceptorUnary ¶
func InjectServerSpanInterceptorUnary() grpc.UnaryServerInterceptor
InjectServerSpanInterceptorUnary is a server middleware that injects a server span into the `next` context.
If "User-Agent" (transport.HeaderUserAgent) header is set, the created server span will also have "peer.service" (tracing.TagKeyPeerService) tag set to its value.
func MonitorInterceptorStreaming ¶
func MonitorInterceptorStreaming(args MonitorInterceptorArgs) grpc.StreamClientInterceptor
MonitorInterceptorStreaming is a client middleware that provides tracing and metrics by starting or continuing a span.
This is not implemented yet.
func MonitorInterceptorUnary ¶
func MonitorInterceptorUnary(args MonitorInterceptorArgs) grpc.UnaryClientInterceptor
MonitorInterceptorUnary is a client middleware that provides tracing and metrics by starting or continuing a span.
func PrometheusStreamClientInterceptor ¶ added in v0.9.2
func PrometheusStreamClientInterceptor(serverSlug string) grpc.StreamClientInterceptor
PrometheusStreamClientInterceptor is a client-side interceptor that provides Prometheus monitoring for Streaming RPCs.
This is not implemented yet.
func PrometheusUnaryClientInterceptor ¶ added in v0.9.2
func PrometheusUnaryClientInterceptor(serverSlug string) grpc.UnaryClientInterceptor
PrometheusUnaryClientInterceptor is a client-side interceptor that provides Prometheus monitoring for Unary RPCs.
It emits the following metrics:
* grpc_client_active_requests gauge with labels:
- grpc_service: the fully qualified name of the gRPC service
- grpc_method: the name of the method called on the gRPC service
- grpc_client_name: an arbitray short string representing the backend the client is connecting to, the serverSlug arg
* grpc_client_latency_seconds histogram with labels:
- all above labels plus
- grpc_success: "true" if status is OK, "false" otherwise
- grpc_type: type of request, i.e unary
* grpc_client_requests_total counter with labels
- all above labels plus
- grpc_code: the human-readable status code, e.g. OK, Internal, etc
func StartSpanFromGRPCContext ¶
StartSpanFromGRPCContext creates a server span from a gRPC context object.
This span would usually be used as the span of the whole gRPC endpoint handler, and the parent of the child-spans.
Caller should pass in the context object they got from gRPC library, which would have all the required headers already injected.
Please note that "Sampled" header is default to false according to baseplate specification, so if the context object doesn't have headers injected correctly, this span (and all its child-spans) will never be sampled, unless debug flag was set explicitly later.
If any of the tracing related gRPC header is present but malformed, it will be ignored. The error will also be logged if InitGlobalTracer was last called with a non-nil logger. Absent tracing related headers are always silently ignored.
Types ¶
type MonitorInterceptorArgs ¶
type MonitorInterceptorArgs struct {
ServiceSlug string
}
MonitorInterceptorArgs are the arguments to be passed into the MonitorInterceptorUnary function.