handlers.go 2.3 KB

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