rpcinfo

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 9 Imported by: 674

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 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 PutRPCInfo

func PutRPCInfo(ri RPCInfo)

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

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.

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
}

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)
	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
}

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
}

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
}

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
	RecvSize() uint64
	Error() error
	Panicked() (bool, interface{})
	GetEvent(event stats.Event) Event
	Level() stats.Level
}

RPCStats is used to collect statistics about the RPC.

func NewRPCStats

func NewRPCStats() RPCStats

NewRPCStats creates a new RPCStats.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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