OSDN Git Service

new repo
[bytom/vapor.git] / vendor / google.golang.org / grpc / stats / handlers.go
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         "net"
23
24         "golang.org/x/net/context"
25 )
26
27 // ConnTagInfo defines the relevant information needed by connection context tagger.
28 type ConnTagInfo struct {
29         // RemoteAddr is the remote address of the corresponding connection.
30         RemoteAddr net.Addr
31         // LocalAddr is the local address of the corresponding connection.
32         LocalAddr net.Addr
33 }
34
35 // RPCTagInfo defines the relevant information needed by RPC context tagger.
36 type RPCTagInfo struct {
37         // FullMethodName is the RPC method in the format of /package.service/method.
38         FullMethodName string
39         // FailFast indicates if this RPC is failfast.
40         // This field is only valid on client side, it's always false on server side.
41         FailFast bool
42 }
43
44 // Handler defines the interface for the related stats handling (e.g., RPCs, connections).
45 type Handler interface {
46         // TagRPC can attach some information to the given context.
47         // The context used for the rest lifetime of the RPC will be derived from
48         // the returned context.
49         TagRPC(context.Context, *RPCTagInfo) context.Context
50         // HandleRPC processes the RPC stats.
51         HandleRPC(context.Context, RPCStats)
52
53         // TagConn can attach some information to the given context.
54         // The returned context will be used for stats handling.
55         // For conn stats handling, the context used in HandleConn for this
56         // connection will be derived from the context returned.
57         // For RPC stats handling,
58         //  - On server side, the context used in HandleRPC for all RPCs on this
59         // connection will be derived from the context returned.
60         //  - On client side, the context is not derived from the context returned.
61         TagConn(context.Context, *ConnTagInfo) context.Context
62         // HandleConn processes the Conn stats.
63         HandleConn(context.Context, ConnStats)
64 }