Compare commits

...

7 Commits

Author SHA1 Message Date
M. Mert Yıldıran
fc194354bc Fix a nil pointer dereference error that occurs in tcpReader's Read method (#1090)
* Fix a `nil pointer dereference` error that occurs in `tcpReader`'s `Read` method

* #run_acceptance_tests

* #run_acceptance_tests

* Revert "Fix a `nil pointer dereference` error that occurs in `tcpReader`'s `Read` method"

This reverts commit ccef6cb393.

* Fix the race condition using locks #run_acceptance_tests
2022-05-17 13:13:50 +03:00
M. Mert Yıldıran
8418802c7e Handle the wait for fetch in acceptance tests better (#1088)
* Handle the wait for fetch in acceptance tests better

* #run_acceptance_tests

* Fix the error #run_acceptance_tests

* Fix `waitForFetchAndPause` and `checkFilter` #run_acceptance_tests

* Fix the tests #run_acceptance_tests
2022-05-17 11:01:47 +03:00
M. Mert Yıldıran
bfa834e840 Spawn only two Goroutines per TCP stream (#1062)
* Spawn only two Goroutines per TCP stream

* Fix the linter error

* Use `isProtocolIdentified` method instead

* Fix the `Read` method of `tcpReader`

* Remove unnecessary `append`

* Copy to buffer only a message is received

* Remove `exhaustBuffer` field and add `rewind` function

* Rename `buffer` field to `pastData`

* Update tap/tcp_reader.go

Co-authored-by: Nimrod Gilboa Markevich <59927337+nimrod-up9@users.noreply.github.com>

* Use `copy` instead of assignment

* No lint

* #run_acceptance_tests

* Fix `rewind` #run_acceptance_tests

* Fix the buffering algorithm #run_acceptance_tests

* Add `TODO`

* Fix the problems in AMQP and Kafka #run_acceptance_tests

* Use `*bytes.Buffer` instead of `[]api.TcpReaderDataMsg` #run_acceptance_tests

* Have a single `*bytes.Buffer`

* Revert "Have a single `*bytes.Buffer`"

This reverts commit fad96a288a.

* Revert "Use `*bytes.Buffer` instead of `[]api.TcpReaderDataMsg` #run_acceptance_tests"

This reverts commit 0fc70bffe2.

* Fix the early timing out issue #run_acceptance_tests

* Remove `NewBytes()` method

* Update the `NewTcpReader` method signature #run_acceptance_tests

* #run_acceptance_tests

* #run_acceptance_tests

* #run_acceptance_tests

Co-authored-by: Nimrod Gilboa Markevich <59927337+nimrod-up9@users.noreply.github.com>
2022-05-16 16:06:36 +03:00
David Levanon
5c012641a5 Feature/limit fd to address map (#1078)
* limit fd to address map

* limit fd to address map

Co-authored-by: gadotroee <55343099+gadotroee@users.noreply.github.com>
2022-05-16 12:32:26 +03:00
Igor Gov
74bd4b180f Removing elastic dump experimental feature (#1086)
* Removing elastic dump experimental feature
2022-05-15 15:23:03 +03:00
RoyUP9
8ea2dabb34 Added send to socket error validation (#1085) 2022-05-15 14:44:48 +03:00
leon-up9
366d34b8d0 Ui/fix/selectList-sticky-header-fix (#1084)
* selectList sticky header

* selectList changed & servicemap adapted

* ignore eslint

Co-authored-by: Leon <>
Co-authored-by: AmitUp9 <96980485+AmitUp9@users.noreply.github.com>
2022-05-15 14:39:09 +03:00
38 changed files with 350 additions and 495 deletions

View File

@@ -193,58 +193,60 @@ function checkFilter(filterDetails) {
const entriesForDeeperCheck = 5; const entriesForDeeperCheck = 5;
it(`checking the filter: ${filter}`, function () { it(`checking the filter: ${filter}`, function () {
waitForFetch50AndPause(); waitForFetch();
cy.get('#total-entries').should('not.have.text', '0').then(number => { cy.get(`#list [id^=entry]`).last().then(elem => {
const totalEntries = number.text(); const element = elem[0];
const entryId = getEntryId(element.id);
// checks the hover on the last entry (the only one in DOM at the beginning)
leftOnHoverCheck(entryId, leftSidePath, filter);
cy.get(`#list [id^=entry]`).last().then(elem => { cy.get('.w-tc-editor-text').clear();
const element = elem[0]; // applying the filter with alt+enter or with the button
const entryId = getEntryId(element.id); cy.get('.w-tc-editor-text').type(`${filter}${applyByCtrlEnter ? '{ctrl+enter}' : ''}`);
// checks the hover on the last entry (the only one in DOM at the beginning) cy.get('.w-tc-editor').should('have.attr', 'style').and('include', Cypress.env('greenFilterColor'));
leftOnHoverCheck(entryId, leftSidePath, filter); if (!applyByCtrlEnter)
cy.get('[type="submit"]').click();
cy.get('.w-tc-editor-text').clear(); waitForFetch();
// applying the filter with alt+enter or with the button pauseStream();
cy.get('.w-tc-editor-text').type(`${filter}${applyByCtrlEnter ? '{ctrl+enter}' : ''}`);
cy.get('.w-tc-editor').should('have.attr', 'style').and('include', Cypress.env('greenFilterColor'));
if (!applyByCtrlEnter)
cy.get('[type="submit"]').click();
waitForFetch50AndPause(); // only one entry in DOM after filtering, checking all checks on it
leftTextCheck(entryId, leftSidePath, leftSideExpectedText);
leftOnHoverCheck(entryId, leftSidePath, filter);
// only one entry in DOM after filtering, checking all checks on it rightTextCheck(rightSidePath, rightSideExpectedText);
leftTextCheck(entryId, leftSidePath, leftSideExpectedText); rightOnHoverCheck(rightSidePath, filter);
leftOnHoverCheck(entryId, leftSidePath, filter); checkRightSideResponseBody();
});
rightTextCheck(rightSidePath, rightSideExpectedText); resizeToHugeMizu();
rightOnHoverCheck(rightSidePath, filter);
checkRightSideResponseBody();
});
resizeToHugeMizu(); // checking only 'leftTextCheck' on all entries because the rest of the checks require more time
cy.get(`#list [id^=entry]`).each(elem => {
const element = elem[0];
let entryId = getEntryId(element.id);
leftTextCheck(entryId, leftSidePath, leftSideExpectedText);
});
// checking only 'leftTextCheck' on all entries because the rest of the checks require more time // making the other 3 checks on the first X entries (longer time for each check)
cy.get(`#list [id^=entry]`).each(elem => { deeperCheck(leftSidePath, rightSidePath, filter, rightSideExpectedText, entriesForDeeperCheck);
const element = elem[0];
let entryId = getEntryId(element.id);
leftTextCheck(entryId, leftSidePath, leftSideExpectedText);
});
// making the other 3 checks on the first X entries (longer time for each check) // reloading then waiting for the entries number to load
deeperCheck(leftSidePath, rightSidePath, filter, rightSideExpectedText, entriesForDeeperCheck); resizeToNormalMizu();
cy.reload();
// reloading then waiting for the entries number to load waitForFetch();
resizeToNormalMizu(); pauseStream();
cy.reload();
cy.get('#total-entries', {timeout: refreshWaitTimeout}).should('have.text', totalEntries);
})
}); });
} }
function waitForFetch50AndPause() { function waitForFetch() {
// wait half a second and pause the stream to preserve the DOM cy.get('#entries-length', {timeout: refreshWaitTimeout}).should((el) => {
cy.wait(500); expect(parseInt(el.text().trim(), 10)).to.be.greaterThan(20);
});
}
function pauseStream() {
cy.get('#pause-icon').click(); cy.get('#pause-icon').click();
cy.get('#pause-icon').should('not.be.visible'); cy.get('#pause-icon').should('not.be.visible');
} }

View File

@@ -6,7 +6,6 @@ require (
github.com/antelman107/net-wait-go v0.0.0-20210623112055-cf684aebda7b github.com/antelman107/net-wait-go v0.0.0-20210623112055-cf684aebda7b
github.com/chanced/openapi v0.0.8 github.com/chanced/openapi v0.0.8
github.com/djherbis/atime v1.1.0 github.com/djherbis/atime v1.1.0
github.com/elastic/go-elasticsearch/v7 v7.17.0
github.com/getkin/kin-openapi v0.89.0 github.com/getkin/kin-openapi v0.89.0
github.com/gin-contrib/static v0.0.1 github.com/gin-contrib/static v0.0.1
github.com/gin-gonic/gin v1.7.7 github.com/gin-gonic/gin v1.7.7

View File

@@ -166,8 +166,6 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8/yCZMuEPMUDHG0CW/brkkEp8mzqk2+ODEitlw= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8/yCZMuEPMUDHG0CW/brkkEp8mzqk2+ODEitlw=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/elastic/go-elasticsearch/v7 v7.17.0 h1:0fcSh4qeC/i1+7QU1KXpmq2iUAdMk4l0/vmbtW1+KJM=
github.com/elastic/go-elasticsearch/v7 v7.17.0/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc=
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=

View File

@@ -17,7 +17,6 @@ import (
"github.com/gin-contrib/static" "github.com/gin-contrib/static"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/up9inc/mizu/agent/pkg/dependency" "github.com/up9inc/mizu/agent/pkg/dependency"
"github.com/up9inc/mizu/agent/pkg/elastic"
"github.com/up9inc/mizu/agent/pkg/entries" "github.com/up9inc/mizu/agent/pkg/entries"
"github.com/up9inc/mizu/agent/pkg/middlewares" "github.com/up9inc/mizu/agent/pkg/middlewares"
"github.com/up9inc/mizu/agent/pkg/models" "github.com/up9inc/mizu/agent/pkg/models"
@@ -205,7 +204,6 @@ func enableExpFeatureIfNeeded() {
serviceMapGenerator := dependency.GetInstance(dependency.ServiceMapGeneratorDependency).(servicemap.ServiceMap) serviceMapGenerator := dependency.GetInstance(dependency.ServiceMapGeneratorDependency).(servicemap.ServiceMap)
serviceMapGenerator.Enable() serviceMapGenerator.Enable()
} }
elastic.GetInstance().Configure(config.Config.Elastic)
} }
func getSyncEntriesConfig() *shared.SyncEntriesConfig { func getSyncEntriesConfig() *shared.SyncEntriesConfig {

View File

@@ -5,20 +5,19 @@ import (
basenine "github.com/up9inc/basenine/client/go" basenine "github.com/up9inc/basenine/client/go"
"github.com/up9inc/mizu/agent/pkg/models" "github.com/up9inc/mizu/agent/pkg/models"
"github.com/up9inc/mizu/logger"
tapApi "github.com/up9inc/mizu/tap/api" tapApi "github.com/up9inc/mizu/tap/api"
) )
type EntryStreamerSocketConnector interface { type EntryStreamerSocketConnector interface {
SendEntry(socketId int, entry *tapApi.Entry, params *WebSocketParams) SendEntry(socketId int, entry *tapApi.Entry, params *WebSocketParams) error
SendMetadata(socketId int, metadata *basenine.Metadata) SendMetadata(socketId int, metadata *basenine.Metadata) error
SendToastError(socketId int, err error) SendToastError(socketId int, err error) error
CleanupSocket(socketId int) CleanupSocket(socketId int)
} }
type DefaultEntryStreamerSocketConnector struct{} type DefaultEntryStreamerSocketConnector struct{}
func (e *DefaultEntryStreamerSocketConnector) SendEntry(socketId int, entry *tapApi.Entry, params *WebSocketParams) { func (e *DefaultEntryStreamerSocketConnector) SendEntry(socketId int, entry *tapApi.Entry, params *WebSocketParams) error {
var message []byte var message []byte
if params.EnableFullEntries { if params.EnableFullEntries {
message, _ = models.CreateFullEntryWebSocketMessage(entry) message, _ = models.CreateFullEntryWebSocketMessage(entry)
@@ -29,26 +28,32 @@ func (e *DefaultEntryStreamerSocketConnector) SendEntry(socketId int, entry *tap
} }
if err := SendToSocket(socketId, message); err != nil { if err := SendToSocket(socketId, message); err != nil {
logger.Log.Error(err) return err
} }
return nil
} }
func (e *DefaultEntryStreamerSocketConnector) SendMetadata(socketId int, metadata *basenine.Metadata) { func (e *DefaultEntryStreamerSocketConnector) SendMetadata(socketId int, metadata *basenine.Metadata) error {
metadataBytes, _ := models.CreateWebsocketQueryMetadataMessage(metadata) metadataBytes, _ := models.CreateWebsocketQueryMetadataMessage(metadata)
if err := SendToSocket(socketId, metadataBytes); err != nil { if err := SendToSocket(socketId, metadataBytes); err != nil {
logger.Log.Error(err) return err
} }
return nil
} }
func (e *DefaultEntryStreamerSocketConnector) SendToastError(socketId int, err error) { func (e *DefaultEntryStreamerSocketConnector) SendToastError(socketId int, err error) error {
toastBytes, _ := models.CreateWebsocketToastMessage(&models.ToastMessage{ toastBytes, _ := models.CreateWebsocketToastMessage(&models.ToastMessage{
Type: "error", Type: "error",
AutoClose: 5000, AutoClose: 5000,
Text: fmt.Sprintf("Syntax error: %s", err.Error()), Text: fmt.Sprintf("Syntax error: %s", err.Error()),
}) })
if err := SendToSocket(socketId, toastBytes); err != nil { if err := SendToSocket(socketId, toastBytes); err != nil {
logger.Log.Error(err) return err
} }
return nil
} }
func (e *DefaultEntryStreamerSocketConnector) CleanupSocket(socketId int) { func (e *DefaultEntryStreamerSocketConnector) CleanupSocket(socketId int) {

View File

@@ -14,7 +14,6 @@ import (
"github.com/up9inc/mizu/agent/pkg/models" "github.com/up9inc/mizu/agent/pkg/models"
"github.com/up9inc/mizu/agent/pkg/dependency" "github.com/up9inc/mizu/agent/pkg/dependency"
"github.com/up9inc/mizu/agent/pkg/elastic"
"github.com/up9inc/mizu/agent/pkg/har" "github.com/up9inc/mizu/agent/pkg/har"
"github.com/up9inc/mizu/agent/pkg/holder" "github.com/up9inc/mizu/agent/pkg/holder"
"github.com/up9inc/mizu/agent/pkg/providers" "github.com/up9inc/mizu/agent/pkg/providers"
@@ -153,8 +152,6 @@ func startReadingChannel(outputItems <-chan *tapApi.OutputChannelItem, extension
serviceMapGenerator := dependency.GetInstance(dependency.ServiceMapGeneratorDependency).(servicemap.ServiceMapSink) serviceMapGenerator := dependency.GetInstance(dependency.ServiceMapGeneratorDependency).(servicemap.ServiceMapSink)
serviceMapGenerator.NewTCPEntry(mizuEntry.Source, mizuEntry.Destination, &item.Protocol) serviceMapGenerator.NewTCPEntry(mizuEntry.Source, mizuEntry.Destination, &item.Protocol)
elastic.GetInstance().PushEntry(mizuEntry)
} }
} }

View File

@@ -34,14 +34,18 @@ func (e *BasenineEntryStreamer) Get(ctx context.Context, socketId int, params *W
meta := make(chan []byte) meta := make(chan []byte)
query := params.Query query := params.Query
err = basenine.Validate(shared.BasenineHost, shared.BaseninePort, query) if err = basenine.Validate(shared.BasenineHost, shared.BaseninePort, query); err != nil {
if err != nil { if err := entryStreamerSocketConnector.SendToastError(socketId, err); err != nil {
entryStreamerSocketConnector.SendToastError(socketId, err) return err
}
entryStreamerSocketConnector.CleanupSocket(socketId)
return err
} }
leftOff, err := e.fetch(socketId, params, entryStreamerSocketConnector) leftOff, err := e.fetch(socketId, params, entryStreamerSocketConnector)
if err != nil { if err != nil {
logger.Log.Errorf("Fetch error: %v", err.Error()) logger.Log.Errorf("Fetch error: %v", err)
} }
handleDataChannel := func(c *basenine.Connection, data chan []byte) { handleDataChannel := func(c *basenine.Connection, data chan []byte) {
@@ -53,13 +57,15 @@ func (e *BasenineEntryStreamer) Get(ctx context.Context, socketId int, params *W
} }
var entry *tapApi.Entry var entry *tapApi.Entry
err = json.Unmarshal(bytes, &entry) if err = json.Unmarshal(bytes, &entry); err != nil {
if err != nil { logger.Log.Debugf("Error unmarshalling entry: %v", err)
logger.Log.Debugf("Error unmarshalling entry: %v", err.Error())
continue continue
} }
entryStreamerSocketConnector.SendEntry(socketId, entry, params) if err := entryStreamerSocketConnector.SendEntry(socketId, entry, params); err != nil {
logger.Log.Errorf("Error sending entry to socket, err: %v", err)
return
}
} }
} }
@@ -72,13 +78,15 @@ func (e *BasenineEntryStreamer) Get(ctx context.Context, socketId int, params *W
} }
var metadata *basenine.Metadata var metadata *basenine.Metadata
err = json.Unmarshal(bytes, &metadata) if err = json.Unmarshal(bytes, &metadata); err != nil {
if err != nil { logger.Log.Debugf("Error unmarshalling metadata: %v", err)
logger.Log.Debugf("Error unmarshalling metadata: %v", err.Error())
continue continue
} }
entryStreamerSocketConnector.SendMetadata(socketId, metadata) if err := entryStreamerSocketConnector.SendMetadata(socketId, metadata); err != nil {
logger.Log.Errorf("Error sending metadata to socket, err: %v", err)
return
}
} }
} }
@@ -125,28 +133,31 @@ func (e *BasenineEntryStreamer) fetch(socketId int, params *WebSocketParams, con
} }
var firstMetadata *basenine.Metadata var firstMetadata *basenine.Metadata
err = json.Unmarshal(firstMeta, &firstMetadata) if err = json.Unmarshal(firstMeta, &firstMetadata); err != nil {
if err != nil {
return return
} }
leftOff = firstMetadata.LeftOff leftOff = firstMetadata.LeftOff
var lastMetadata *basenine.Metadata var lastMetadata *basenine.Metadata
err = json.Unmarshal(lastMeta, &lastMetadata) if err = json.Unmarshal(lastMeta, &lastMetadata); err != nil {
if err != nil { return
}
if err = connector.SendMetadata(socketId, lastMetadata); err != nil {
return return
} }
connector.SendMetadata(socketId, lastMetadata)
data = e.reverseBytesSlice(data) data = e.reverseBytesSlice(data)
for _, row := range data { for _, row := range data {
var entry *tapApi.Entry var entry *tapApi.Entry
err = json.Unmarshal(row, &entry) if err = json.Unmarshal(row, &entry); err != nil {
if err != nil {
break break
} }
connector.SendEntry(socketId, entry, params) if err = connector.SendEntry(socketId, entry, params); err != nil {
return
}
} }
return return
} }

View File

@@ -1,116 +0,0 @@
package elastic
import (
"bytes"
"crypto/tls"
"encoding/json"
"net/http"
"sync"
"time"
"github.com/elastic/go-elasticsearch/v7"
"github.com/up9inc/mizu/logger"
"github.com/up9inc/mizu/shared"
"github.com/up9inc/mizu/tap/api"
)
type client struct {
es *elasticsearch.Client
index string
insertedCount int
}
var instance *client
var once sync.Once
func GetInstance() *client {
once.Do(func() {
instance = newClient()
})
return instance
}
func (client *client) Configure(config shared.ElasticConfig) {
if config.Url == "" || config.User == "" || config.Password == "" {
if client.es != nil {
client.es = nil
}
logger.Log.Infof("No elastic configuration was supplied, elastic exporter disabled")
return
}
transport := http.DefaultTransport
tlsClientConfig := &tls.Config{InsecureSkipVerify: true}
transport.(*http.Transport).TLSClientConfig = tlsClientConfig
cfg := elasticsearch.Config{
Addresses: []string{config.Url},
Username: config.User,
Password: config.Password,
Transport: transport,
}
es, err := elasticsearch.NewClient(cfg)
if err != nil {
logger.Log.Errorf("Failed to initialize elastic client %v", err)
}
// Have the client instance return a response
res, err := es.Info()
if err != nil {
logger.Log.Errorf("Elastic client.Info() ERROR: %v", err)
} else {
client.es = es
client.index = "mizu_traffic_http_" + time.Now().Format("2006_01_02_15_04")
client.insertedCount = 0
logger.Log.Infof("Elastic client configured, index: %s, cluster info: %v", client.index, res)
}
defer res.Body.Close()
}
func newClient() *client {
return &client{
es: nil,
index: "",
}
}
type httpEntry struct {
Source *api.TCP `json:"src"`
Destination *api.TCP `json:"dst"`
Outgoing bool `json:"outgoing"`
CreatedAt time.Time `json:"createdAt"`
Request map[string]interface{} `json:"request"`
Response map[string]interface{} `json:"response"`
ElapsedTime int64 `json:"elapsedTime"`
}
func (client *client) PushEntry(entry *api.Entry) {
if client.es == nil {
return
}
if entry.Protocol.Name != "http" {
return
}
entryToPush := httpEntry{
Source: entry.Source,
Destination: entry.Destination,
Outgoing: entry.Outgoing,
CreatedAt: entry.StartTime,
Request: entry.Request,
Response: entry.Response,
ElapsedTime: entry.ElapsedTime,
}
entryJson, err := json.Marshal(entryToPush)
if err != nil {
logger.Log.Errorf("json.Marshal ERROR: %v", err)
return
}
var buffer bytes.Buffer
buffer.WriteString(string(entryJson))
res, _ := client.es.Index(client.index, &buffer)
if res.StatusCode == 201 {
client.insertedCount += 1
}
}

View File

@@ -164,7 +164,6 @@ func getTapMizuAgentConfig() *shared.MizuAgentConfig {
ServiceMap: config.Config.ServiceMap, ServiceMap: config.Config.ServiceMap,
OAS: config.Config.OAS, OAS: config.Config.OAS,
Telemetry: config.Config.Telemetry, Telemetry: config.Config.Telemetry,
Elastic: config.Config.Elastic,
} }
return &mizuAgentConfig return &mizuAgentConfig

View File

@@ -41,7 +41,6 @@ type ConfigStruct struct {
LogLevelStr string `yaml:"log-level,omitempty" default:"INFO" readonly:""` LogLevelStr string `yaml:"log-level,omitempty" default:"INFO" readonly:""`
ServiceMap bool `yaml:"service-map" default:"true"` ServiceMap bool `yaml:"service-map" default:"true"`
OAS bool `yaml:"oas" default:"true"` OAS bool `yaml:"oas" default:"true"`
Elastic shared.ElasticConfig `yaml:"elastic"`
} }
func (config *ConfigStruct) validate() error { func (config *ConfigStruct) validate() error {

View File

@@ -45,13 +45,6 @@ type MizuAgentConfig struct {
ServiceMap bool `json:"serviceMap"` ServiceMap bool `json:"serviceMap"`
OAS bool `json:"oas"` OAS bool `json:"oas"`
Telemetry bool `json:"telemetry"` Telemetry bool `json:"telemetry"`
Elastic ElasticConfig `json:"elastic"`
}
type ElasticConfig struct {
User string `yaml:"user,omitempty" default:"" readonly:""`
Password string `yaml:"password,omitempty" default:"" readonly:""`
Url string `yaml:"url,omitempty" default:"" readonly:""`
} }
type WebSocketMessageMetadata struct { type WebSocketMessageMetadata struct {

View File

@@ -104,11 +104,6 @@ type OutputChannelItem struct {
Namespace string Namespace string
} }
type ProtoIdentifier struct {
Protocol *Protocol
IsClosedOthers bool
}
type ReadProgress struct { type ReadProgress struct {
readBytes int readBytes int
lastCurrent int lastCurrent int
@@ -123,6 +118,11 @@ func (p *ReadProgress) Current() (n int) {
return p.lastCurrent return p.lastCurrent
} }
func (p *ReadProgress) Reset() {
p.readBytes = 0
p.lastCurrent = 0
}
type Dissector interface { type Dissector interface {
Register(*Extension) Register(*Extension)
Ping() Ping()
@@ -419,13 +419,12 @@ type TcpReader interface {
GetCaptureTime() time.Time GetCaptureTime() time.Time
GetEmitter() Emitter GetEmitter() Emitter
GetIsClosed() bool GetIsClosed() bool
GetExtension() *Extension
} }
type TcpStream interface { type TcpStream interface {
SetProtocol(protocol *Protocol) SetProtocol(protocol *Protocol)
GetOrigin() Capture GetOrigin() Capture
GetProtoIdentifier() *ProtoIdentifier GetProtocol() *Protocol
GetReqResMatchers() []RequestResponseMatcher GetReqResMatchers() []RequestResponseMatcher
GetIsTapTarget() bool GetIsTapTarget() bool
GetIsClosed() bool GetIsClosed() bool

View File

@@ -75,14 +75,14 @@ func (d dissecting) Dissect(b *bufio.Reader, reader api.TcpReader, options *api.
var lastMethodFrameMessage Message var lastMethodFrameMessage Message
for { for {
if reader.GetParent().GetProtoIdentifier().Protocol != nil && reader.GetParent().GetProtoIdentifier().Protocol != &protocol { if reader.GetParent().GetProtocol() != nil && reader.GetParent().GetProtocol() != &protocol {
return errors.New("Identified by another protocol") return errors.New("Identified by another protocol")
} }
frame, err := r.ReadFrame() frame, err := r.ReadFrame()
if err == io.EOF { if err == io.EOF {
// We must read until we see an EOF... very important! // We must read until we see an EOF... very important!
return nil return err
} }
switch f := frame.(type) { switch f := frame.(type) {

View File

@@ -78,7 +78,3 @@ func (reader *tcpReader) GetEmitter() api.Emitter {
func (reader *tcpReader) GetIsClosed() bool { func (reader *tcpReader) GetIsClosed() bool {
return reader.isClosed return reader.isClosed
} }
func (reader *tcpReader) GetExtension() *api.Extension {
return reader.extension
}

View File

@@ -7,18 +7,17 @@ import (
) )
type tcpStream struct { type tcpStream struct {
isClosed bool isClosed bool
protoIdentifier *api.ProtoIdentifier protocol *api.Protocol
isTapTarget bool isTapTarget bool
origin api.Capture origin api.Capture
reqResMatchers []api.RequestResponseMatcher reqResMatchers []api.RequestResponseMatcher
sync.Mutex sync.Mutex
} }
func NewTcpStream(capture api.Capture) api.TcpStream { func NewTcpStream(capture api.Capture) api.TcpStream {
return &tcpStream{ return &tcpStream{
origin: capture, origin: capture,
protoIdentifier: &api.ProtoIdentifier{},
} }
} }
@@ -28,8 +27,8 @@ func (t *tcpStream) GetOrigin() api.Capture {
return t.origin return t.origin
} }
func (t *tcpStream) GetProtoIdentifier() *api.ProtoIdentifier { func (t *tcpStream) GetProtocol() *api.Protocol {
return t.protoIdentifier return t.protocol
} }
func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher { func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher {

View File

@@ -144,7 +144,7 @@ func (d dissecting) Dissect(b *bufio.Reader, reader api.TcpReader, options *api.
http2Assembler = createHTTP2Assembler(b) http2Assembler = createHTTP2Assembler(b)
} }
if reader.GetParent().GetProtoIdentifier().Protocol != nil && reader.GetParent().GetProtoIdentifier().Protocol != &http11protocol { if reader.GetParent().GetProtocol() != nil && reader.GetParent().GetProtocol() != &http11protocol {
return errors.New("Identified by another protocol") return errors.New("Identified by another protocol")
} }
@@ -200,7 +200,7 @@ func (d dissecting) Dissect(b *bufio.Reader, reader api.TcpReader, options *api.
} }
} }
if reader.GetParent().GetProtoIdentifier().Protocol == nil { if reader.GetParent().GetProtocol() == nil {
return err return err
} }

View File

@@ -78,7 +78,3 @@ func (reader *tcpReader) GetEmitter() api.Emitter {
func (reader *tcpReader) GetIsClosed() bool { func (reader *tcpReader) GetIsClosed() bool {
return reader.isClosed return reader.isClosed
} }
func (reader *tcpReader) GetExtension() *api.Extension {
return reader.extension
}

View File

@@ -7,18 +7,17 @@ import (
) )
type tcpStream struct { type tcpStream struct {
isClosed bool isClosed bool
protoIdentifier *api.ProtoIdentifier protocol *api.Protocol
isTapTarget bool isTapTarget bool
origin api.Capture origin api.Capture
reqResMatchers []api.RequestResponseMatcher reqResMatchers []api.RequestResponseMatcher
sync.Mutex sync.Mutex
} }
func NewTcpStream(capture api.Capture) api.TcpStream { func NewTcpStream(capture api.Capture) api.TcpStream {
return &tcpStream{ return &tcpStream{
origin: capture, origin: capture,
protoIdentifier: &api.ProtoIdentifier{},
} }
} }
@@ -28,8 +27,8 @@ func (t *tcpStream) GetOrigin() api.Capture {
return t.origin return t.origin
} }
func (t *tcpStream) GetProtoIdentifier() *api.ProtoIdentifier { func (t *tcpStream) GetProtocol() *api.Protocol {
return t.protoIdentifier return t.protocol
} }
func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher { func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher {

View File

@@ -38,7 +38,7 @@ func (d dissecting) Ping() {
func (d dissecting) Dissect(b *bufio.Reader, reader api.TcpReader, options *api.TrafficFilteringOptions) error { func (d dissecting) Dissect(b *bufio.Reader, reader api.TcpReader, options *api.TrafficFilteringOptions) error {
reqResMatcher := reader.GetReqResMatcher().(*requestResponseMatcher) reqResMatcher := reader.GetReqResMatcher().(*requestResponseMatcher)
for { for {
if reader.GetParent().GetProtoIdentifier().Protocol != nil && reader.GetParent().GetProtoIdentifier().Protocol != &_protocol { if reader.GetParent().GetProtocol() != nil && reader.GetParent().GetProtocol() != &_protocol {
return errors.New("Identified by another protocol") return errors.New("Identified by another protocol")
} }

View File

@@ -78,7 +78,3 @@ func (reader *tcpReader) GetEmitter() api.Emitter {
func (reader *tcpReader) GetIsClosed() bool { func (reader *tcpReader) GetIsClosed() bool {
return reader.isClosed return reader.isClosed
} }
func (reader *tcpReader) GetExtension() *api.Extension {
return reader.extension
}

View File

@@ -7,18 +7,17 @@ import (
) )
type tcpStream struct { type tcpStream struct {
isClosed bool isClosed bool
protoIdentifier *api.ProtoIdentifier protocol *api.Protocol
isTapTarget bool isTapTarget bool
origin api.Capture origin api.Capture
reqResMatchers []api.RequestResponseMatcher reqResMatchers []api.RequestResponseMatcher
sync.Mutex sync.Mutex
} }
func NewTcpStream(capture api.Capture) api.TcpStream { func NewTcpStream(capture api.Capture) api.TcpStream {
return &tcpStream{ return &tcpStream{
origin: capture, origin: capture,
protoIdentifier: &api.ProtoIdentifier{},
} }
} }
@@ -28,8 +27,8 @@ func (t *tcpStream) GetOrigin() api.Capture {
return t.origin return t.origin
} }
func (t *tcpStream) GetProtoIdentifier() *api.ProtoIdentifier { func (t *tcpStream) GetProtocol() *api.Protocol {
return t.protoIdentifier return t.protocol
} }
func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher { func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher {

View File

@@ -78,7 +78,3 @@ func (reader *tcpReader) GetEmitter() api.Emitter {
func (reader *tcpReader) GetIsClosed() bool { func (reader *tcpReader) GetIsClosed() bool {
return reader.isClosed return reader.isClosed
} }
func (reader *tcpReader) GetExtension() *api.Extension {
return reader.extension
}

View File

@@ -7,18 +7,17 @@ import (
) )
type tcpStream struct { type tcpStream struct {
isClosed bool isClosed bool
protoIdentifier *api.ProtoIdentifier protocol *api.Protocol
isTapTarget bool isTapTarget bool
origin api.Capture origin api.Capture
reqResMatchers []api.RequestResponseMatcher reqResMatchers []api.RequestResponseMatcher
sync.Mutex sync.Mutex
} }
func NewTcpStream(capture api.Capture) api.TcpStream { func NewTcpStream(capture api.Capture) api.TcpStream {
return &tcpStream{ return &tcpStream{
origin: capture, origin: capture,
protoIdentifier: &api.ProtoIdentifier{},
} }
} }
@@ -28,8 +27,8 @@ func (t *tcpStream) GetOrigin() api.Capture {
return t.origin return t.origin
} }
func (t *tcpStream) GetProtoIdentifier() *api.ProtoIdentifier { func (t *tcpStream) GetProtocol() *api.Protocol {
return t.protoIdentifier return t.protocol
} }
func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher { func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher {

View File

@@ -3,11 +3,9 @@ package tap
import ( import (
"bufio" "bufio"
"io" "io"
"io/ioutil"
"sync" "sync"
"time" "time"
"github.com/up9inc/mizu/logger"
"github.com/up9inc/mizu/tap/api" "github.com/up9inc/mizu/tap/api"
) )
@@ -17,50 +15,48 @@ import (
* Implements io.Reader interface (Read) * Implements io.Reader interface (Read)
*/ */
type tcpReader struct { type tcpReader struct {
ident string ident string
tcpID *api.TcpID tcpID *api.TcpID
isClosed bool isClosed bool
isClient bool isClient bool
isOutgoing bool isOutgoing bool
msgQueue chan api.TcpReaderDataMsg // Channel of captured reassembled tcp payload msgQueue chan api.TcpReaderDataMsg // Channel of captured reassembled tcp payload
data []byte msgBuffer []api.TcpReaderDataMsg
progress *api.ReadProgress msgBufferMaster []api.TcpReaderDataMsg
captureTime time.Time data []byte
parent *tcpStream progress *api.ReadProgress
packetsSeen uint captureTime time.Time
extension *api.Extension parent *tcpStream
emitter api.Emitter emitter api.Emitter
counterPair *api.CounterPair counterPair *api.CounterPair
reqResMatcher api.RequestResponseMatcher reqResMatcher api.RequestResponseMatcher
sync.Mutex sync.Mutex
} }
func NewTcpReader(msgQueue chan api.TcpReaderDataMsg, progress *api.ReadProgress, ident string, tcpId *api.TcpID, captureTime time.Time, parent *tcpStream, isClient bool, isOutgoing bool, extension *api.Extension, emitter api.Emitter, counterPair *api.CounterPair, reqResMatcher api.RequestResponseMatcher) *tcpReader { func NewTcpReader(ident string, tcpId *api.TcpID, parent *tcpStream, isClient bool, isOutgoing bool, emitter api.Emitter) *tcpReader {
return &tcpReader{ return &tcpReader{
msgQueue: msgQueue, msgQueue: make(chan api.TcpReaderDataMsg),
progress: progress, progress: &api.ReadProgress{},
ident: ident, ident: ident,
tcpID: tcpId, tcpID: tcpId,
captureTime: captureTime, parent: parent,
parent: parent, isClient: isClient,
isClient: isClient, isOutgoing: isOutgoing,
isOutgoing: isOutgoing, emitter: emitter,
extension: extension,
emitter: emitter,
counterPair: counterPair,
reqResMatcher: reqResMatcher,
} }
} }
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) for i, extension := range extensions {
err := reader.extension.Dissector.Dissect(b, reader, options) reader.reqResMatcher = reader.parent.reqResMatchers[i]
if err != nil { reader.counterPair = reader.parent.counterPairs[i]
_, err = io.Copy(ioutil.Discard, reader) b := bufio.NewReader(reader)
if err != nil { extension.Dissector.Dissect(b, reader, options) //nolint
logger.Log.Errorf("%v", err) if reader.isProtocolIdentified() {
break
} }
reader.rewind()
} }
} }
@@ -81,21 +77,60 @@ func (reader *tcpReader) sendMsgIfNotClosed(msg api.TcpReaderDataMsg) {
reader.Unlock() reader.Unlock()
} }
func (reader *tcpReader) isProtocolIdentified() bool {
return reader.parent.protocol != nil
}
func (reader *tcpReader) rewind() {
// Reset the data
reader.data = make([]byte, 0)
// Reset msgBuffer from the master record
reader.parent.Lock()
reader.msgBuffer = make([]api.TcpReaderDataMsg, len(reader.msgBufferMaster))
copy(reader.msgBuffer, reader.msgBufferMaster)
reader.parent.Unlock()
// Reset the read progress
reader.progress.Reset()
}
func (reader *tcpReader) populateData(msg api.TcpReaderDataMsg) {
reader.data = msg.GetBytes()
reader.captureTime = msg.GetTimestamp()
}
func (reader *tcpReader) Read(p []byte) (int, error) { func (reader *tcpReader) Read(p []byte) (int, error) {
var msg api.TcpReaderDataMsg var msg api.TcpReaderDataMsg
for len(reader.msgBuffer) > 0 && len(reader.data) == 0 {
// Pop first message
if len(reader.msgBuffer) > 1 {
msg, reader.msgBuffer = reader.msgBuffer[0], reader.msgBuffer[1:]
} else {
msg = reader.msgBuffer[0]
reader.msgBuffer = make([]api.TcpReaderDataMsg, 0)
}
// Get the bytes
reader.populateData(msg)
}
ok := true ok := true
for ok && len(reader.data) == 0 { for ok && len(reader.data) == 0 {
msg, ok = <-reader.msgQueue msg, ok = <-reader.msgQueue
if msg != nil { if msg != nil {
reader.data = msg.GetBytes() reader.populateData(msg)
reader.captureTime = msg.GetTimestamp()
}
if len(reader.data) > 0 { if !reader.isProtocolIdentified() {
reader.packetsSeen += 1 reader.msgBufferMaster = append(
reader.msgBufferMaster,
msg,
)
}
} }
} }
if !ok || len(reader.data) == 0 { if !ok || len(reader.data) == 0 {
return 0, io.EOF return 0, io.EOF
} }
@@ -142,7 +177,3 @@ func (reader *tcpReader) GetEmitter() api.Emitter {
func (reader *tcpReader) GetIsClosed() bool { func (reader *tcpReader) GetIsClosed() bool {
return reader.isClosed return reader.isClosed
} }
func (reader *tcpReader) GetExtension() *api.Extension {
return reader.extension
}

View File

@@ -6,7 +6,6 @@ import (
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/layers" // pulls in all layers decoders "github.com/google/gopacket/layers" // pulls in all layers decoders
"github.com/google/gopacket/reassembly" "github.com/google/gopacket/reassembly"
"github.com/up9inc/mizu/tap/api"
"github.com/up9inc/mizu/tap/diagnose" "github.com/up9inc/mizu/tap/diagnose"
) )
@@ -16,10 +15,10 @@ type tcpReassemblyStream struct {
fsmerr bool fsmerr bool
optchecker reassembly.TCPOptionCheck optchecker reassembly.TCPOptionCheck
isDNS bool isDNS bool
tcpStream api.TcpStream tcpStream *tcpStream
} }
func NewTcpReassemblyStream(ident string, tcp *layers.TCP, fsmOptions reassembly.TCPSimpleFSMOptions, stream api.TcpStream) reassembly.Stream { func NewTcpReassemblyStream(ident string, tcp *layers.TCP, fsmOptions reassembly.TCPSimpleFSMOptions, stream *tcpStream) reassembly.Stream {
return &tcpReassemblyStream{ return &tcpReassemblyStream{
ident: ident, ident: ident,
tcpState: reassembly.NewTCPSimpleFSM(fsmOptions), tcpState: reassembly.NewTCPSimpleFSM(fsmOptions),
@@ -139,17 +138,10 @@ func (t *tcpReassemblyStream) ReassembledSG(sg reassembly.ScatterGather, ac reas
// This channel is read by an tcpReader object // This channel is read by an tcpReader object
diagnose.AppStats.IncReassembledTcpPayloadsCount() diagnose.AppStats.IncReassembledTcpPayloadsCount()
timestamp := ac.GetCaptureInfo().Timestamp timestamp := ac.GetCaptureInfo().Timestamp
stream := t.tcpStream.(*tcpStream)
if dir == reassembly.TCPDirClientToServer { if dir == reassembly.TCPDirClientToServer {
for i := range stream.getClients() { t.tcpStream.client.sendMsgIfNotClosed(NewTcpReaderDataMsg(data, timestamp))
reader := stream.getClient(i)
reader.sendMsgIfNotClosed(NewTcpReaderDataMsg(data, timestamp))
}
} else { } else {
for i := range stream.getServers() { t.tcpStream.server.sendMsgIfNotClosed(NewTcpReaderDataMsg(data, timestamp))
reader := stream.getServer(i)
reader.sendMsgIfNotClosed(NewTcpReaderDataMsg(data, timestamp))
}
} }
} }
} }
@@ -157,7 +149,7 @@ func (t *tcpReassemblyStream) ReassembledSG(sg reassembly.ScatterGather, ac reas
func (t *tcpReassemblyStream) ReassemblyComplete(ac reassembly.AssemblerContext) bool { func (t *tcpReassemblyStream) ReassemblyComplete(ac reassembly.AssemblerContext) bool {
if t.tcpStream.GetIsTapTarget() && !t.tcpStream.GetIsClosed() { if t.tcpStream.GetIsTapTarget() && !t.tcpStream.GetIsClosed() {
t.tcpStream.(*tcpStream).close() t.tcpStream.close()
} }
// do not remove the connection to allow last ACK // do not remove the connection to allow last ACK
return false return false

View File

@@ -13,25 +13,26 @@ import (
* In our implementation, we pass information from ReassembledSG to the TcpReader through a shared channel. * In our implementation, we pass information from ReassembledSG to the TcpReader through a shared channel.
*/ */
type tcpStream struct { type tcpStream struct {
id int64 id int64
isClosed bool isClosed bool
protoIdentifier *api.ProtoIdentifier protocol *api.Protocol
isTapTarget bool isTapTarget bool
clients []*tcpReader client *tcpReader
servers []*tcpReader server *tcpReader
origin api.Capture origin api.Capture
reqResMatchers []api.RequestResponseMatcher counterPairs []*api.CounterPair
createdAt time.Time reqResMatchers []api.RequestResponseMatcher
streamsMap api.TcpStreamMap createdAt time.Time
streamsMap api.TcpStreamMap
sync.Mutex sync.Mutex
} }
func NewTcpStream(isTapTarget bool, streamsMap api.TcpStreamMap, capture api.Capture) *tcpStream { func NewTcpStream(isTapTarget bool, streamsMap api.TcpStreamMap, capture api.Capture) *tcpStream {
return &tcpStream{ return &tcpStream{
isTapTarget: isTapTarget, isTapTarget: isTapTarget,
protoIdentifier: &api.ProtoIdentifier{}, streamsMap: streamsMap,
streamsMap: streamsMap, origin: capture,
origin: capture, createdAt: time.Now(),
} }
} }
@@ -55,38 +56,12 @@ func (t *tcpStream) close() {
t.streamsMap.Delete(t.id) t.streamsMap.Delete(t.id)
for i := range t.clients { t.client.close()
reader := t.clients[i] t.server.close()
reader.close()
}
for i := range t.servers {
reader := t.servers[i]
reader.close()
}
} }
func (t *tcpStream) addClient(reader *tcpReader) { func (t *tcpStream) addCounterPair(counterPair *api.CounterPair) {
t.clients = append(t.clients, reader) t.counterPairs = append(t.counterPairs, counterPair)
}
func (t *tcpStream) addServer(reader *tcpReader) {
t.servers = append(t.servers, reader)
}
func (t *tcpStream) getClients() []*tcpReader {
return t.clients
}
func (t *tcpStream) getServers() []*tcpReader {
return t.servers
}
func (t *tcpStream) getClient(index int) *tcpReader {
return t.clients[index]
}
func (t *tcpStream) getServer(index int) *tcpReader {
return t.servers[index]
} }
func (t *tcpStream) addReqResMatcher(reqResMatcher api.RequestResponseMatcher) { func (t *tcpStream) addReqResMatcher(reqResMatcher api.RequestResponseMatcher) {
@@ -94,37 +69,21 @@ func (t *tcpStream) addReqResMatcher(reqResMatcher api.RequestResponseMatcher) {
} }
func (t *tcpStream) SetProtocol(protocol *api.Protocol) { func (t *tcpStream) SetProtocol(protocol *api.Protocol) {
t.protocol = protocol
// Clean the buffers
t.Lock() t.Lock()
defer t.Unlock() t.client.msgBufferMaster = make([]api.TcpReaderDataMsg, 0)
t.server.msgBufferMaster = make([]api.TcpReaderDataMsg, 0)
if t.protoIdentifier.IsClosedOthers { t.Unlock()
return
}
t.protoIdentifier.Protocol = protocol
for i := range t.clients {
reader := t.clients[i]
if reader.GetExtension().Protocol != t.protoIdentifier.Protocol {
reader.close()
}
}
for i := range t.servers {
reader := t.servers[i]
if reader.GetExtension().Protocol != t.protoIdentifier.Protocol {
reader.close()
}
}
t.protoIdentifier.IsClosedOthers = true
} }
func (t *tcpStream) GetOrigin() api.Capture { func (t *tcpStream) GetOrigin() api.Capture {
return t.origin return t.origin
} }
func (t *tcpStream) GetProtoIdentifier() *api.ProtoIdentifier { func (t *tcpStream) GetProtocol() *api.Protocol {
return t.protoIdentifier return t.protocol
} }
func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher { func (t *tcpStream) GetReqResMatchers() []api.RequestResponseMatcher {

View File

@@ -3,7 +3,6 @@ package tap
import ( import (
"fmt" "fmt"
"sync" "sync"
"time"
"github.com/up9inc/mizu/logger" "github.com/up9inc/mizu/logger"
"github.com/up9inc/mizu/tap/api" "github.com/up9inc/mizu/tap/api"
@@ -62,62 +61,50 @@ func (factory *tcpStreamFactory) New(net, transport gopacket.Flow, tcpLayer *lay
reassemblyStream := NewTcpReassemblyStream(fmt.Sprintf("%s:%s", net, transport), tcpLayer, fsmOptions, stream) reassemblyStream := NewTcpReassemblyStream(fmt.Sprintf("%s:%s", net, transport), tcpLayer, fsmOptions, stream)
if stream.GetIsTapTarget() { if stream.GetIsTapTarget() {
stream.setId(factory.streamsMap.NextId()) stream.setId(factory.streamsMap.NextId())
for i, extension := range extensions { for _, extension := range extensions {
reqResMatcher := extension.Dissector.NewResponseRequestMatcher()
stream.addReqResMatcher(reqResMatcher)
counterPair := &api.CounterPair{ counterPair := &api.CounterPair{
Request: 0, Request: 0,
Response: 0, Response: 0,
} }
stream.addClient( stream.addCounterPair(counterPair)
NewTcpReader(
make(chan api.TcpReaderDataMsg),
&api.ReadProgress{},
fmt.Sprintf("%s %s", net, transport),
&api.TcpID{
SrcIP: srcIp,
DstIP: dstIp,
SrcPort: srcPort,
DstPort: dstPort,
},
time.Time{},
stream,
true,
props.isOutgoing,
extension,
factory.emitter,
counterPair,
reqResMatcher,
),
)
stream.addServer(
NewTcpReader(
make(chan api.TcpReaderDataMsg),
&api.ReadProgress{},
fmt.Sprintf("%s %s", net, transport),
&api.TcpID{
SrcIP: net.Dst().String(),
DstIP: net.Src().String(),
SrcPort: transport.Dst().String(),
DstPort: transport.Src().String(),
},
time.Time{},
stream,
false,
props.isOutgoing,
extension,
factory.emitter,
counterPair,
reqResMatcher,
),
)
factory.streamsMap.Store(stream.getId(), stream) reqResMatcher := extension.Dissector.NewResponseRequestMatcher()
stream.addReqResMatcher(reqResMatcher)
factory.wg.Add(2)
go stream.getClient(i).run(filteringOptions, &factory.wg)
go stream.getServer(i).run(filteringOptions, &factory.wg)
} }
stream.client = NewTcpReader(
fmt.Sprintf("%s %s", net, transport),
&api.TcpID{
SrcIP: srcIp,
DstIP: dstIp,
SrcPort: srcPort,
DstPort: dstPort,
},
stream,
true,
props.isOutgoing,
factory.emitter,
)
stream.server = NewTcpReader(
fmt.Sprintf("%s %s", net, transport),
&api.TcpID{
SrcIP: net.Dst().String(),
DstIP: net.Src().String(),
SrcPort: transport.Dst().String(),
DstPort: transport.Src().String(),
},
stream,
false,
props.isOutgoing,
factory.emitter,
)
factory.streamsMap.Store(stream.getId(), stream)
factory.wg.Add(2)
go stream.client.run(filteringOptions, &factory.wg)
go stream.server.run(filteringOptions, &factory.wg)
} }
return reassemblyStream return reassemblyStream
} }

View File

@@ -57,7 +57,7 @@ func (streamMap *tcpStreamMap) CloseTimedoutTcpStreamChannels() {
return true return true
} }
if stream.protoIdentifier.Protocol == nil { if stream.protocol == nil {
if !stream.isClosed && time.Now().After(stream.createdAt.Add(tcpStreamChannelTimeoutMs)) { if !stream.isClosed && time.Now().After(stream.createdAt.Add(tcpStreamChannelTimeoutMs)) {
stream.close() stream.close()
diagnose.AppStats.IncDroppedTcpStreams() diagnose.AppStats.IncDroppedTcpStreams()

View File

@@ -68,7 +68,7 @@ struct fd_info {
BPF_HASH(pids_map, __u32, __u32); BPF_HASH(pids_map, __u32, __u32);
BPF_LRU_HASH(ssl_write_context, __u64, struct ssl_info); BPF_LRU_HASH(ssl_write_context, __u64, struct ssl_info);
BPF_LRU_HASH(ssl_read_context, __u64, struct ssl_info); BPF_LRU_HASH(ssl_read_context, __u64, struct ssl_info);
BPF_HASH(file_descriptor_to_ipv4, __u64, struct fd_info); BPF_LRU_HASH(file_descriptor_to_ipv4, __u64, struct fd_info);
BPF_PERF_OUTPUT(chunks_buffer); BPF_PERF_OUTPUT(chunks_buffer);
BPF_PERF_OUTPUT(log_buffer); BPF_PERF_OUTPUT(log_buffer);

View File

@@ -188,8 +188,7 @@ func (p *tlsPoller) startNewTlsReader(chunk *tlsChunk, address *addressPair, key
} }
stream := &tlsStream{ stream := &tlsStream{
reader: reader, reader: reader,
protoIdentifier: &api.ProtoIdentifier{},
} }
streamsMap.Store(streamsMap.NextId(), stream) streamsMap.Store(streamsMap.NextId(), stream)

View File

@@ -94,7 +94,3 @@ func (r *tlsReader) GetEmitter() api.Emitter {
func (r *tlsReader) GetIsClosed() bool { func (r *tlsReader) GetIsClosed() bool {
return false return false
} }
func (r *tlsReader) GetExtension() *api.Extension {
return r.extension
}

View File

@@ -3,20 +3,20 @@ package tlstapper
import "github.com/up9inc/mizu/tap/api" import "github.com/up9inc/mizu/tap/api"
type tlsStream struct { type tlsStream struct {
reader *tlsReader reader *tlsReader
protoIdentifier *api.ProtoIdentifier protocol *api.Protocol
} }
func (t *tlsStream) GetOrigin() api.Capture { func (t *tlsStream) GetOrigin() api.Capture {
return api.Ebpf return api.Ebpf
} }
func (t *tlsStream) GetProtoIdentifier() *api.ProtoIdentifier { func (t *tlsStream) GetProtocol() *api.Protocol {
return t.protoIdentifier return t.protocol
} }
func (t *tlsStream) SetProtocol(protocol *api.Protocol) { func (t *tlsStream) SetProtocol(protocol *api.Protocol) {
t.protoIdentifier.Protocol = protocol t.protocol = protocol
} }
func (t *tlsStream) GetReqResMatchers() []api.RequestResponseMatcher { func (t *tlsStream) GetReqResMatchers() []api.RequestResponseMatcher {

Binary file not shown.

Binary file not shown.

View File

@@ -67,7 +67,6 @@
height: 100% height: 100%
display: flex display: flex
flex-direction: column flex-direction: column
margin-right: 10px
width: 100% width: 100%
border-radius: 4px border-radius: 4px
@@ -82,17 +81,18 @@
margin-top: 10px margin-top: 10px
margin-right: 10px margin-right: 10px
.protocolsFilterList, .servicesFilter .card
background: white background: white
padding: 10px padding: 10px
border-radius: 4px border-radius: 4px
user-select: none user-select: none
box-shadow: 0px 1px 5px #979797
.servicesFilter .servicesFilterWrapper
margin-top: 10px margin-top: 20px
margin-bottom: 3px
height: 100% height: 100%
overflow: hidden overflow: hidden
border-radius: 4px
& .servicesFilterList .servicesFilterList
height: calc(100% - 30px - 52px) height: calc(100% - 30px - 52px)

View File

@@ -158,6 +158,7 @@ export const ServiceMapModal: React.FC<ServiceMapModalProps> = ({ isOpen, onClos
if (checkedProtocols.length === 0) { if (checkedProtocols.length === 0) {
setCheckedProtocols(getProtocolsForFilter.map(x => x.key)) setCheckedProtocols(getProtocolsForFilter.map(x => x.key))
} }
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [getProtocolsForFilter]) }, [getProtocolsForFilter])
useEffect(() => { useEffect(() => {
@@ -217,13 +218,13 @@ export const ServiceMapModal: React.FC<ServiceMapModalProps> = ({ isOpen, onClos
<div className={styles.filterSection + ` ${isFilterClicked ? styles.show : ""}`}> <div className={styles.filterSection + ` ${isFilterClicked ? styles.show : ""}`}>
<Resizeable minWidth={170} maxWidth={320}> <Resizeable minWidth={170} maxWidth={320}>
<div className={styles.filterWrapper}> <div className={styles.filterWrapper}>
<div className={styles.protocolsFilterList}> <div className={styles.card}>
<SelectList items={getProtocolsForFilter} checkBoxWidth="5%" tableName={"PROTOCOLS"} multiSelect={true} <SelectList items={getProtocolsForFilter} checkBoxWidth="5%" tableName={"PROTOCOLS"} multiSelect={true}
checkedValues={checkedProtocols} setCheckedValues={onProtocolsChange} tableClassName={styles.filters} checkedValues={checkedProtocols} setCheckedValues={onProtocolsChange} tableClassName={styles.filters}
inputSearchClass={styles.servicesFilterSearch} isFilterable={false}/> inputSearchClass={styles.servicesFilterSearch} isFilterable={false}/>
</div> </div>
<div className={styles.servicesFilter}> <div className={styles.servicesFilterWrapper + ` ${styles.card}`}>
<div className={styles.servicesFilterList}> <div className={styles.servicesFilterList}>
<SelectList items={getServicesForFilter} tableName={"SERVICES"} tableClassName={styles.filters} multiSelect={true} <SelectList items={getServicesForFilter} tableName={"SERVICES"} tableClassName={styles.filters} multiSelect={true}
checkBoxWidth="5%" checkedValues={checkedServices} setCheckedValues={onServiceChanges} inputSearchClass={styles.servicesFilterSearch}/> checkBoxWidth="5%" checkedValues={checkedServices} setCheckedValues={onServiceChanges} inputSearchClass={styles.servicesFilterSearch}/>
</div> </div>

View File

@@ -85,7 +85,7 @@ const SelectList: React.FC<Props> = ({ items, tableName, checkedValues = [], mul
const tableBody = filteredValues.length === 0 ? const tableBody = filteredValues.length === 0 ?
<tr> <tr>
<td colSpan={2}> <td colSpan={2} className={styles.displayBlock}>
<NoDataMessage messageText={noItemsMessage} /> <NoDataMessage messageText={noItemsMessage} />
</td> </td>
</tr> </tr>

View File

@@ -1,44 +1,70 @@
@import '../../../variables.module' @import '../../../variables.module'
@import '../../../components' @import '../../../components'
.selectListTable .selectListTable
overflow: auto
height: 100%
user-select: none // when resizble moved we get unwanted beheviour user-select: none // when resizble moved we get unwanted beheviour
height: 100%
table table
width: 100% width: 100%
margin-top: 20px
border-collapse: collapse border-collapse: collapse
table-layout: fixed
height: 100%
display: flex
flex-flow: column
height: 100%
th thead
color: $blue-gray display: table
text-align: left table-layout: fixed
padding: 10px flex: 0 0 auto
position: sticky width: calc(100% - 0.9em)
top: 0
background: $main-background-color
font-size: 12px
tr tbody
border-bottom-width: 1px display: block
border-bottom-color: $data-background-color overflow: auto
border-bottom-style: solid width: 100%
width: 100% height: 100%
flex: 1 1 auto
td tbody tr:hover
color: $light-gray background: $header-background-color
padding: 10px
font-size: 11px th
font-weight: 600 color: $blue-gray
padding-top: 5px text-align: left
padding-bottom: 5px padding: 10px
background: $main-background-color
font-size: 12px
tr
border-bottom-width: 1px
border-bottom-color: $data-background-color
border-bottom-style: solid
width: 100%
display: block
position: relative
display: table
table-layout: fixed
td
color: $light-gray
padding: 10px
font-size: 11px
font-weight: 600
padding-top: 5px
padding-bottom: 5px
.nowrap .nowrap
white-space: nowrap white-space: nowrap
.totalSelected .totalSelected
font-size: 12px font-size: 12px
color: $light-blue-color color: $light-blue-color
font-weight: 700 font-weight: 700
.displayBlock
display: block
.filterInput
margin-bottom: 20px