This commit is contained in:
RamiBerm 2021-05-09 16:34:47 +03:00
parent ee63247888
commit 21694d0ff9
3 changed files with 34 additions and 3 deletions

View File

@ -3,11 +3,12 @@ module mizuserver
go 1.16
require (
github.com/up9inc/mizu/resolver v0.0.0
github.com/antoniodipinto/ikisocket v0.0.0-20210417133349-f1502512d69a
github.com/djherbis/atime v1.0.0
github.com/fasthttp/websocket v1.4.3-beta.1 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/locales v0.13.0
github.com/go-playground/universal-translator v0.17.0
github.com/go-playground/validator/v10 v10.5.0
github.com/gofiber/fiber/v2 v2.8.0
github.com/google/gopacket v1.1.19
@ -16,8 +17,11 @@ require (
github.com/leodido/go-urn v1.2.1 // indirect
github.com/orcaman/concurrent-map v0.0.0-20210106121528-16402b402231
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/stretchr/objx v0.2.0 // indirect
go.mongodb.org/mongo-driver v1.5.1
golang.org/x/net v0.0.0-20210421230115-4e50805a0758
gorm.io/driver/sqlite v1.1.4
gorm.io/gorm v1.21.8
)
replace github.com/up9inc/mizu/resolver => ../resolver

View File

@ -115,8 +115,9 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=

View File

@ -2,10 +2,12 @@ package inserter
import (
"bufio"
"context"
"encoding/json"
"fmt"
"github.com/antoniodipinto/ikisocket"
"github.com/google/martian/har"
"github.com/up9inc/mizu/resolver"
"go.mongodb.org/mongo-driver/bson/primitive"
"mizuserver/pkg/database"
"mizuserver/pkg/models"
@ -17,6 +19,28 @@ import (
"time"
)
var k8sResolver *resolver.Resolver
func init() {
errOut := make(chan error, 100)
res, err := resolver.NewFromOutOfCluster("", errOut)
if err != nil {
fmt.Printf("error creating k8s resolver %s", err)
}
ctx := context.Background()
res.Start(ctx)
go func() {
for {
select {
case err := <- errOut:
fmt.Printf("name resolving error %s", err)
}
}
}()
k8sResolver = res
}
func StartReadingFiles(harChannel chan *har.Entry, workingDir *string) {
if workingDir != nil && *workingDir != "" {
startReadingFiles(*workingDir)
@ -77,6 +101,8 @@ func saveHarToDb(entry har.Entry, source string) {
Status: entry.Response.Status,
Source: source,
Timestamp: entry.StartedDateTime.UnixNano() / int64(time.Millisecond),
ResolvedSource: k8sResolver.Resolve(source),
ResolvedDestination: k8sResolver.Resolve(serviceName),
}
database.GetEntriesTable().Create(&mizuEntry)