mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-11 07:19:58 +00:00
Improve the HTTP request-response counter (still not perfect)
This commit is contained in:
@@ -14,17 +14,27 @@ import (
|
|||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func populateCounterMap(ident string) {
|
||||||
|
if counterMap[ident] == nil {
|
||||||
|
counterMap[ident] = &counterPair{
|
||||||
|
request: 0,
|
||||||
|
response: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func handleHTTP2Stream(grpcAssembler *GrpcAssembler, tcpID *api.TcpID, emitter api.Emitter) error {
|
func handleHTTP2Stream(grpcAssembler *GrpcAssembler, tcpID *api.TcpID, emitter api.Emitter) error {
|
||||||
streamID, messageHTTP1, err := grpcAssembler.readMessage()
|
streamID, messageHTTP1, err := grpcAssembler.readMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
populateCounterMap(tcpID.Ident)
|
||||||
|
|
||||||
var item *api.OutputChannelItem
|
var item *api.OutputChannelItem
|
||||||
|
|
||||||
switch messageHTTP1 := messageHTTP1.(type) {
|
switch messageHTTP1 := messageHTTP1.(type) {
|
||||||
case http.Request:
|
case http.Request:
|
||||||
requestCounter++
|
counterMap[tcpID.Ident].request++
|
||||||
ident := fmt.Sprintf(
|
ident := fmt.Sprintf(
|
||||||
"%s->%s %s->%s %d",
|
"%s->%s %s->%s %d",
|
||||||
tcpID.SrcIP,
|
tcpID.SrcIP,
|
||||||
@@ -44,7 +54,7 @@ func handleHTTP2Stream(grpcAssembler *GrpcAssembler, tcpID *api.TcpID, emitter a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case http.Response:
|
case http.Response:
|
||||||
responseCounter++
|
counterMap[tcpID.Ident].response++
|
||||||
ident := fmt.Sprintf(
|
ident := fmt.Sprintf(
|
||||||
"%s->%s %s->%s %d",
|
"%s->%s %s->%s %d",
|
||||||
tcpID.DstIP,
|
tcpID.DstIP,
|
||||||
@@ -74,13 +84,13 @@ func handleHTTP2Stream(grpcAssembler *GrpcAssembler, tcpID *api.TcpID, emitter a
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleHTTP1ClientStream(b *bufio.Reader, tcpID *api.TcpID, emitter api.Emitter) error {
|
func handleHTTP1ClientStream(b *bufio.Reader, tcpID *api.TcpID, emitter api.Emitter) error {
|
||||||
requestCounter++
|
|
||||||
req, err := http.ReadRequest(b)
|
req, err := http.ReadRequest(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
requestCounter--
|
|
||||||
// log.Println("Error reading stream:", err)
|
// log.Println("Error reading stream:", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
populateCounterMap(tcpID.Ident)
|
||||||
|
counterMap[tcpID.Ident].request++
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.Body)
|
body, err := ioutil.ReadAll(req.Body)
|
||||||
req.Body = io.NopCloser(bytes.NewBuffer(body)) // rewind
|
req.Body = io.NopCloser(bytes.NewBuffer(body)) // rewind
|
||||||
@@ -100,7 +110,7 @@ func handleHTTP1ClientStream(b *bufio.Reader, tcpID *api.TcpID, emitter api.Emit
|
|||||||
tcpID.DstIP,
|
tcpID.DstIP,
|
||||||
tcpID.SrcPort,
|
tcpID.SrcPort,
|
||||||
tcpID.DstPort,
|
tcpID.DstPort,
|
||||||
requestCounter,
|
counterMap[tcpID.Ident].request,
|
||||||
)
|
)
|
||||||
item := reqResMatcher.registerRequest(ident, req, time.Now())
|
item := reqResMatcher.registerRequest(ident, req, time.Now())
|
||||||
if item != nil {
|
if item != nil {
|
||||||
@@ -117,13 +127,13 @@ func handleHTTP1ClientStream(b *bufio.Reader, tcpID *api.TcpID, emitter api.Emit
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleHTTP1ServerStream(b *bufio.Reader, tcpID *api.TcpID, emitter api.Emitter) error {
|
func handleHTTP1ServerStream(b *bufio.Reader, tcpID *api.TcpID, emitter api.Emitter) error {
|
||||||
responseCounter++
|
|
||||||
res, err := http.ReadResponse(b, nil)
|
res, err := http.ReadResponse(b, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responseCounter--
|
|
||||||
// log.Println("Error reading stream:", err)
|
// log.Println("Error reading stream:", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
populateCounterMap(tcpID.Ident)
|
||||||
|
counterMap[tcpID.Ident].response++
|
||||||
var req string
|
var req string
|
||||||
req = fmt.Sprintf("<no-request-seen>")
|
req = fmt.Sprintf("<no-request-seen>")
|
||||||
|
|
||||||
@@ -153,7 +163,7 @@ func handleHTTP1ServerStream(b *bufio.Reader, tcpID *api.TcpID, emitter api.Emit
|
|||||||
tcpID.SrcIP,
|
tcpID.SrcIP,
|
||||||
tcpID.DstPort,
|
tcpID.DstPort,
|
||||||
tcpID.SrcPort,
|
tcpID.SrcPort,
|
||||||
responseCounter,
|
counterMap[tcpID.Ident].response,
|
||||||
)
|
)
|
||||||
item := reqResMatcher.registerResponse(ident, res, time.Now())
|
item := reqResMatcher.registerResponse(ident, res, time.Now())
|
||||||
if item != nil {
|
if item != nil {
|
||||||
|
@@ -12,8 +12,12 @@ import (
|
|||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
var requestCounter uint
|
type counterPair struct {
|
||||||
var responseCounter uint
|
request uint
|
||||||
|
response uint
|
||||||
|
}
|
||||||
|
|
||||||
|
var counterMap map[string]*counterPair
|
||||||
|
|
||||||
var protocol api.Protocol = api.Protocol{
|
var protocol api.Protocol = api.Protocol{
|
||||||
Name: "http",
|
Name: "http",
|
||||||
@@ -48,8 +52,7 @@ const (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.Println("Initializing HTTP extension.")
|
log.Println("Initializing HTTP extension.")
|
||||||
requestCounter = 0
|
counterMap = make(map[string]*counterPair)
|
||||||
responseCounter = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type dissecting string
|
type dissecting string
|
||||||
|
Reference in New Issue
Block a user