Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ func GRPCClientInterceptor(options ...grpc_opentracing.Option) grpc.UnaryClientI
return grpc_opentracing.UnaryClientInterceptor(options...)
}

// HystrixClientInterceptor is the interceptor that intercepts all client requests and adds hystrix info to them
// HystrixClientInterceptor returns a unary client interceptor that executes the RPC inside a Hystrix command.
//
// The interceptor applies provided default and per-call client options to configure Hystrix behavior (for example the command name, disabled flag, excluded errors, and excluded gRPC status codes).
// If Hystrix is disabled via options, the RPC is invoked directly. If the underlying RPC returns an error that matches any configured excluded error or whose gRPC status code matches any configured excluded code, Hystrix fallback is skipped and the RPC error is returned.
// Panics raised during the RPC invocation are captured and reported to the notifier before being converted into an error. If the RPC itself returns an error, that error is returned; otherwise any error produced by Hystrix is returned.
func HystrixClientInterceptor(defaultOpts ...grpc.CallOption) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
options := clientOptions{
Expand Down Expand Up @@ -457,4 +461,4 @@ func TraceIdInterceptor() grpc.UnaryServerInterceptor {
}
return handler(ctx, req)
}
}
}
12 changes: 7 additions & 5 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func (h *optionCarrier) process(co *clientOptions) {
h.processor(co)
}

// WithHystrixName changes the hystrix name to be used in the client interceptors
// WithHystrixName creates a clientOption that sets the Hystrix command name used by client interceptors.
// If name is empty, the existing Hystrix name is left unchanged.
func WithHystrixName(name string) clientOption {
return &optionCarrier{
processor: func(co *clientOptions) {
Expand Down Expand Up @@ -55,7 +56,8 @@ func WithHystrix() clientOption {
}
}

// WithHystrixExcludedErrors sets the errors that should be excluded from hystrix circuit breaker
// WithHystrixExcludedErrors returns a clientOption that adds the provided errors to the list of errors
// excluded from the Hystrix circuit breaker.
func WithHystrixExcludedErrors(errors ...error) clientOption {
return &optionCarrier{
processor: func(co *clientOptions) {
Expand All @@ -64,11 +66,11 @@ func WithHystrixExcludedErrors(errors ...error) clientOption {
}
}

// WithHystrixExcludedCodes sets the gRPC codes that should be excluded from hystrix circuit breaker
func WithHystrixExcludedCodes(grpcCodes ...codes.Code) clientOption {
// WithHystrixExcludedCodes returns a clientOption that appends the provided gRPC codes to the list of codes excluded from the Hystrix circuit breaker.
func WithHystrixExcludedCodes(codes ...codes.Code) clientOption {
return &optionCarrier{
processor: func(co *clientOptions) {
co.excludedCodes = append(co.excludedCodes, grpcCodes...)
co.excludedCodes = append(co.excludedCodes, codes...)
},
}
}
Loading