l7.go 3.0 KB

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