Skip to content

Commit

Permalink
feat: collector OT receiver 处理 tenantKey --story=116702353 (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiandongx authored Mar 26, 2024
1 parent 215ef98 commit 52edf5c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/collector/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.49.x
0.50.x
17 changes: 14 additions & 3 deletions pkg/collector/receiver/otlp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import (
)

const (
tokenKey = "X-BK-TOKEN"
tokenKey = "X-BK-TOKEN"
tenantIDKey = "X-Tps-TenantID"

routeV1Traces = "/v1/traces"
routeV1Trace = "/v1/trace"
routeV1Metrics = "/v1/metrics"
Expand Down Expand Up @@ -102,6 +104,16 @@ func writeError(w http.ResponseWriter, rh receiver.ResponseHandler, err error, s
receiver.WriteResponse(w, rh.ContentType(), statusCode, msg)
}

// 允许从 HTTP Header 中读取 token
// 优先读取 TokenKey 再尝试读取 TenantKey
func extractTokenFromHeader(header http.Header) string {
token := header.Get(tokenKey)
if len(token) > 0 {
return token
}
return header.Get(tenantIDKey)
}

func (s HttpService) httpExport(w http.ResponseWriter, req *http.Request, rtype define.RecordType) {
defer utils.HandleCrash()
ip := utils.ParseRequestIP(req.RemoteAddr)
Expand Down Expand Up @@ -135,8 +147,7 @@ func (s HttpService) httpExport(w http.ResponseWriter, req *http.Request, rtype
Data: data,
}

// 允许从 HTTP Header 中读取 token
tk := req.Header.Get(tokenKey)
tk := extractTokenFromHeader(req.Header)
if len(tk) > 0 {
r.Token = define.Token{Original: tk}
}
Expand Down

0 comments on commit 52edf5c

Please sign in to comment.