Skip to content

Commit

Permalink
fixes from teting
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-axway committed Nov 30, 2023
1 parent 628fcb8 commit cd8f942
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
20 changes: 10 additions & 10 deletions pkg/traceability/processor/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ type Latencies struct {
}

type Request struct {
QueryString map[string]string `json:"querystring"`
Size int `json:"size"`
URI string `json:"uri"`
URL string `json:"url"`
Headers map[string]string `json:"headers"`
Method string `json:"method"`
TLS *TLS `json:"tls"`
QueryString map[string]string `json:"querystring"`
Size int `json:"size"`
URI string `json:"uri"`
URL string `json:"url"`
Headers map[string]interface{} `json:"headers"`
Method string `json:"method"`
TLS *TLS `json:"tls"`
}

type Response struct {
Headers map[string]string `json:"headers"`
Status int `json:"status"`
Size int `json:"size"`
Headers map[string]interface{} `json:"headers"`
Status int `json:"status"`
Size int `json:"size"`
}

type Route struct {
Expand Down
16 changes: 13 additions & 3 deletions pkg/traceability/processor/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,28 @@ func (p *TransactionProcessor) process() ([]beat.Event, error) {
}

func createTransactionEvent(ktle TrafficLogEntry, txnid string) (*transaction.LogEvent, error) {
requestHost := ""
if value, found := ktle.Request.Headers[host]; found {
requestHost = fmt.Sprintf("%v", value)
}

userAgentVal := ""
if value, found := ktle.Request.Headers[userAgent]; found {
userAgentVal = fmt.Sprintf("%v", value)
}

httpProtocolDetails, err := transaction.NewHTTPProtocolBuilder().
SetURI(ktle.Request.URI).
SetMethod(ktle.Request.Method).
SetArgs(processQueryArgs(ktle.Request.QueryString)).
SetStatus(ktle.Response.Status, http.StatusText(ktle.Response.Status)).
SetHost(ktle.Request.Headers[host]).
SetHost(requestHost).
SetHeaders(buildHeaders(ktle.Request.Headers), buildHeaders(ktle.Response.Headers)).
SetByteLength(ktle.Request.Size, ktle.Response.Size).
SetLocalAddress(ktle.ClientIP, 0). // Could not determine local port for now
SetRemoteAddress("", "", ktle.Service.Port).
SetSSLProperties(buildSSLInfoIfAvailable(ktle)).
SetUserAgent(ktle.Request.Headers[userAgent]).
SetUserAgent(userAgentVal).
Build()

if err != nil {
Expand All @@ -106,7 +116,7 @@ func createTransactionEvent(ktle TrafficLogEntry, txnid string) (*transaction.Lo
SetTransactionID(txnid).
SetID(leg0).
SetSource(ktle.ClientIP).
SetDestination(ktle.Request.Headers[host]).
SetDestination(requestHost).
SetDuration(ktle.Latencies.Request).
SetDirection(inbound).
SetStatus(getTransactionEventStatus(ktle.Response.Status)).
Expand Down
10 changes: 7 additions & 3 deletions pkg/traceability/processor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ func getTransactionSummaryStatus(statusCode int) transaction.TxSummaryStatus {
return transSummaryStatus
}

func buildHeaders(headers map[string]string) string {
jsonHeader, err := json.Marshal(headers)
func buildHeaders(headers map[string]interface{}) string {
newHeaders := make(map[string]string)
for key, val := range headers {
newHeaders[key] = fmt.Sprintf("%v", val)
}

jsonHeader, err := json.Marshal(newHeaders)
if err != nil {
log.Error(err.Error())
}

return string(jsonHeader)
}

Expand Down

0 comments on commit cd8f942

Please sign in to comment.