| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- package l7
- import (
- "inet.af/netaddr"
- "strconv"
- "time"
- )
- type Protocol uint8
- const (
- ProtocolTrace Protocol = 200
- ProtocolHTTP Protocol = 1
- ProtocolPostgres Protocol = 2
- ProtocolRedis Protocol = 3
- ProtocolMemcached Protocol = 4
- ProtocolMysql Protocol = 5
- ProtocolMongo Protocol = 6
- ProtocolKafka Protocol = 7
- ProtocolCassandra Protocol = 8
- ProtocolRabbitmq Protocol = 9
- ProtocolNats Protocol = 10
- ProtocolHTTP2 Protocol = 11
- ProtocolDubbo2 Protocol = 12
- ProtocolDNS Protocol = 13
- ProtocolDM Protocol = 14
- )
- func (p Protocol) Int() int {
- return int(p)
- }
- func (p Protocol) String() string {
- switch p {
- case ProtocolTrace:
- return "TRACE"
- case ProtocolHTTP:
- return "HTTP"
- case ProtocolPostgres:
- return "Postgres"
- case ProtocolRedis:
- return "Redis"
- case ProtocolMemcached:
- return "Memcached"
- case ProtocolMysql:
- return "Mysql"
- case ProtocolMongo:
- return "Mongo"
- case ProtocolKafka:
- return "Kafka"
- case ProtocolCassandra:
- return "Cassandra"
- case ProtocolRabbitmq:
- return "Rabbitmq"
- case ProtocolNats:
- return "NATS"
- case ProtocolHTTP2:
- return "HTTP2"
- case ProtocolDubbo2:
- return "Dubbo2"
- case ProtocolDNS:
- return "DNS"
- case ProtocolDM:
- return "DM"
- }
- return "UNKNOWN:" + strconv.Itoa(int(p))
- }
- func (p Protocol) ServiceNameString() string {
- switch p {
- case ProtocolTrace:
- return "TRACE"
- case ProtocolHTTP:
- return "HTTP"
- case ProtocolPostgres:
- return "POSTGRESQL"
- case ProtocolRedis:
- return "REDIS"
- case ProtocolMemcached:
- return "Memcached"
- case ProtocolMysql:
- return "MYSQL"
- case ProtocolMongo:
- return "Mongo"
- case ProtocolKafka:
- return "Kafka"
- case ProtocolCassandra:
- return "Cassandra"
- case ProtocolRabbitmq:
- return "Rabbitmq"
- case ProtocolNats:
- return "NATS"
- case ProtocolHTTP2:
- return "HTTP2"
- case ProtocolDubbo2:
- return "Dubbo2"
- case ProtocolDNS:
- return "DNS"
- case ProtocolDM:
- return "DM"
- }
- return "UNKNOWN:" + strconv.Itoa(int(p))
- }
- type Method uint8
- const (
- MethodUnknown Method = 0
- MethodProduce Method = 1
- MethodConsume Method = 2
- MethodStatementPrepare Method = 3
- MethodStatementClose Method = 4
- MethodHttp2ClientFrames Method = 5
- MethodHttp2ServerFrames Method = 6
- )
- func (m Method) String() string {
- switch m {
- case MethodUnknown:
- return "unknown"
- case MethodProduce:
- return "produce"
- case MethodConsume:
- return "consume"
- case MethodStatementPrepare:
- return "statement_prepare"
- case MethodStatementClose:
- return "statement_close"
- case MethodHttp2ClientFrames:
- return "http2_client_frames"
- case MethodHttp2ServerFrames:
- return "http2_server_frames"
- }
- return "UNKNOWN:" + strconv.Itoa(int(m))
- }
- type Status int
- const (
- StatusUnknown Status = 0
- StatusOk Status = 200
- StatusFailed Status = 500
- )
- func (s Status) String() string {
- switch s {
- case StatusUnknown:
- return "unknown"
- case StatusOk:
- return "ok"
- case StatusFailed:
- return "failed"
- }
- return strconv.Itoa(int(s))
- }
- func (s Status) Http() string {
- return strconv.Itoa(int(s))
- }
- func (s Status) DNS() string {
- switch s {
- case 0:
- return "ok"
- case 1:
- return "format_error"
- case 2:
- return "servfail"
- case 3:
- return "nxdomain"
- case 4:
- return "not_implemented"
- case 5:
- return "refused"
- }
- return ""
- }
- func (s Status) Error() bool {
- return s == StatusFailed
- }
- type RequestData struct {
- Protocol Protocol
- Status Status
- Duration time.Duration
- Method Method
- StatementId uint32
- Payload []byte
- TraceId uint64
- TraceStart uint32
- TraceEnd uint32
- EventCount uint32
- AssumedAppId string
- SpanId string
- StartAt uint64
- EndAt uint64
- SAddr netaddr.IPPort
- DAddr netaddr.IPPort
- ComponentSAddr netaddr.IPPort
- ComponentDAddr netaddr.IPPort
- ParentSpanContext struct {
- TraceIdFrom string
- CalledId string
- InstanceIdFrom string
- AppIdFrom string
- SpanIdFrom string
- }
- }
|