Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(httpapi): logger belongs to endpoint #1003

Merged
merged 3 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/go1.19.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ jobs:
steps:
- uses: actions/checkout@v2

- run: go install golang.org/dl/go1.19.1@latest
- uses: actions/setup-go@v3
with:
go-version: "1.19"

- run: $(go env GOPATH)/bin/go1.19.1 download
- run: go version

- run: $(go env GOPATH)/bin/go1.19.1 build -v ./...

- run: $(go env GOPATH)/bin/go1.19.1 test -short -race -tags shaping ./...
- run: go build -v ./...

- run: go test -short -race -tags shaping ./...
4 changes: 2 additions & 2 deletions internal/engine/experiment/webconnectivity/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func Control(
ctx context.Context, sess model.ExperimentSession,
testhelpers []model.OOAPIService, creq ControlRequest) (ControlResponse, *model.OOAPIService, error) {
seqCaller := httpapi.NewSequenceCaller(
httpapi.MustNewPOSTJSONWithJSONResponseDescriptor(sess.Logger(), "/", creq).WithBodyLogging(true),
httpapi.NewEndpointList(sess.DefaultHTTPClient(), sess.UserAgent(), testhelpers...)...,
httpapi.MustNewPOSTJSONWithJSONResponseDescriptor("/", creq).WithBodyLogging(true),
httpapi.NewEndpointList(sess.DefaultHTTPClient(), sess.Logger(), sess.UserAgent(), testhelpers...)...,
)
sess.Logger().Infof("control for %s...", creq.HTTPRequest)
var out ControlResponse
Expand Down
4 changes: 2 additions & 2 deletions internal/experiment/webconnectivity/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func (c *Control) Run(parentCtx context.Context) {

// create an httpapi sequence caller
seqCaller := httpapi.NewSequenceCaller(
httpapi.MustNewPOSTJSONWithJSONResponseDescriptor(c.Logger, "/", creq).WithBodyLogging(true),
httpapi.NewEndpointList(c.Session.DefaultHTTPClient(), c.Session.UserAgent(), c.TestHelpers...)...,
httpapi.MustNewPOSTJSONWithJSONResponseDescriptor("/", creq).WithBodyLogging(true),
httpapi.NewEndpointList(c.Session.DefaultHTTPClient(), c.Logger, c.Session.UserAgent(), c.TestHelpers...)...,
)

// issue the control request and wait for the response
Expand Down
10 changes: 5 additions & 5 deletions internal/httpapi/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func newRequest(ctx context.Context, endpoint *Endpoint, desc *Descriptor) (*htt
var reqBody io.Reader
if len(desc.RequestBody) > 0 {
reqBody = bytes.NewReader(desc.RequestBody)
desc.Logger.Debugf("httpapi: request body length: %d", len(desc.RequestBody))
endpoint.Logger.Debugf("httpapi: request body length: %d", len(desc.RequestBody))
if desc.LogBody {
desc.Logger.Debugf("httpapi: request body: %s", string(desc.RequestBody))
endpoint.Logger.Debugf("httpapi: request body: %s", string(desc.RequestBody))
}
}
request, err := http.NewRequestWithContext(ctx, desc.Method, URL.String(), reqBody)
Expand Down Expand Up @@ -120,9 +120,9 @@ func docall(endpoint *Endpoint, desc *Descriptor, request *http.Request) (*http.
if err != nil {
return response, nil, &errMaybeCensorship{err}
}
desc.Logger.Debugf("httpapi: response body length: %d bytes", len(data))
endpoint.Logger.Debugf("httpapi: response body length: %d bytes", len(data))
if desc.LogBody {
desc.Logger.Debugf("httpapi: response body: %s", string(data))
endpoint.Logger.Debugf("httpapi: response body: %s", string(data))
}
if response.StatusCode >= 400 {
return response, nil, &ErrHTTPRequestFailed{response.StatusCode}
Expand Down Expand Up @@ -174,7 +174,7 @@ func CallWithJSONResponse(ctx context.Context, desc *Descriptor, endpoint *Endpo
return err
}
if ctype := httpResp.Header.Get("Content-Type"); !goodContentTypeForJSON[ctype] {
desc.Logger.Warnf("httpapi: unexpected content-type: %s", ctype)
endpoint.Logger.Warnf("httpapi: unexpected content-type: %s", ctype)
// fallthrough
}
return json.Unmarshal(rawRespBody, response)
Expand Down
Loading