Skip to content

Commit 7f5c90a

Browse files
Add homeserver name to client request logging to differentiate who/where (#154)
Before: ``` === CONT TestBackfillingHistory client.go:356: GET /_matrix/client/r0/sync => 200 OK (31.496008ms) client.go:356: POST /_matrix/client/unstable/org.matrix.msc2716/rooms/!GkmAGvcDmllsuqLgZA:hs1/batch_send => 200 OK (96.308307ms) client.go:356: POST /_matrix/client/r0/join/!GkmAGvcDmllsuqLgZA:hs1 => 200 OK (808.747133ms) client.go:356: GET /_matrix/client/r0/rooms/!GkmAGvcDmllsuqLgZA:hs1/messages => 200 OK (83.415512ms) ``` After: ``` === CONT TestBackfillingHistory client.go:357: GET hs1/_matrix/client/r0/sync => 200 OK (29.885812ms) client.go:357: POST hs1/_matrix/client/unstable/org.matrix.msc2716/rooms/!jbwgZJKNOedwNWRdop:hs1/batch_send => 200 OK (96.173807ms) client.go:357: POST hs2/_matrix/client/r0/join/!jbwgZJKNOedwNWRdop:hs1 => 200 OK (808.849665ms) client.go:357: GET hs2/_matrix/client/r0/rooms/!jbwgZJKNOedwNWRdop:hs1/messages => 200 OK (73.667196ms) ```
1 parent 94c1deb commit 7f5c90a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

internal/client/client.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (c *CSAPI) DoFunc(t *testing.T, method string, paths []string, opts ...Requ
324324
}
325325

326326
// NewLoggedClient returns an http.Client which logs requests/responses
327-
func NewLoggedClient(t *testing.T, cli *http.Client) *http.Client {
327+
func NewLoggedClient(t *testing.T, hsName string, cli *http.Client) *http.Client {
328328
t.Helper()
329329
if cli == nil {
330330
cli = &http.Client{
@@ -335,22 +335,23 @@ func NewLoggedClient(t *testing.T, cli *http.Client) *http.Client {
335335
if transport == nil {
336336
transport = http.DefaultTransport
337337
}
338-
cli.Transport = &loggedRoundTripper{t, transport}
338+
cli.Transport = &loggedRoundTripper{t, hsName, transport}
339339
return cli
340340
}
341341

342342
type loggedRoundTripper struct {
343-
t *testing.T
344-
wrap http.RoundTripper
343+
t *testing.T
344+
hsName string
345+
wrap http.RoundTripper
345346
}
346347

347348
func (t *loggedRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
348349
start := time.Now()
349350
res, err := t.wrap.RoundTrip(req)
350351
if err != nil {
351-
t.t.Logf("%s %s => error: %s (%s)", req.Method, req.URL.Path, err, time.Since(start))
352+
t.t.Logf("%s %s%s => error: %s (%s)", req.Method, t.hsName, req.URL.Path, err, time.Since(start))
352353
} else {
353-
t.t.Logf("%s %s => %s (%s)", req.Method, req.URL.Path, res.Status, time.Since(start))
354+
t.t.Logf("%s %s%s => %s (%s)", req.Method, t.hsName, req.URL.Path, res.Status, time.Since(start))
354355
}
355356
return res, err
356357
}

internal/docker/deployment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (d *Deployment) Client(t *testing.T, hsName, userID string) *client.CSAPI {
5353
UserID: userID,
5454
AccessToken: token,
5555
BaseURL: dep.BaseURL,
56-
Client: client.NewLoggedClient(t, nil),
56+
Client: client.NewLoggedClient(t, hsName, nil),
5757
SyncUntilTimeout: 5 * time.Second,
5858
Debug: d.Deployer.debugLogging,
5959
}
@@ -69,7 +69,7 @@ func (d *Deployment) RegisterUser(t *testing.T, hsName, localpart, password stri
6969
}
7070
client := &client.CSAPI{
7171
BaseURL: dep.BaseURL,
72-
Client: client.NewLoggedClient(t, nil),
72+
Client: client.NewLoggedClient(t, hsName, nil),
7373
SyncUntilTimeout: 5 * time.Second,
7474
Debug: d.Deployer.debugLogging,
7575
}

0 commit comments

Comments
 (0)