mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-29 15:37:05 +00:00
Connect OutputChannelItem
to the last WebSocket means that finally the web UI started to work again
This commit is contained in:
parent
163fc7c4ae
commit
fb56106741
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"mizuserver/pkg/api"
|
"mizuserver/pkg/api"
|
||||||
"mizuserver/pkg/models"
|
"mizuserver/pkg/models"
|
||||||
"mizuserver/pkg/routes"
|
"mizuserver/pkg/routes"
|
||||||
@ -201,6 +202,9 @@ func pipeTapChannelToSocket(connection *websocket.Conn, messageDataChannel <-cha
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("marshaledData: %s\n", marshaledData)
|
||||||
|
// NOTE: This is where the `*tapApi.OutputChannelItem` leaves the code
|
||||||
|
// and goes into the intermediate WebSocket.
|
||||||
err = connection.WriteMessage(websocket.TextMessage, marshaledData)
|
err = connection.WriteMessage(websocket.TextMessage, marshaledData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rlog.Infof("error sending message through socket server %s, (%v,%+v)\n", err, err, err)
|
rlog.Infof("error sending message through socket server %s, (%v,%+v)\n", err, err, err)
|
||||||
|
@ -5,10 +5,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
"mizuserver/pkg/database"
|
"mizuserver/pkg/database"
|
||||||
"mizuserver/pkg/holder"
|
"mizuserver/pkg/holder"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -16,6 +14,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
|
||||||
"github.com/google/martian/har"
|
"github.com/google/martian/har"
|
||||||
"github.com/romana/rlog"
|
"github.com/romana/rlog"
|
||||||
"github.com/up9inc/mizu/tap"
|
"github.com/up9inc/mizu/tap"
|
||||||
@ -110,11 +110,14 @@ func startReadingChannel(outputItems <-chan *tapApi.OutputChannelItem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for item := range outputItems {
|
for item := range outputItems {
|
||||||
if harEntry, err := models.NewEntry(item.Data.Request.Orig.(*http.Request), item.Data.Request.CaptureTime, item.Data.Response.Orig.(*http.Response), item.Data.Response.CaptureTime); err == nil {
|
fmt.Printf("item: %+v\n", item)
|
||||||
saveHarToDb(harEntry, item.ConnectionInfo)
|
// NOTE: With this call, the incoming data is sent to the last WebSocket (that the web UI communicates).
|
||||||
} else {
|
handleItem(item)
|
||||||
rlog.Errorf("Error when creating HTTP entry")
|
// if harEntry, err := models.NewEntry(item.Data.Request.Orig.(*http.Request), item.Data.Request.CaptureTime, item.Data.Response.Orig.(*http.Response), item.Data.Response.CaptureTime); err == nil {
|
||||||
}
|
// saveHarToDb(harEntry, item.ConnectionInfo)
|
||||||
|
// } else {
|
||||||
|
// rlog.Errorf("Error when creating HTTP entry")
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +128,15 @@ func StartReadingOutbound(outboundLinkChannel <-chan *tap.OutboundLink) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleItem(item *tapApi.OutputChannelItem) {
|
||||||
|
baseEntry := models.BaseEntryDetails{
|
||||||
|
RequestSenderIp: item.ConnectionInfo.ClientIP,
|
||||||
|
}
|
||||||
|
baseEntryBytes, _ := models.CreateBaseEntryWebSocketMessage(&baseEntry)
|
||||||
|
// NOTE: This is where it's sent to the last WebSocket
|
||||||
|
BroadcastToBrowserClients(baseEntryBytes)
|
||||||
|
}
|
||||||
|
|
||||||
func saveHarToDb(entry *har.Entry, connectionInfo *tapApi.ConnectionInfo) {
|
func saveHarToDb(entry *har.Entry, connectionInfo *tapApi.ConnectionInfo) {
|
||||||
entryBytes, _ := json.Marshal(entry)
|
entryBytes, _ := json.Marshal(entry)
|
||||||
serviceName, urlPath := getServiceNameFromUrl(entry.Request.URL)
|
serviceName, urlPath := getServiceNameFromUrl(entry.Request.URL)
|
||||||
|
@ -14,6 +14,7 @@ type HTTPPayloader interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
||||||
|
// TODO: Implement JSON marshaling for HTTP request and response
|
||||||
switch h.Type {
|
switch h.Type {
|
||||||
case "http_request":
|
case "http_request":
|
||||||
return []byte("{\"val\": \"" + h.Type + "\"}"), nil
|
return []byte("{\"val\": \"" + h.Type + "\"}"), nil
|
||||||
|
Loading…
Reference in New Issue
Block a user