create tapper modes for debugging using env vars

This commit is contained in:
David Levanon 2022-05-15 14:42:21 +03:00
parent f6f06b4b27
commit 7515d18f88
7 changed files with 28 additions and 8 deletions

View File

@ -292,9 +292,12 @@ func pipeTapChannelToSocket(connection *websocket.Conn, messageDataChannel <-cha
continue continue
} }
if os.Getenv("MIZU_TAPPER_NO_SENDING") == "true" {
continue
}
// NOTE: This is where the `*tapApi.OutputChannelItem` leaves the code // NOTE: This is where the `*tapApi.OutputChannelItem` leaves the code
// and goes into the intermediate WebSocket. // and goes into the intermediate WebSocket.
// (DEBUG_PERF 7) Comment out to disable writing to WebSocket
err = connection.WriteMessage(websocket.TextMessage, marshaledData) err = connection.WriteMessage(websocket.TextMessage, marshaledData)
if err != nil { if err != nil {
logger.Log.Errorf("error sending message through socket server %v, err: %s, (%v,%+v)", messageData, err, err, err) logger.Log.Errorf("error sending message through socket server %v, err: %s, (%v,%+v)", messageData, err, err, err)

View File

@ -149,7 +149,10 @@ type Emitter interface {
} }
func (e *Emitting) Emit(item *OutputChannelItem) { func (e *Emitting) Emit(item *OutputChannelItem) {
// (DEBUG_PERF 6) Comment out to disable emitting from tapper to api-server if os.Getenv("MIZU_TAPPER_NO_EMITTER") == "true" {
return
}
e.OutputChannel <- item e.OutputChannel <- item
e.AppStats.IncMatchedPairs() e.AppStats.IncMatchedPairs()
} }

View File

@ -44,7 +44,6 @@ func NewPacketSourceManager(procfs string, filename string, interfaceName string
behaviour: behaviour, behaviour: behaviour,
} }
// (DEBUG_PERF 1) Comment out to disable host pcap (do not pass --tls or --service-mesh)
go hostSource.readPackets(ipdefrag, packets) go hostSource.readPackets(ipdefrag, packets)
return sourceManager, nil return sourceManager, nil
} }

View File

@ -1,6 +1,7 @@
package source package source
import ( import (
"os"
"fmt" "fmt"
"io" "io"
"time" "time"
@ -116,6 +117,10 @@ func (source *tcpPacketSource) close() {
} }
func (source *tcpPacketSource) readPackets(ipdefrag bool, packets chan<- TcpPacketInfo) { func (source *tcpPacketSource) readPackets(ipdefrag bool, packets chan<- TcpPacketInfo) {
if os.Getenv("MIZU_TAPPER_NO_PCAP") == "true" {
return
}
logger.Log.Infof("Start reading packets from %v", source.name) logger.Log.Infof("Start reading packets from %v", source.name)
for { for {

View File

@ -78,7 +78,6 @@ func (a *tcpAssembler) processPackets(dumpPacket bool, packets <-chan source.Tcp
logger.Log.Debugf("Packet content (%d/0x%x) - %s", len(data), len(data), hex.Dump(data)) logger.Log.Debugf("Packet content (%d/0x%x) - %s", len(data), len(data), hex.Dump(data))
} }
// (DEBUG_PERF 2) Comment out to disable assembler
tcp := packet.Layer(layers.LayerTypeTCP) tcp := packet.Layer(layers.LayerTypeTCP)
if tcp != nil { if tcp != nil {
diagnose.AppStats.IncTcpPacketsCount() diagnose.AppStats.IncTcpPacketsCount()
@ -90,7 +89,9 @@ func (a *tcpAssembler) processPackets(dumpPacket bool, packets <-chan source.Tcp
} }
diagnose.InternalStats.Totalsz += len(tcp.Payload) diagnose.InternalStats.Totalsz += len(tcp.Payload)
a.assemblerMutex.Lock() a.assemblerMutex.Lock()
a.AssembleWithContext(packet.NetworkLayer().NetworkFlow(), tcp, &c) if os.Getenv("MIZU_TAPPER_NO_ASSEMBLER") != "true" {
a.AssembleWithContext(packet.NetworkLayer().NetworkFlow(), tcp, &c)
}
a.assemblerMutex.Unlock() a.assemblerMutex.Unlock()
} }

View File

@ -1,6 +1,7 @@
package tap package tap
import ( import (
"os"
"bufio" "bufio"
"io" "io"
"io/ioutil" "io/ioutil"
@ -55,8 +56,12 @@ func NewTcpReader(msgQueue chan api.TcpReaderDataMsg, progress *api.ReadProgress
func (reader *tcpReader) run(options *api.TrafficFilteringOptions, wg *sync.WaitGroup) { func (reader *tcpReader) run(options *api.TrafficFilteringOptions, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
b := bufio.NewReader(reader) b := bufio.NewReader(reader)
// (DEBUG_PERF 4) Swap with next line to disable dissectors
// _, _ = io.ReadAll(b) if os.Getenv("MIZU_TAPPER_NO_DISSECTORS") == "true" {
io.ReadAll(b)
return
}
err := reader.extension.Dissector.Dissect(b, reader, options) err := reader.extension.Dissector.Dissect(b, reader, options)
if err != nil { if err != nil {
_, err = io.Copy(ioutil.Discard, reader) _, err = io.Copy(ioutil.Discard, reader)

View File

@ -1,6 +1,7 @@
package tap package tap
import ( import (
"os"
"sync" "sync"
"time" "time"
@ -132,7 +133,10 @@ func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher {
} }
func (t *tcpStream) GetIsTapTarget() bool { func (t *tcpStream) GetIsTapTarget() bool {
// (DEBUG_PERF 3) Return false to disable Dissecting if os.Getenv("MIZU_TAPPER_NO_TAP_TARGET") == "true" {
return false
}
return t.isTapTarget return t.isTapTarget
} }