hystrix

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Overview

Package hystrix provides hystrix filter.

Index

Constants

View Source
const (
	// nolint
	HYSTRIX = "hystrix"
)

Variables

This section is empty.

Functions

func NewHystrixFilterError

func NewHystrixFilterError(err error, failByHystrix bool) error

NewHystrixFilterError return a FilterError instance

Types

type CommandConfigWithError

type CommandConfigWithError struct {
	Timeout                int      `yaml:"timeout"`
	MaxConcurrentRequests  int      `yaml:"max_concurrent_requests"`
	RequestVolumeThreshold int      `yaml:"request_volume_threshold"`
	SleepWindow            int      `yaml:"sleep_window"`
	ErrorPercentThreshold  int      `yaml:"error_percent_threshold"`
	Error                  []string `yaml:"error_whitelist"`
}

nolint

type Filter

type Filter struct {
	COrP bool // true for consumer
	// contains filtered or unexported fields
}

Filter for Hystrix *

  • You should add hystrix related configuration in provider or consumer config or both, according to which side you are to apply Filter.
  • For example:
  • filter_conf:
  • hystrix:
  • configs:
  • # =========== Define config here ============
  • "Default":
  • timeout : 1000
  • max_concurrent_requests : 25
  • sleep_window : 5000
  • error_percent_threshold : 50
  • request_volume_threshold: 20
  • "userp":
  • timeout: 2000
  • max_concurrent_requests: 512
  • sleep_window: 4000
  • error_percent_threshold: 35
  • request_volume_threshold: 6
  • "userp_m":
  • timeout : 1200
  • max_concurrent_requests : 512
  • sleep_window : 6000
  • error_percent_threshold : 60
  • request_volume_threshold: 16
  • # =========== Define error whitelist which will be ignored by Hystrix counter ============
  • error_whitelist: [".*exception.*"] *
  • # =========== Apply default config here ===========
  • default: "Default" *
  • services:
  • "com.ikurento.user.UserProvider":
  • # =========== Apply service level config ===========
  • service_config: "userp"
  • # =========== Apply method level config ===========
  • methods:
  • "GetUser": "userp_m"
  • "GetUser1": "userp_m"

func (*Filter) Invoke

func (f *Filter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result

Invoke is an implementation of filter, provides Hystrix pattern latency and fault tolerance

func (*Filter) OnResponse

func (f *Filter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result

OnResponse dummy process, returns the result directly

type FilterConfig

type FilterConfig struct {
	Configs  map[string]*CommandConfigWithError
	Default  string
	Services map[string]ServiceHystrixConfig
}

nolint

type FilterError

type FilterError struct {
	// contains filtered or unexported fields
}

FilterError implements error interface

func (*FilterError) Error

func (hfError *FilterError) Error() string

func (*FilterError) FailByHystrix

func (hfError *FilterError) FailByHystrix() bool

FailByHystrix returns whether the fails causing by Hystrix

type ServiceHystrixConfig

type ServiceHystrixConfig struct {
	ServiceConfig string `yaml:"service_config"`
	Methods       map[string]string
}

nolint

Jump to

Keyboard shortcuts

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