diff --git a/api/pkg/api/main.go b/api/pkg/api/main.go index 1aea81795..e5eb0b5c2 100644 --- a/api/pkg/api/main.go +++ b/api/pkg/api/main.go @@ -97,8 +97,8 @@ func saveHarToDb(entry *har.Entry, sender string) { serviceName, urlPath, serviceHostName := getServiceNameFromUrl(entry.Request.URL) entryId := primitive.NewObjectID().Hex() var ( - resolvedSource *string - resolvedDestination *string + resolvedSource string + resolvedDestination string ) if k8sResolver != nil { resolvedSource = k8sResolver.Resolve(sender) diff --git a/api/pkg/controllers/entries_controller.go b/api/pkg/controllers/entries_controller.go index 70ec62714..293f02c29 100644 --- a/api/pkg/controllers/entries_controller.go +++ b/api/pkg/controllers/entries_controller.go @@ -90,12 +90,10 @@ func GetHARs(c *fiber.Ctx) error { harsObject := map[string]*models.ExtendedHAR{} for _, entryData := range entries { - harEntryObject := []byte(entryData.Entry) - var harEntry har.Entry - _ = json.Unmarshal(harEntryObject, &harEntry) + _ = json.Unmarshal([]byte(entryData.Entry), &harEntry) - sourceOfEntry := *entryData.ResolvedSource + sourceOfEntry := entryData.ResolvedSource if harOfSource, ok := harsObject[sourceOfEntry]; ok { harOfSource.Log.Entries = append(harOfSource.Log.Entries, &harEntry) } else { @@ -137,8 +135,8 @@ func GetEntry(c *fiber.Ctx) error { unmarshallErr := json.Unmarshal([]byte(entryData.Entry), &fullEntry) utils.CheckErr(unmarshallErr) - if entryData.ResolvedDestination != nil { - fullEntry.Request.URL = utils.SetHostname(fullEntry.Request.URL, *entryData.ResolvedDestination) + if entryData.ResolvedDestination != "" { + fullEntry.Request.URL = utils.SetHostname(fullEntry.Request.URL, entryData.ResolvedDestination) } return c.Status(fiber.StatusOK).JSON(fullEntry) diff --git a/api/pkg/models/models.go b/api/pkg/models/models.go index 856d1aa4c..3ed03ebed 100644 --- a/api/pkg/models/models.go +++ b/api/pkg/models/models.go @@ -21,8 +21,8 @@ type MizuEntry struct { Service string `json:"service" gorm:"column:service"` Timestamp int64 `json:"timestamp" gorm:"column:timestamp"` Path string `json:"path" gorm:"column:path"` - ResolvedSource *string `json:"resolvedSource,omitempty" gorm:"column:resolvedSource"` - ResolvedDestination *string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"` + ResolvedSource string `json:"resolvedSource,omitempty" gorm:"column:resolvedSource"` + ResolvedDestination string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"` } type BaseEntryDetails struct { @@ -38,7 +38,7 @@ type BaseEntryDetails struct { type EntryData struct { Entry string `json:"entry,omitempty"` - ResolvedDestination *string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"` + ResolvedDestination string `json:"resolvedDestination,omitempty" gorm:"column:resolvedDestination"` } type EntriesFilter struct { diff --git a/api/pkg/resolver/resolver.go b/api/pkg/resolver/resolver.go index e45ce490a..14076a108 100644 --- a/api/pkg/resolver/resolver.go +++ b/api/pkg/resolver/resolver.go @@ -33,12 +33,12 @@ func (resolver *Resolver) Start(ctx context.Context) { } } -func (resolver *Resolver) Resolve(name string) *string { +func (resolver *Resolver) Resolve(name string) string { resolvedName, isFound := resolver.nameMap[name] if !isFound { - return nil + return "" } - return &resolvedName + return resolvedName } func (resolver *Resolver) watchPods(ctx context.Context) error { diff --git a/api/pkg/utils/utils.go b/api/pkg/utils/utils.go index ebf4ce9f1..9492c9b55 100644 --- a/api/pkg/utils/utils.go +++ b/api/pkg/utils/utils.go @@ -65,9 +65,9 @@ func SetHostname(address, newHostname string) string { func GetResolvedBaseEntry(entry models.MizuEntry) models.BaseEntryDetails { entryUrl := entry.Url service := entry.Service - if entry.ResolvedDestination != nil { - entryUrl = SetHostname(entryUrl, *entry.ResolvedDestination) - service = SetHostname(service, *entry.ResolvedDestination) + if entry.ResolvedDestination != "" { + entryUrl = SetHostname(entryUrl, entry.ResolvedDestination) + service = SetHostname(service, entry.ResolvedDestination) } return models.BaseEntryDetails{ Id: entry.EntryId,