rpcinfo

package
v0.9.2-rc2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 16 Imported by: 675

Documentation

Index

Constants

View Source
const (
	ConnResetTag     = "crrst"
	RetryTag         = "retry"
	RetryLastCostTag = "last_cost"
	RetryPrevInstTag = "prev_inst"
	ShmIPCTag        = "shmipc"
	RemoteClosedTag  = "remote_closed"
)

Tag names in EndpointInfo. Notice: These keys just be used for framework.

View Source
const (
	// connection full url
	HTTPURL = "http_url"
	// specify host header
	HTTPHost = "http_host"
	// http header for remote message tag
	HTTPHeader = "http_header"
)

client HTTP

View Source
const (
	BitRPCTimeout = 1 << iota
	BitConnectTimeout
	BitReadWriteTimeout
	BitIOBufferSize
)

Mask bits.

Variables

This section is empty.

Functions

func CalcEventCostUs added in v0.6.0

func CalcEventCostUs(start, end Event) uint64

CalcEventCostUs calculates the duration between start and end and returns in microsecond.

func ClientPanicToErr added in v0.6.0

func ClientPanicToErr(ctx context.Context, panicInfo interface{}, ri RPCInfo, logErr bool) error

ClientPanicToErr to transform the panic info to error, and output the error if needed.

func EnablePool added in v0.8.0

func EnablePool(enable bool)

EnablePool allows user to enable/disable rpcInfoPool. It's enabled by default for performance, but may cause trouble due to misuses:

referencing RPCInfo in another goroutine other than the one running the handler.

By turning off the pool, we can quickly confirm whether the concurrency issues is caused by such cases, but do remember there's a PERFORMANCE LOSS.

func FreezeRPCInfo added in v0.2.0

func FreezeRPCInfo(ctx context.Context) context.Context

FreezeRPCInfo returns a new context containing an RPCInfo that is safe to be used asynchronically. Note that the RPCStats of the freezed RPCInfo will be nil and the FreezeRPCInfo itself should not be used asynchronically.

Example:

func (p *MyServiceImpl) MyMethod(ctx context.Context, req *MyRequest) (resp *MyResponse, err error) {
    ri := rpcinfo.GetRPCInfo(ctx)
    go func(ctx context.Context) {
        ...
        ri := rpcinfo.GetRPCInfo(ctx) // not concurrent-safe
        ...
    }(ctx2)

    ctx2 := rpcinfo.FreezeRPCInfo(ctx) // this creates a read-only copy of `ri` and attaches it to the new context
    go func(ctx context.Context) {
        ...
        ri := rpcinfo.GetRPCInfo(ctx) // OK
        ...
    }(ctx2)
}

func NewCtxWithRPCInfo

func NewCtxWithRPCInfo(ctx context.Context, ri RPCInfo) context.Context

NewCtxWithRPCInfo creates a new context with the RPCInfo given.

func NewInvocation

func NewInvocation(service, method string, pkgOpt ...string) *invocation

NewInvocation creates a new Invocation with the given service, method and optional package.

func PoolEnabled added in v0.9.0

func PoolEnabled() bool

PoolEnabled returns true if rpcInfoPool is enabled.

func PutRPCInfo

func PutRPCInfo(ri RPCInfo)

PutRPCInfo recycles the RPCInfo. This function is for internal use only.

func Record added in v0.6.0

func Record(ctx context.Context, ri RPCInfo, event stats.Event, err error)

Record records the event to RPCStats.

Types

type EndpointBasicInfo

type EndpointBasicInfo struct {
	ServiceName string
	Method      string
	Tags        map[string]string
}

EndpointBasicInfo should be immutable after created.

type EndpointInfo

type EndpointInfo interface {
	ServiceName() string
	Method() string
	Address() net.Addr
	Tag(key string) (value string, exist bool)
	DefaultTag(key, def string) string
}

EndpointInfo contains info for endpoint.

func EmptyEndpointInfo

func EmptyEndpointInfo() EndpointInfo

EmptyEndpointInfo creates an empty EndpointInfo.

func FromBasicInfo

func FromBasicInfo(bi *EndpointBasicInfo) EndpointInfo

FromBasicInfo converts an EndpointBasicInfo into EndpointInfo.

func NewEndpointInfo

func NewEndpointInfo(serviceName, method string, address net.Addr, tags map[string]string) EndpointInfo

NewEndpointInfo creates an immutable EndpointInfo with the given information.

type Event

type Event interface {
	Event() stats.Event
	Status() stats.Status
	Info() string
	Time() time.Time
	IsNil() bool
}

Event is the abstraction of an event happened at a specific time.

func NewEvent added in v0.9.0

func NewEvent(statsEvent stats.Event, status stats.Status, info string) Event

NewEvent creates a new Event based on the given event, status and info.

type InteractionMode added in v0.0.6

type InteractionMode int32
const (
	PingPong  InteractionMode = 0
	Oneway    InteractionMode = 1
	Streaming InteractionMode = 2
)

type Invocation

type Invocation interface {
	PackageName() string
	ServiceName() string
	MethodName() string
	SeqID() int32
	BizStatusErr() kerrors.BizStatusErrorIface
	Extra(key string) interface{}
}

Invocation contains specific information about the call.

func NewServerInvocation

func NewServerInvocation() Invocation

NewServerInvocation to get Invocation for new request in server side

type InvocationSetter

type InvocationSetter interface {
	SetPackageName(name string)
	SetServiceName(name string)
	SetMethodName(name string)
	SetSeqID(seqID int32)
	SetBizStatusErr(err kerrors.BizStatusErrorIface)
	SetExtra(key string, value interface{})
	Reset()
}

InvocationSetter is used to set information about an RPC.

type MutableEndpointInfo

type MutableEndpointInfo interface {
	SetServiceName(service string) error
	SetMethod(method string) error
	SetAddress(addr net.Addr) error
	SetTag(key, value string) error
	ImmutableView() EndpointInfo
	Reset()
	ResetFromBasicInfo(bi *EndpointBasicInfo)
}

MutableEndpointInfo is used to change the information in the EndpointInfo.

func AsMutableEndpointInfo

func AsMutableEndpointInfo(ei EndpointInfo) MutableEndpointInfo

AsMutableEndpointInfo converts an EndpointInfo into a MutableEndpointInfo. Returns nil if impossible.

func NewMutableEndpointInfo

func NewMutableEndpointInfo(serviceName, method string, address net.Addr, tags map[string]string) MutableEndpointInfo

NewMutableEndpointInfo creates a new MutableEndpointInfo with the given information.

type MutableRPCConfig

type MutableRPCConfig interface {
	SetRPCTimeout(to time.Duration) error
	IsRPCTimeoutLocked() bool
	SetConnectTimeout(to time.Duration) error
	IsConnectTimeoutLocked() bool
	SetReadWriteTimeout(to time.Duration) error
	IsReadWriteTimeoutLocked() bool
	SetIOBufferSize(sz int) error
	SetTransportProtocol(tp transport.Protocol) error
	SetInteractionMode(mode InteractionMode) error
	LockConfig(bits int)
	Clone() MutableRPCConfig
	CopyFrom(from RPCConfig)
	ImmutableView() RPCConfig
	SetPayloadCodec(codec serviceinfo.PayloadCodec)
}

MutableRPCConfig is used to change the information in the RPCConfig.

func AsMutableRPCConfig

func AsMutableRPCConfig(r RPCConfig) MutableRPCConfig

AsMutableRPCConfig .

type MutableRPCStats

type MutableRPCStats interface {
	SetSendSize(size uint64)
	SetRecvSize(size uint64)
	SetError(err error)
	SetPanicked(x interface{})
	SetLevel(level stats.Level)
	Reset()
	ImmutableView() RPCStats
	IncrSendSize(size uint64)
	IncrRecvSize(size uint64)
}

MutableRPCStats is used to change the information in the RPCStats.

func AsMutableRPCStats

func AsMutableRPCStats(r RPCStats) MutableRPCStats

AsMutableRPCStats converts an rpcStats into a MutableRPCStats. Returns nil if impossible.

type RPCConfig

type RPCConfig interface {
	Timeouts
	IOBufferSize() int
	TransportProtocol() transport.Protocol
	InteractionMode() InteractionMode
	PayloadCodec() serviceinfo.PayloadCodec
}

RPCConfig contains configuration for RPC.

func NewRPCConfig

func NewRPCConfig() RPCConfig

NewRPCConfig creates a default RPCConfig.

type RPCInfo

type RPCInfo interface {
	From() EndpointInfo
	To() EndpointInfo
	Invocation() Invocation
	Config() RPCConfig
	Stats() RPCStats
}

RPCInfo is the core abstraction of information about an RPC in Kitex.

func GetRPCInfo

func GetRPCInfo(ctx context.Context) RPCInfo

GetRPCInfo gets RPCInfo from ctx. Returns nil if not found.

func NewRPCInfo

func NewRPCInfo(from, to EndpointInfo, ink Invocation, config RPCConfig, stats RPCStats) RPCInfo

NewRPCInfo creates a new RPCInfo using the given information.

type RPCStats

type RPCStats interface {
	Record(ctx context.Context, event stats.Event, status stats.Status, info string)
	SendSize() uint64
	// LastSendSize returns the size of the last sent message in a stream.
	LastSendSize() uint64
	RecvSize() uint64
	// LastRecvSize returns the size of the last received message in a stream.
	LastRecvSize() uint64
	Error() error
	Panicked() (bool, interface{})
	GetEvent(event stats.Event) Event
	Level() stats.Level
	CopyForRetry() RPCStats
}

RPCStats is used to collect statistics about the RPC.

func NewRPCStats

func NewRPCStats() RPCStats

NewRPCStats creates a new RPCStats.

type StreamEventReporter added in v0.9.0

type StreamEventReporter interface {
	// ReportStreamEvent is for collecting Recv/Send events on stream
	// NOTE: The callee should NOT hold references to event, which may be recycled later
	ReportStreamEvent(ctx context.Context, ri RPCInfo, event Event)
}

StreamEventReporter should be implemented by any tracer that wants to report stream events

type Taggable

type Taggable interface {
	SetTag(key, value string) error
}

Taggable is a type that supports setting tag.

func AsTaggable

func AsTaggable(i interface{}) Taggable

AsTaggable converts an object into a Taggable. Returns nil if impossible.

type TimeoutProvider added in v0.0.5

type TimeoutProvider interface {
	Timeouts(ri RPCInfo) Timeouts
}

TimeoutProvider provides timeout settings.

type Timeouts added in v0.0.5

type Timeouts interface {
	RPCTimeout() time.Duration
	ConnectTimeout() time.Duration
	ReadWriteTimeout() time.Duration
}

Timeouts contains settings of timeouts.

type TraceController added in v0.6.0

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

TraceController controls tracers.

func (*TraceController) Append added in v0.6.0

func (c *TraceController) Append(col stats.Tracer)

Append appends a new tracer to the controller.

func (*TraceController) DoFinish added in v0.6.0

func (c *TraceController) DoFinish(ctx context.Context, ri RPCInfo, err error)

DoFinish calls the tracers in reversed order.

func (*TraceController) DoStart added in v0.6.0

func (c *TraceController) DoStart(ctx context.Context, ri RPCInfo) context.Context

DoStart starts the tracers.

func (*TraceController) GetStreamEventHandler added in v0.9.0

func (c *TraceController) GetStreamEventHandler() stream.StreamEventHandler

GetStreamEventHandler returns the stream event handler If there's no StreamEventReporter, nil is returned for client/server to skip adding tracing middlewares

func (*TraceController) HasStreamEventReporter added in v0.9.0

func (c *TraceController) HasStreamEventReporter() bool

HasStreamEventReporter reports whether there exists any StreamEventReporter.

func (*TraceController) HasTracer added in v0.6.0

func (c *TraceController) HasTracer() bool

HasTracer reports whether there exists any tracer.

func (*TraceController) ReportStreamEvent added in v0.9.0

func (c *TraceController) ReportStreamEvent(ctx context.Context, statsEvent stats.Event, err error)

ReportStreamEvent is for collecting Recv/Send events on stream

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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