github.com/cloudwego/kitex@v0.9.0/pkg/rpcinfo/interface.go (about) 1 /* 2 * Copyright 2021 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package rpcinfo 18 19 import ( 20 "context" 21 "net" 22 "time" 23 24 "github.com/cloudwego/kitex/pkg/kerrors" 25 "github.com/cloudwego/kitex/pkg/serviceinfo" 26 "github.com/cloudwego/kitex/pkg/stats" 27 "github.com/cloudwego/kitex/transport" 28 ) 29 30 // EndpointInfo contains info for endpoint. 31 type EndpointInfo interface { 32 ServiceName() string 33 Method() string 34 Address() net.Addr 35 Tag(key string) (value string, exist bool) 36 DefaultTag(key, def string) string 37 } 38 39 // RPCStats is used to collect statistics about the RPC. 40 type RPCStats interface { 41 Record(ctx context.Context, event stats.Event, status stats.Status, info string) 42 SendSize() uint64 43 // LastSendSize returns the size of the last sent message in a stream. 44 LastSendSize() uint64 45 RecvSize() uint64 46 // LastRecvSize returns the size of the last received message in a stream. 47 LastRecvSize() uint64 48 Error() error 49 Panicked() (bool, interface{}) 50 GetEvent(event stats.Event) Event 51 Level() stats.Level 52 CopyForRetry() RPCStats 53 } 54 55 // Event is the abstraction of an event happened at a specific time. 56 type Event interface { 57 Event() stats.Event 58 Status() stats.Status 59 Info() string 60 Time() time.Time 61 IsNil() bool 62 } 63 64 // Timeouts contains settings of timeouts. 65 type Timeouts interface { 66 RPCTimeout() time.Duration 67 ConnectTimeout() time.Duration 68 ReadWriteTimeout() time.Duration 69 } 70 71 // TimeoutProvider provides timeout settings. 72 type TimeoutProvider interface { 73 Timeouts(ri RPCInfo) Timeouts 74 } 75 76 // RPCConfig contains configuration for RPC. 77 type RPCConfig interface { 78 Timeouts 79 IOBufferSize() int 80 TransportProtocol() transport.Protocol 81 InteractionMode() InteractionMode 82 PayloadCodec() serviceinfo.PayloadCodec 83 } 84 85 // Invocation contains specific information about the call. 86 type Invocation interface { 87 PackageName() string 88 ServiceName() string 89 MethodName() string 90 SeqID() int32 91 BizStatusErr() kerrors.BizStatusErrorIface 92 Extra(key string) interface{} 93 } 94 95 // RPCInfo is the core abstraction of information about an RPC in Kitex. 96 type RPCInfo interface { 97 From() EndpointInfo 98 To() EndpointInfo 99 Invocation() Invocation 100 Config() RPCConfig 101 Stats() RPCStats 102 }