interceptors

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 21 Imported by: 1

README

GoDoc Go Report Card

interceptors

import "github.com/go-coldbrew/interceptors"
Package interceptors provides a common set of interceptors which are used in Coldbrew

Almost all of these interceptors are reusable and can be used in any other project using grpc.

Index

Variables

var (
    //FilterMethods is the list of methods that are filtered by default
    FilterMethods = []string{"healthcheck", "readycheck", "serverreflectioninfo"}
)

func AddStreamClientInterceptor

func AddStreamClientInterceptor(ctx context.Context, i ...grpc.StreamClientInterceptor)

AddStreamClientInterceptor adds a server interceptor to default server interceptors

func AddStreamServerInterceptor

func AddStreamServerInterceptor(ctx context.Context, i ...grpc.StreamServerInterceptor)

AddStreamServerInterceptor adds a server interceptor to default server interceptors

func AddUnaryClientInterceptor

func AddUnaryClientInterceptor(ctx context.Context, i ...grpc.UnaryClientInterceptor)

AddUnaryClientInterceptor adds a server interceptor to default server interceptors

func AddUnaryServerInterceptor

func AddUnaryServerInterceptor(ctx context.Context, i ...grpc.UnaryServerInterceptor)

AddUnaryServerInterceptor adds a server interceptor to default server interceptors

func DebugLoggingInterceptor

func DebugLoggingInterceptor() grpc.UnaryServerInterceptor

DebugLoggingInterceptor is the interceptor that logs all request/response from a handler

func DefaultClientInterceptor

func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptor

DefaultClientInterceptor are the set of default interceptors that should be applied to all client calls

func DefaultClientInterceptors

func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor

DefaultClientInterceptors are the set of default interceptors that should be applied to all client calls

func DefaultClientStreamInterceptor

func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClientInterceptor

DefaultClientStreamInterceptor are the set of default interceptors that should be applied to all stream client calls

func DefaultClientStreamInterceptors

func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamClientInterceptor

DefaultClientStreamInterceptors are the set of default interceptors that should be applied to all stream client calls

func DefaultInterceptors

func DefaultInterceptors() []grpc.UnaryServerInterceptor

DefaultInterceptors are the set of default interceptors that are applied to all coldbrew methods

func DefaultStreamInterceptors

func DefaultStreamInterceptors() []grpc.StreamServerInterceptor

DefaultStreamInterceptors are the set of default interceptors that should be applied to all coldbrew streams

func DoHTTPtoGRPC

func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error)

DoHTTPtoGRPC allows calling the interceptors when you use the Register<svc-name>HandlerServer in grpc-gateway, see example below for reference

func (s *svc) Echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
    handler := func(ctx context.Context, req interface{}) (interface{}, error) {
        return s.echo(ctx, req.(*proto.EchoRequest))
    }
    r, e := doHTTPtoGRPC(ctx, s, handler, req)
    if e != nil {
        return nil, e.(error)
    }
    return r.(*proto.EchoResponse), nil
}

func (s *svc) echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
       .... implementation ....
}

func FilterMethodsFunc

func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool

FilterMethodsFunc is the default implementation of Filter function

func GRPCClientInterceptor

func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientInterceptor

GRPCClientInterceptor is the interceptor that intercepts all cleint requests and adds tracing info to them

func HystrixClientInterceptor

func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor

HystrixClientInterceptor is the interceptor that intercepts all client requests and adds hystrix info to them

func NRHttpTracer

func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)

NRHttpTracer adds newrelic tracing to this http function

func NewRelicClientInterceptor

func NewRelicClientInterceptor() grpc.UnaryClientInterceptor

NewRelicClientInterceptor intercepts all client actions and reports them to newrelic

func NewRelicInterceptor

func NewRelicInterceptor() grpc.UnaryServerInterceptor

NewRelicInterceptor intercepts all server actions and reports them to newrelic

func OptionsInterceptor

func OptionsInterceptor() grpc.UnaryServerInterceptor

func PanicRecoveryInterceptor

func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor

func ResponseTimeLoggingInterceptor

func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor

ResponseTimeLoggingInterceptor logs response time for each request on server

func ResponseTimeLoggingStreamInterceptor

func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor

ResponseTimeLoggingStreamInterceptor logs response time for stream RPCs.

func ServerErrorInterceptor

func ServerErrorInterceptor() grpc.UnaryServerInterceptor

ServerErrorInterceptor intercepts all server actions and reports them to error notifier

func ServerErrorStreamInterceptor

func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor

ServerErrorStreamInterceptor intercepts server errors for stream RPCs and reports them to the error notifier.

func SetFilterFunc

func SetFilterFunc(ctx context.Context, ff FilterFunc)

SetFilterFunc sets the default filter function to be used by interceptors

func TraceIdInterceptor

func TraceIdInterceptor() grpc.UnaryServerInterceptor

TraceIdInterceptor allows injecting trace id from request objects

func UseColdBrewClientInterceptors

func UseColdBrewClientInterceptors(ctx context.Context, flag bool)
UseColdBrewClientInterceptors allows enabling/disabling coldbrew client interceptors

when set to false, the coldbrew client interceptors will not be used

func UseColdBrewServerInterceptors

func UseColdBrewServerInterceptors(ctx context.Context, flag bool)
UseColdBrewServerInterceptors allows enabling/disabling coldbrew server interceptors

when set to false, the coldbrew server interceptors will not be used

type FilterFunc

If it returns false, the given request will not be traced.

type FilterFunc func(ctx context.Context, fullMethodName string) bool

Generated by gomarkdoc

Documentation

Overview

Package interceptors provides a common set of interceptors which are used in Coldbrew

Almost all of these interceptors are reusable and can be used in any other project using grpc.

Index

Constants

This section is empty.

Variables

View Source
var (
	//FilterMethods is the list of methods that are filtered by default
	FilterMethods = []string{"healthcheck", "readycheck", "serverreflectioninfo"}
)

Functions

func AddStreamClientInterceptor added in v0.1.5

func AddStreamClientInterceptor(ctx context.Context, i ...grpc.StreamClientInterceptor)

AddStreamClientInterceptor adds a server interceptor to default server interceptors

func AddStreamServerInterceptor added in v0.1.5

func AddStreamServerInterceptor(ctx context.Context, i ...grpc.StreamServerInterceptor)

AddStreamServerInterceptor adds a server interceptor to default server interceptors

func AddUnaryClientInterceptor added in v0.1.5

func AddUnaryClientInterceptor(ctx context.Context, i ...grpc.UnaryClientInterceptor)

AddUnaryClientInterceptor adds a server interceptor to default server interceptors

func AddUnaryServerInterceptor added in v0.1.5

func AddUnaryServerInterceptor(ctx context.Context, i ...grpc.UnaryServerInterceptor)

AddUnaryServerInterceptor adds a server interceptor to default server interceptors

func DebugLoggingInterceptor

func DebugLoggingInterceptor() grpc.UnaryServerInterceptor

DebugLoggingInterceptor is the interceptor that logs all request/response from a handler

func DefaultClientInterceptor

func DefaultClientInterceptor(defaultOpts ...interface{}) grpc.UnaryClientInterceptor

DefaultClientInterceptor are the set of default interceptors that should be applied to all client calls

func DefaultClientInterceptors

func DefaultClientInterceptors(defaultOpts ...interface{}) []grpc.UnaryClientInterceptor

DefaultClientInterceptors are the set of default interceptors that should be applied to all client calls

func DefaultClientStreamInterceptor added in v0.1.4

func DefaultClientStreamInterceptor(defaultOpts ...interface{}) grpc.StreamClientInterceptor

DefaultClientStreamInterceptor are the set of default interceptors that should be applied to all stream client calls

func DefaultClientStreamInterceptors added in v0.1.4

func DefaultClientStreamInterceptors(defaultOpts ...interface{}) []grpc.StreamClientInterceptor

DefaultClientStreamInterceptors are the set of default interceptors that should be applied to all stream client calls

func DefaultInterceptors

func DefaultInterceptors() []grpc.UnaryServerInterceptor

DefaultInterceptors are the set of default interceptors that are applied to all coldbrew methods

func DefaultStreamInterceptors

func DefaultStreamInterceptors() []grpc.StreamServerInterceptor

DefaultStreamInterceptors are the set of default interceptors that should be applied to all coldbrew streams

func DoHTTPtoGRPC added in v0.1.2

func DoHTTPtoGRPC(ctx context.Context, svr interface{}, handler func(ctx context.Context, req interface{}) (interface{}, error), in interface{}) (interface{}, error)

DoHTTPtoGRPC allows calling the interceptors when you use the Register<svc-name>HandlerServer in grpc-gateway, see example below for reference

func (s *svc) Echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
    handler := func(ctx context.Context, req interface{}) (interface{}, error) {
        return s.echo(ctx, req.(*proto.EchoRequest))
    }
    r, e := doHTTPtoGRPC(ctx, s, handler, req)
    if e != nil {
        return nil, e.(error)
    }
    return r.(*proto.EchoResponse), nil
}

func (s *svc) echo(ctx context.Context, req *proto.EchoRequest) (*proto.EchoResponse, error) {
       .... implementation ....
}

func FilterMethodsFunc

func FilterMethodsFunc(ctx context.Context, fullMethodName string) bool

FilterMethodsFunc is the default implementation of Filter function

func GRPCClientInterceptor

func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientInterceptor

GRPCClientInterceptor is the interceptor that intercepts all cleint requests and adds tracing info to them

func HystrixClientInterceptor

func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor

HystrixClientInterceptor is the interceptor that intercepts all client requests and adds hystrix info to them

func NRHttpTracer

func NRHttpTracer(pattern string, h http.HandlerFunc) (string, http.HandlerFunc)

NRHttpTracer adds newrelic tracing to this http function

func NewRelicClientInterceptor

func NewRelicClientInterceptor() grpc.UnaryClientInterceptor

NewRelicClientInterceptor intercepts all client actions and reports them to newrelic

func NewRelicInterceptor

func NewRelicInterceptor() grpc.UnaryServerInterceptor

NewRelicInterceptor intercepts all server actions and reports them to newrelic

func OptionsInterceptor

func OptionsInterceptor() grpc.UnaryServerInterceptor

func PanicRecoveryInterceptor

func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor

func ResponseTimeLoggingInterceptor

func ResponseTimeLoggingInterceptor(ff FilterFunc) grpc.UnaryServerInterceptor

ResponseTimeLoggingInterceptor logs response time for each request on server

func ResponseTimeLoggingStreamInterceptor

func ResponseTimeLoggingStreamInterceptor() grpc.StreamServerInterceptor

ResponseTimeLoggingStreamInterceptor logs response time for stream RPCs.

func ServerErrorInterceptor

func ServerErrorInterceptor() grpc.UnaryServerInterceptor

ServerErrorInterceptor intercepts all server actions and reports them to error notifier

func ServerErrorStreamInterceptor

func ServerErrorStreamInterceptor() grpc.StreamServerInterceptor

ServerErrorStreamInterceptor intercepts server errors for stream RPCs and reports them to the error notifier.

func SetFilterFunc

func SetFilterFunc(ctx context.Context, ff FilterFunc)

SetFilterFunc sets the default filter function to be used by interceptors

func TraceIdInterceptor added in v0.1.2

func TraceIdInterceptor() grpc.UnaryServerInterceptor

TraceIdInterceptor allows injecting trace id from request objects

func UseColdBrewClientInterceptors added in v0.1.5

func UseColdBrewClientInterceptors(ctx context.Context, flag bool)

UseColdBrewClientInterceptors allows enabling/disabling coldbrew client interceptors

when set to false, the coldbrew client interceptors will not be used

func UseColdBrewServerInterceptors added in v0.1.5

func UseColdBrewServerInterceptors(ctx context.Context, flag bool)

UseColdBrewServerInterceptors allows enabling/disabling coldbrew server interceptors

when set to false, the coldbrew server interceptors will not be used

func WithHystrix

func WithHystrix() clientOption

WithHystrix enables hystrix

func WithHystrixName

func WithHystrixName(name string) clientOption

WithHystrixName changes the hystrix name to be used in the client interceptors

func WithoutHystrix

func WithoutHystrix() clientOption

WithoutHystrix disables hystrix

Types

type FilterFunc

type FilterFunc func(ctx context.Context, fullMethodName string) bool

If it returns false, the given request will not be traced.

Jump to

Keyboard shortcuts

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