Skip to content

Commit

Permalink
fix http&thrift request when adding header
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjing committed Nov 2, 2020
1 parent 7ce0475 commit 425735f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions replayer-agent/logic/worker/replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"os"
"strconv"
"strings"
"time"

"github.com/didi/sharingan/replayer-agent/common/handlers/tlog"
Expand Down Expand Up @@ -83,12 +84,17 @@ func (r *Replayer) ReplaySessionDoreplay(ctx context.Context, session *replaying

{
// add header
traceHeader := fmt.Sprintf("Sharingan-Replayer-Traceid: %s\r\n", traceID)
timeHeader := fmt.Sprintf("Sharingan-Replayer-Time: %d\r\n", session.CallFromInbound.OccurredAt)
traceHeader := fmt.Sprintf("\r\nSharingan-Replayer-Traceid: %s", traceID)
timeHeader := fmt.Sprintf("\r\nSharingan-Replayer-Time: %d", session.CallFromInbound.OccurredAt)
s := bytes.Split(request, []byte("\r\n"))
// add at the front for the thrift inbound
s[0] = append([]byte(traceHeader+timeHeader), s[0]...)
request = bytes.Join(s, []byte("\r\n"))
if strings.Contains(string(s[0]), " HTTP/") {
// http: add at the second line,the first line cannot be changed for 400 Bad Request
s[0] = append(s[0], []byte(traceHeader+timeHeader)...)
request = bytes.Join(s, []byte("\r\n"))
} else {
// thrift: add at the end for the thrift inbound
request = append(request, []byte(traceHeader+timeHeader)...)
}
}

testResponse, err := handleConn(ctx, conn, request, true, project)
Expand Down
4 changes: 2 additions & 2 deletions replayer/fastmock/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

var (
// inbound header feature, include traceID、replay Time
traceRegex = regexp.MustCompile(`Sharingan-Replayer-Traceid: (\w{32})\r\n`)
timeRegex = regexp.MustCompile(`Sharingan-Replayer-Time: (\d{19})\r\n`)
traceRegex = regexp.MustCompile(`Sharingan-Replayer-Trace(?:id|ID)\s?: (\w{32})\r\n`)
timeRegex = regexp.MustCompile(`Sharingan-Replayer-Time\s?: (\d{19})\r\n`)

// outbound traffic prefix, include traceID、origin connect addr
trafficPrefix = `/*{"rid":"%s","addr":"%s"}*/`
Expand Down

0 comments on commit 425735f

Please sign in to comment.