Fix some errors related to conversion to HAR (#286)

* Fix some errors related to conversion to HAR

* Fix the build error

* Fix the variable name

* Change to `Errorf`
This commit is contained in:
M. Mert Yıldıran
2021-09-20 13:53:20 +03:00
committed by GitHub
parent 8c7f82c6f0
commit 043b845c06
2 changed files with 11 additions and 11 deletions

View File

@@ -119,10 +119,12 @@ func startReadingChannel(outputItems <-chan *tapApi.OutputChannelItem, extension
if extension.Protocol.Name == "http" { if extension.Protocol.Name == "http" {
var pair tapApi.RequestResponsePair var pair tapApi.RequestResponsePair
json.Unmarshal([]byte(mizuEntry.Entry), &pair) json.Unmarshal([]byte(mizuEntry.Entry), &pair)
harEntry, _ := utils.NewEntry(&pair) harEntry, err := utils.NewEntry(&pair)
rules, _ := models.RunValidationRulesState(*harEntry, mizuEntry.Service) if err == nil {
baseEntry.Rules = rules rules, _ := models.RunValidationRulesState(*harEntry, mizuEntry.Service)
baseEntry.Latency = mizuEntry.ElapsedTime baseEntry.Rules = rules
baseEntry.Latency = mizuEntry.ElapsedTime
}
} }
baseEntryBytes, _ := models.CreateBaseEntryWebSocketMessage(baseEntry) baseEntryBytes, _ := models.CreateBaseEntryWebSocketMessage(baseEntry)

View File

@@ -9,11 +9,10 @@ import (
"time" "time"
"github.com/google/martian/har" "github.com/google/martian/har"
"github.com/up9inc/mizu/tap" "github.com/romana/rlog"
"github.com/up9inc/mizu/tap/api" "github.com/up9inc/mizu/tap/api"
) )
// Keep it because we might want cookies in the future // Keep it because we might want cookies in the future
//func BuildCookies(rawCookies []interface{}) []har.Cookie { //func BuildCookies(rawCookies []interface{}) []har.Cookie {
// cookies := make([]har.Cookie, 0, len(rawCookies)) // cookies := make([]har.Cookie, 0, len(rawCookies))
@@ -82,7 +81,7 @@ func BuildHeaders(rawHeaders []interface{}) ([]har.Header, string, string, strin
path = h["value"].(string) path = h["value"].(string)
} }
if h["name"] == ":status" { if h["name"] == ":status" {
path = h["value"].(string) status = h["value"].(string)
} }
} }
@@ -205,7 +204,7 @@ func NewResponse(response *api.GenericMessage) (harResponse *har.Response, err e
if strings.HasPrefix(mimeType.(string), "application/grpc") { if strings.HasPrefix(mimeType.(string), "application/grpc") {
status, err = strconv.Atoi(_status) status, err = strconv.Atoi(_status)
if err != nil { if err != nil {
tap.SilentError("convert-response-status-for-har", "Failed converting status to int %s (%v,%+v)", err, err, err) rlog.Errorf("Failed converting status to int %s (%v,%+v)", err, err, err)
return nil, errors.New("failed converting response status to int for HAR") return nil, errors.New("failed converting response status to int for HAR")
} }
} }
@@ -226,14 +225,13 @@ func NewResponse(response *api.GenericMessage) (harResponse *har.Response, err e
func NewEntry(pair *api.RequestResponsePair) (*har.Entry, error) { func NewEntry(pair *api.RequestResponsePair) (*har.Entry, error) {
harRequest, err := NewRequest(&pair.Request) harRequest, err := NewRequest(&pair.Request)
if err != nil { if err != nil {
tap.SilentError("convert-request-to-har", "Failed converting request to HAR %s (%v,%+v)", err, err, err) rlog.Errorf("Failed converting request to HAR %s (%v,%+v)", err, err, err)
return nil, errors.New("failed converting request to HAR") return nil, errors.New("failed converting request to HAR")
} }
harResponse, err := NewResponse(&pair.Response) harResponse, err := NewResponse(&pair.Response)
if err != nil { if err != nil {
fmt.Printf("err: %+v\n", err) rlog.Errorf("Failed converting response to HAR %s (%v,%+v)", err, err, err)
tap.SilentError("convert-response-to-har", "Failed converting response to HAR %s (%v,%+v)", err, err, err)
return nil, errors.New("failed converting response to HAR") return nil, errors.New("failed converting response to HAR")
} }