diff --git a/agent/pkg/api/main.go b/agent/pkg/api/main.go index 685ef2516..41abea924 100644 --- a/agent/pkg/api/main.go +++ b/agent/pkg/api/main.go @@ -140,7 +140,17 @@ func startReadingChannel(outputItems <-chan *tapApi.OutputChannelItem, extension mizuEntry.Rules = rules } - entryWSource := oas.EntryWithSource{Entry: *harEntry, Source: mizuEntry.Source.Name, Id: mizuEntry.Id} + entryWSource := oas.EntryWithSource{ + Entry: *harEntry, + Source: mizuEntry.Source.Name, + Destination: mizuEntry.Destination.Name, + Id: mizuEntry.Id, + } + + if entryWSource.Destination == "" { + entryWSource.Destination = mizuEntry.Destination.IP + ":" + mizuEntry.Destination.Port + } + oas.GetOasGeneratorInstance().PushEntry(&entryWSource) } diff --git a/agent/pkg/oas/feeder_test.go b/agent/pkg/oas/feeder_test.go index 4e78734ce..893c6033f 100644 --- a/agent/pkg/oas/feeder_test.go +++ b/agent/pkg/oas/feeder_test.go @@ -6,6 +6,7 @@ import ( "errors" "io" "io/ioutil" + "net/url" "os" "path/filepath" "sort" @@ -139,7 +140,12 @@ func feedEntry(entry *har.Entry, source string, isSync bool, file string) { logger.Log.Debugf("Interesting: %s", entry.Request.URL) } - ews := EntryWithSource{Entry: *entry, Source: source, Id: uint(0)} + u, err := url.Parse(entry.Request.URL) + if err != nil { + logger.Log.Errorf("Failed to parse entry URL: %v, err: %v", entry.Request.URL, err) + } + + ews := EntryWithSource{Entry: *entry, Source: source, Destination: u.Host, Id: uint(0)} if isSync { GetOasGeneratorInstance().entriesChan <- ews // blocking variant, right? } else { diff --git a/agent/pkg/oas/oas_generator.go b/agent/pkg/oas/oas_generator.go index 0f1f44b3a..df7278325 100644 --- a/agent/pkg/oas/oas_generator.go +++ b/agent/pkg/oas/oas_generator.go @@ -54,11 +54,11 @@ func (g *oasGenerator) runGeneretor() { logger.Log.Errorf("Failed to parse entry URL: %v, err: %v", entry.Request.URL, err) } - val, found := g.ServiceSpecs.Load(u.Host) + val, found := g.ServiceSpecs.Load(entryWithSource.Destination) var gen *SpecGen if !found { - gen = NewGen(u.Scheme + "://" + u.Host) - g.ServiceSpecs.Store(u.Host, gen) + gen = NewGen(u.Scheme + "://" + entryWithSource.Destination) + g.ServiceSpecs.Store(entryWithSource.Destination, gen) } else { gen = val.(*SpecGen) } @@ -105,9 +105,10 @@ func newOasGenerator() *oasGenerator { } type EntryWithSource struct { - Source string - Entry har.Entry - Id uint + Source string + Destination string + Entry har.Entry + Id uint } type oasGenerator struct {