Skip to content

Commit

Permalink
fix(logaget): correct proxy target url
Browse files Browse the repository at this point in the history
  • Loading branch information
leonarliu committed Apr 12, 2022
1 parent b75278e commit 6eb197f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pkg/logagent/registry/logagent/storage/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (r *LogagentProxyREST) Connect(ctx context.Context, clusterName string, opt
if err != nil {
return nil, err
}
log.Errorf("location: %+v\n", location)
return &logAgentProxyHandler{
location: location,
transport: transport,
Expand Down Expand Up @@ -117,7 +118,9 @@ func (h *logAgentProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Reques
if h.token != "" {
newReq.Header.Set("Authorization", fmt.Sprintf("Bearer %s", strings.TrimSpace(h.token)))
}
log.Errorf("req is: %+v\n", newReq)

log.Errorf("targety is: %+v\n", &url.URL{Scheme: h.location.Scheme, Host: h.location.Host})
reverseProxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: h.location.Scheme, Host: h.location.Host})
reverseProxy.Transport = h.transport
reverseProxy.FlushInterval = 100 * time.Millisecond
Expand Down
11 changes: 6 additions & 5 deletions pkg/logagent/util/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ func APIServerLocationByCluster(ctx context.Context, clusterName string, platfor
if credential.Token != nil {
token = *credential.Token
}
return &url.URL{
Scheme: "https",
Host: restConfig.Host,
Path: requestInfo.Path,
}, transport, token, nil
apiserver, err := url.Parse(restConfig.Host)
if err != nil {
return nil, nil, "", err
}
apiserver.Path = requestInfo.Path
return apiserver, transport, token, nil
}

//use cache to optimize this function
Expand Down

0 comments on commit 6eb197f

Please sign in to comment.