handlers.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. *
  3. * Copyright 2016, Google Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. package stats
  34. import (
  35. "net"
  36. "golang.org/x/net/context"
  37. )
  38. // ConnTagInfo defines the relevant information needed by connection context tagger.
  39. type ConnTagInfo struct {
  40. // RemoteAddr is the remote address of the corresponding connection.
  41. RemoteAddr net.Addr
  42. // LocalAddr is the local address of the corresponding connection.
  43. LocalAddr net.Addr
  44. // TODO add QOS related fields.
  45. }
  46. // RPCTagInfo defines the relevant information needed by RPC context tagger.
  47. type RPCTagInfo struct {
  48. // FullMethodName is the RPC method in the format of /package.service/method.
  49. FullMethodName string
  50. }
  51. // Handler defines the interface for the related stats handling (e.g., RPCs, connections).
  52. type Handler interface {
  53. // TagRPC can attach some information to the given context.
  54. // The returned context is used in the rest lifetime of the RPC.
  55. TagRPC(context.Context, *RPCTagInfo) context.Context
  56. // HandleRPC processes the RPC stats.
  57. HandleRPC(context.Context, RPCStats)
  58. // TagConn can attach some information to the given context.
  59. // The returned context will be used for stats handling.
  60. // For conn stats handling, the context used in HandleConn for this
  61. // connection will be derived from the context returned.
  62. // For RPC stats handling,
  63. // - On server side, the context used in HandleRPC for all RPCs on this
  64. // connection will be derived from the context returned.
  65. // - On client side, the context is not derived from the context returned.
  66. TagConn(context.Context, *ConnTagInfo) context.Context
  67. // HandleConn processes the Conn stats.
  68. HandleConn(context.Context, ConnStats)
  69. }