Scott Baker | eee8dd8 | 2019-09-24 12:52:34 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2016 gRPC authors. |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | package stats |
| 20 | |
| 21 | import ( |
| 22 | "context" |
| 23 | "net" |
| 24 | ) |
| 25 | |
| 26 | // ConnTagInfo defines the relevant information needed by connection context tagger. |
| 27 | type ConnTagInfo struct { |
| 28 | // RemoteAddr is the remote address of the corresponding connection. |
| 29 | RemoteAddr net.Addr |
| 30 | // LocalAddr is the local address of the corresponding connection. |
| 31 | LocalAddr net.Addr |
| 32 | } |
| 33 | |
| 34 | // RPCTagInfo defines the relevant information needed by RPC context tagger. |
| 35 | type RPCTagInfo struct { |
| 36 | // FullMethodName is the RPC method in the format of /package.service/method. |
| 37 | FullMethodName string |
| 38 | // FailFast indicates if this RPC is failfast. |
| 39 | // This field is only valid on client side, it's always false on server side. |
| 40 | FailFast bool |
| 41 | } |
| 42 | |
| 43 | // Handler defines the interface for the related stats handling (e.g., RPCs, connections). |
| 44 | type Handler interface { |
| 45 | // TagRPC can attach some information to the given context. |
| 46 | // The context used for the rest lifetime of the RPC will be derived from |
| 47 | // the returned context. |
| 48 | TagRPC(context.Context, *RPCTagInfo) context.Context |
| 49 | // HandleRPC processes the RPC stats. |
| 50 | HandleRPC(context.Context, RPCStats) |
| 51 | |
| 52 | // TagConn can attach some information to the given context. |
| 53 | // The returned context will be used for stats handling. |
| 54 | // For conn stats handling, the context used in HandleConn for this |
| 55 | // connection will be derived from the context returned. |
| 56 | // For RPC stats handling, |
| 57 | // - On server side, the context used in HandleRPC for all RPCs on this |
| 58 | // connection will be derived from the context returned. |
| 59 | // - On client side, the context is not derived from the context returned. |
| 60 | TagConn(context.Context, *ConnTagInfo) context.Context |
| 61 | // HandleConn processes the Conn stats. |
| 62 | HandleConn(context.Context, ConnStats) |
| 63 | } |