filter

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Overview

Package filter is some default filter implements.

Index

Constants

View Source
const (
	RequestVolumeThresholdField = "circuitBreaker.requestThreshold"
	SleepWindowField            = "circuitBreaker.sleepWindow"  //ms
	ErrorPercentThreshold       = "circuitBreaker.errorPercent" //%
	IncludeBizException         = "circuitBreaker.bizException"
)
View Source
const (
	// endpoint filter
	AccessLog      = "accessLog"
	Metrics        = "metrics"
	CircuitBreaker = "circuitBreaker"
	FailFast       = "failfast"
	Trace          = "trace"
	RateLimit      = "rateLimit"

	// cluster filter
	ClusterAccessLog      = "clusterAccessLog"
	ClusterMetrics        = "clusterMetrics"
	ClusterCircuitBreaker = "clusterCircuitBreaker"
)

ext name

View Source
const (
	MetricsTotalCountSuffix    = ".total_count"
	MetricsTotalCountSuffixLen = len(MetricsTotalCountSuffix)

	MetricsBizErrorCountSuffix   = ".biz_error_count"
	MetricsOtherErrorCountSuffix = ".other_error_count"
	MetricsSlowCountSuffix       = ".slow_count"
)
View Source
const (
	InBoundCall = iota
	OutBoundCall
)

Variables

View Source
var TraceRecordingFunc func(span ot.Span, data *CallData)

TraceRecordingFunc record tracing data, default is DefaultTraceRecordingFunc, Users can rewrite it, and can embed the DefaultTraceRecordingFunc in the Custom Recording Function.

Functions

func DefaultTraceRecordingFunc

func DefaultTraceRecordingFunc(span ot.Span, data *CallData)

DefaultTraceRecordingFunc is the default TraceRecordingFunc.

func GetRateLimitSwitcherName

func GetRateLimitSwitcherName(url *core.URL) string

func RegistDefaultFilters

func RegistDefaultFilters(extFactory motan.ExtensionFactory)

Types

type AccessLogFilter

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

func (*AccessLogFilter) Filter

func (t *AccessLogFilter) Filter(caller motan.Caller, request motan.Request) motan.Response

func (*AccessLogFilter) GetIndex

func (t *AccessLogFilter) GetIndex() int

func (*AccessLogFilter) GetName

func (t *AccessLogFilter) GetName() string

func (*AccessLogFilter) GetNext

func (t *AccessLogFilter) GetNext() motan.EndPointFilter

func (*AccessLogFilter) GetType

func (t *AccessLogFilter) GetType() int32

func (*AccessLogFilter) HasNext

func (t *AccessLogFilter) HasNext() bool

func (*AccessLogFilter) NewFilter

func (t *AccessLogFilter) NewFilter(url *motan.URL) motan.Filter

func (*AccessLogFilter) SetNext

func (t *AccessLogFilter) SetNext(nextFilter motan.EndPointFilter)

type AttachmentReader

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

AttachmentReader is used to read the Attachment. use value type, to decrease the number of escaped variables

func (AttachmentReader) ForeachKey

func (a AttachmentReader) ForeachKey(handler func(key, val string) error) error

type AttachmentWriter

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

func (AttachmentWriter) Set

func (a AttachmentWriter) Set(key, val string)

type CallData

type CallData struct {
	Caller   core.Caller
	Request  core.Request
	Response core.Response

	// If any error occurred during this call, response not get
	Error interface{}
	// the call direction, please refer to InBoundCall and OutBoundCall
	Direction uint32
}

type CircuitBreakerFilter

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

func (*CircuitBreakerFilter) Filter

func (c *CircuitBreakerFilter) Filter(caller motan.Caller, request motan.Request) motan.Response

func (*CircuitBreakerFilter) GetIndex

func (c *CircuitBreakerFilter) GetIndex() int

func (*CircuitBreakerFilter) GetName

func (c *CircuitBreakerFilter) GetName() string

func (*CircuitBreakerFilter) GetNext

func (*CircuitBreakerFilter) GetType

func (c *CircuitBreakerFilter) GetType() int32

func (*CircuitBreakerFilter) HasNext

func (c *CircuitBreakerFilter) HasNext() bool

func (*CircuitBreakerFilter) NewFilter

func (c *CircuitBreakerFilter) NewFilter(url *motan.URL) motan.Filter

func (*CircuitBreakerFilter) SetNext

func (c *CircuitBreakerFilter) SetNext(nextFilter motan.EndPointFilter)

type ClusterAccessLogFilter

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

func (*ClusterAccessLogFilter) Filter

func (t *ClusterAccessLogFilter) Filter(haStrategy motan.HaStrategy, loadBalance motan.LoadBalance, request motan.Request) motan.Response

func (*ClusterAccessLogFilter) GetIndex

func (t *ClusterAccessLogFilter) GetIndex() int

func (*ClusterAccessLogFilter) GetName

func (t *ClusterAccessLogFilter) GetName() string

func (*ClusterAccessLogFilter) GetNext

func (*ClusterAccessLogFilter) GetType

func (t *ClusterAccessLogFilter) GetType() int32

func (*ClusterAccessLogFilter) HasNext

func (t *ClusterAccessLogFilter) HasNext() bool

func (*ClusterAccessLogFilter) NewFilter

func (t *ClusterAccessLogFilter) NewFilter(url *motan.URL) motan.Filter

func (*ClusterAccessLogFilter) SetNext

func (t *ClusterAccessLogFilter) SetNext(nextFilter motan.ClusterFilter)

type ClusterCircuitBreakerFilter

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

func (*ClusterCircuitBreakerFilter) Filter

func (*ClusterCircuitBreakerFilter) GetIndex

func (c *ClusterCircuitBreakerFilter) GetIndex() int

func (*ClusterCircuitBreakerFilter) GetName

func (c *ClusterCircuitBreakerFilter) GetName() string

func (*ClusterCircuitBreakerFilter) GetNext

func (*ClusterCircuitBreakerFilter) GetType

func (c *ClusterCircuitBreakerFilter) GetType() int32

func (*ClusterCircuitBreakerFilter) HasNext

func (c *ClusterCircuitBreakerFilter) HasNext() bool

func (*ClusterCircuitBreakerFilter) NewFilter

func (c *ClusterCircuitBreakerFilter) NewFilter(url *motan.URL) motan.Filter

func (*ClusterCircuitBreakerFilter) SetNext

type ClusterMetricsFilter

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

func (*ClusterMetricsFilter) Filter

func (c *ClusterMetricsFilter) Filter(haStrategy motan.HaStrategy, loadBalance motan.LoadBalance, request motan.Request) motan.Response

func (*ClusterMetricsFilter) GetIndex

func (c *ClusterMetricsFilter) GetIndex() int

func (*ClusterMetricsFilter) GetName

func (c *ClusterMetricsFilter) GetName() string

func (*ClusterMetricsFilter) GetNext

func (*ClusterMetricsFilter) GetType

func (c *ClusterMetricsFilter) GetType() int32

func (*ClusterMetricsFilter) HasNext

func (c *ClusterMetricsFilter) HasNext() bool

func (*ClusterMetricsFilter) NewFilter

func (c *ClusterMetricsFilter) NewFilter(url *motan.URL) motan.Filter

func (*ClusterMetricsFilter) SetNext

func (c *ClusterMetricsFilter) SetNext(cf motan.ClusterFilter)

type FailfastFilter

type FailfastFilter struct {
	URL *motan.URL
	// contains filtered or unexported fields
}

func (*FailfastFilter) Filter

func (e *FailfastFilter) Filter(caller motan.Caller, request motan.Request) motan.Response

func (*FailfastFilter) GetIndex

func (e *FailfastFilter) GetIndex() int

func (*FailfastFilter) GetName

func (e *FailfastFilter) GetName() string

func (*FailfastFilter) GetNext

func (e *FailfastFilter) GetNext() motan.EndPointFilter

func (*FailfastFilter) GetType

func (e *FailfastFilter) GetType() int32

func (*FailfastFilter) HasNext

func (e *FailfastFilter) HasNext() bool

func (*FailfastFilter) IsAvailable

func (e *FailfastFilter) IsAvailable() bool

func (*FailfastFilter) NewFilter

func (e *FailfastFilter) NewFilter(url *motan.URL) motan.Filter

func (*FailfastFilter) SetNext

func (e *FailfastFilter) SetNext(nextFilter motan.EndPointFilter)

type MetricsFilter

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

func (*MetricsFilter) Filter

func (m *MetricsFilter) Filter(caller motan.Caller, request motan.Request) motan.Response

func (*MetricsFilter) GetIndex

func (m *MetricsFilter) GetIndex() int

func (*MetricsFilter) GetName

func (m *MetricsFilter) GetName() string

func (*MetricsFilter) GetNext

func (m *MetricsFilter) GetNext() motan.EndPointFilter

func (*MetricsFilter) GetType

func (m *MetricsFilter) GetType() int32

func (*MetricsFilter) HasNext

func (m *MetricsFilter) HasNext() bool

func (*MetricsFilter) NewFilter

func (m *MetricsFilter) NewFilter(url *motan.URL) motan.Filter

func (*MetricsFilter) SetContext

func (m *MetricsFilter) SetContext(context *motan.Context)

func (*MetricsFilter) SetNext

func (m *MetricsFilter) SetNext(e motan.EndPointFilter)

type RateLimitFilter

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

func (*RateLimitFilter) Filter

func (r *RateLimitFilter) Filter(caller core.Caller, request core.Request) core.Response

func (*RateLimitFilter) GetIndex

func (r *RateLimitFilter) GetIndex() int

func (*RateLimitFilter) GetName

func (r *RateLimitFilter) GetName() string

func (*RateLimitFilter) GetNext

func (r *RateLimitFilter) GetNext() core.EndPointFilter

func (*RateLimitFilter) GetType

func (r *RateLimitFilter) GetType() int32

func (*RateLimitFilter) HasNext

func (r *RateLimitFilter) HasNext() bool

func (*RateLimitFilter) NewFilter

func (r *RateLimitFilter) NewFilter(url *core.URL) core.Filter

func (*RateLimitFilter) SetNext

func (r *RateLimitFilter) SetNext(nextFilter core.EndPointFilter)

type TracingFilter

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

TracingFilter is designed to support OpenTracing, so that we can make use of tracing capability many tracing systems (such as zipkin, etc.)

As described by OpenTracing, for a single call from client to server, both sides will start a span, with the server side span to be child of the client side. Described as following

             call
caller ---------------> callee
    [span1]      [span2]

here [span1] is parent of [span2].

When this filter is applied, it will filter both the incoming and outgoing requests to record trace information. The following diagram is a demonstration.

                         filter
                      +---------+
                      |         |              [span1]
       [span2]  *-----+-- in <--+--------------------- | user |
                |     |         |
                V     |         |
          | -------   |         |
pass-thru | service   |         |
 [span2]  V -------   |         |
                |     |         |
                |     |         |  [span3]
       [span2]  *-----+-> out --+--------------------> | dep  |
                      |         |
                      +---------+

When the filter receives an incoming request, it will:

  1. extract span context from request (will get [span1])
  2. start a child span of the extracted span ([span2], child of [span1])
  3. forward the request with [span2] to the service

Then the service may make an outgoing request to some dependent services, it should pass-through the span information ([span2]). The filter will receive the outgoing request with [span2], then it will.

  1. extract span context from the outgoing request (it should the [span2])
  2. start a child span of the extracted span ([span3], child of [span2])
  3. forward the request with [span3] to the dependent service

So here

        (parent)        (parent)
[span1] <------ [span2] <------ [span3]

NOTE:

The tracing capability should not be duplicated, because duplicated tracing will start more than one subsequent span, then there will be some unwanted spans in the result.

So the TracingFilter should not be applied more than once. and if an existing trace work has been done by the service itself, the TracingFilter should not be used.

func (*TracingFilter) Filter

func (t *TracingFilter) Filter(caller core.Caller, request core.Request) core.Response

func (*TracingFilter) GetIndex

func (*TracingFilter) GetIndex() int

func (*TracingFilter) GetName

func (*TracingFilter) GetName() string

func (*TracingFilter) GetNext

func (t *TracingFilter) GetNext() core.EndPointFilter

func (*TracingFilter) GetType

func (*TracingFilter) GetType() int32

func (*TracingFilter) HasNext

func (t *TracingFilter) HasNext() bool

func (*TracingFilter) NewFilter

func (t *TracingFilter) NewFilter(url *core.URL) core.Filter

func (*TracingFilter) SetNext

func (t *TracingFilter) SetNext(nextFilter core.EndPointFilter)

Jump to

Keyboard shortcuts

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