interceptor

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const PkgName = "grpc_client"

Variables

View Source
var (
	// ClientHandleCounter ...
	ClientHandleCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "grpc_client_handle_total",
		}, []string{"type", "name", "method", "peer", "code"})

	// ClientHandleHistogram ...
	ClientHandleHistogram = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "grpc_client_handle_seconds",
		}, []string{"type", "name", "method", "peer"})
)
View Source
var (
	ClientWithBizHandledCounter = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "monitor_grpc_client_accept_result_total",
			Help: "Total number of RPCs accept on the client, regardless of success or failure.",
		}, []string{"grpc_type", "grpc_service", "grpc_method", "grpc_code", "result_code"})
)

Functions

func ForceTimeout

func ForceTimeout(ctx context.Context, timeout time.Duration) context.Context

ForceTimeout force set timeout for this rpc call Deprecated: use WithForceTimeout

func GrpcHeaderCarrierInterceptor

func GrpcHeaderCarrierInterceptor() grpc.UnaryClientInterceptor

GrpcHeaderCarrierInterceptor

func LoggerUnaryClientInterceptor

func LoggerUnaryClientInterceptor(config *LogConf) grpc.UnaryClientInterceptor

loggerUnaryClientInterceptor returns log interceptor for logging

func MetricUnaryClientInterceptor

func MetricUnaryClientInterceptor(successCodes []string) grpc.UnaryClientInterceptor

func TimeoutInterceptor

func TimeoutInterceptor(timeout time.Duration) grpc.UnaryClientInterceptor

TimeoutInterceptor is an interceptor that controls timeout.

Types

type CallOption

type CallOption struct {
	grpc.EmptyCallOption
	// contains filtered or unexported fields
}

CallOption is a grpc.CallOption that is local to timeout interceptor.

func WithForceTimeout

func WithForceTimeout(forceTimeout time.Duration) CallOption

WithForceTimeout sets the RPC timeout for this call only.

type LogConf

type LogConf struct {
	EnableTraceInterceptor     bool
	EnableAccessInterceptorReq bool          // 是否开启记录请求参数,默认开启
	EnableAccessInterceptorRes bool          // 是否开启记录响应参数,默认开启
	SlowLogThreshold           time.Duration // 慢日志记录的阈值,默认600ms
	EnableAccessInterceptor    bool          // 是否开启记录请求数据,默认开启
}

Jump to

Keyboard shortcuts

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