l7.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package l7
  2. import (
  3. "strconv"
  4. "time"
  5. )
  6. type Protocol uint8
  7. const (
  8. ProtocolTrace Protocol = 200
  9. ProtocolHTTP Protocol = 1
  10. ProtocolPostgres Protocol = 2
  11. ProtocolRedis Protocol = 3
  12. ProtocolMemcached Protocol = 4
  13. ProtocolMysql Protocol = 5
  14. ProtocolMongo Protocol = 6
  15. ProtocolKafka Protocol = 7
  16. ProtocolCassandra Protocol = 8
  17. ProtocolRabbitmq Protocol = 9
  18. ProtocolNats Protocol = 10
  19. ProtocolHTTP2 Protocol = 11
  20. ProtocolDubbo2 Protocol = 12
  21. ProtocolDNS Protocol = 13
  22. ProtocolDM Protocol = 14
  23. )
  24. func (p Protocol) String() string {
  25. switch p {
  26. case ProtocolTrace:
  27. return "TRACE"
  28. case ProtocolHTTP:
  29. return "HTTP"
  30. case ProtocolPostgres:
  31. return "Postgres"
  32. case ProtocolRedis:
  33. return "Redis"
  34. case ProtocolMemcached:
  35. return "Memcached"
  36. case ProtocolMysql:
  37. return "Mysql"
  38. case ProtocolMongo:
  39. return "Mongo"
  40. case ProtocolKafka:
  41. return "Kafka"
  42. case ProtocolCassandra:
  43. return "Cassandra"
  44. case ProtocolRabbitmq:
  45. return "Rabbitmq"
  46. case ProtocolNats:
  47. return "NATS"
  48. case ProtocolHTTP2:
  49. return "HTTP2"
  50. case ProtocolDubbo2:
  51. return "Dubbo2"
  52. case ProtocolDNS:
  53. return "DNS"
  54. case ProtocolDM:
  55. return "DM"
  56. }
  57. return "UNKNOWN:" + strconv.Itoa(int(p))
  58. }
  59. type Method uint8
  60. const (
  61. MethodUnknown Method = 0
  62. MethodProduce Method = 1
  63. MethodConsume Method = 2
  64. MethodStatementPrepare Method = 3
  65. MethodStatementClose Method = 4
  66. MethodHttp2ClientFrames Method = 5
  67. MethodHttp2ServerFrames Method = 6
  68. )
  69. func (m Method) String() string {
  70. switch m {
  71. case MethodUnknown:
  72. return "unknown"
  73. case MethodProduce:
  74. return "produce"
  75. case MethodConsume:
  76. return "consume"
  77. case MethodStatementPrepare:
  78. return "statement_prepare"
  79. case MethodStatementClose:
  80. return "statement_close"
  81. case MethodHttp2ClientFrames:
  82. return "http2_client_frames"
  83. case MethodHttp2ServerFrames:
  84. return "http2_server_frames"
  85. }
  86. return "UNKNOWN:" + strconv.Itoa(int(m))
  87. }
  88. type Status int
  89. const (
  90. StatusUnknown Status = 0
  91. StatusOk Status = 200
  92. StatusFailed Status = 500
  93. )
  94. func (s Status) String() string {
  95. switch s {
  96. case StatusUnknown:
  97. return "unknown"
  98. case StatusOk:
  99. return "ok"
  100. case StatusFailed:
  101. return "failed"
  102. }
  103. return strconv.Itoa(int(s))
  104. }
  105. func (s Status) Http() string {
  106. return strconv.Itoa(int(s))
  107. }
  108. func (s Status) DNS() string {
  109. switch s {
  110. case 0:
  111. return "ok"
  112. case 1:
  113. return "format_error"
  114. case 2:
  115. return "servfail"
  116. case 3:
  117. return "nxdomain"
  118. case 4:
  119. return "not_implemented"
  120. case 5:
  121. return "refused"
  122. }
  123. return ""
  124. }
  125. func (s Status) Error() bool {
  126. return s == StatusFailed
  127. }
  128. type RequestData struct {
  129. Protocol Protocol
  130. Status Status
  131. Duration time.Duration
  132. Method Method
  133. StatementId uint32
  134. Payload []byte
  135. TraceId uint64
  136. TraceStart uint32
  137. TraceEnd uint32
  138. EventCount uint32
  139. AssumedAppId string
  140. SpanId string
  141. StartAt uint64
  142. EndAt uint64
  143. ParentSpanContext struct {
  144. TraceIdFrom string
  145. CalledId string
  146. InstanceIdFrom string
  147. AppIdFrom string
  148. SpanIdFrom string
  149. }
  150. }