Skip to content

Commit 9c68cb5

Browse files
committed
Add homeserver name to client request logging to differentiate who/where
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 1d09b18 commit 9c68cb5

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
@@ -327,7 +327,7 @@ func (c *CSAPI) DoFunc(t *testing.T, method string, paths []string, opts ...Requ
327327
}
328328

329329
// NewLoggedClient returns an http.Client which logs requests/responses
330-
func NewLoggedClient(t *testing.T, cli *http.Client) *http.Client {
330+
func NewLoggedClient(t *testing.T, hsName string, cli *http.Client) *http.Client {
331331
t.Helper()
332332
if cli == nil {
333333
cli = &http.Client{
@@ -338,22 +338,23 @@ func NewLoggedClient(t *testing.T, cli *http.Client) *http.Client {
338338
if transport == nil {
339339
transport = http.DefaultTransport
340340
}
341-
cli.Transport = &loggedRoundTripper{t, transport}
341+
cli.Transport = &loggedRoundTripper{t, hsName, transport}
342342
return cli
343343
}
344344

345345
type loggedRoundTripper struct {
346-
t *testing.T
347-
wrap http.RoundTripper
346+
t *testing.T
347+
hsName string
348+
wrap http.RoundTripper
348349
}
349350

350351
func (t *loggedRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
351352
start := time.Now()
352353
res, err := t.wrap.RoundTrip(req)
353354
if err != nil {
354-
t.t.Logf("%s %s => error: %s (%s)", req.Method, req.URL.Path, err, time.Since(start))
355+
t.t.Logf("%s %s%s => error: %s (%s)", req.Method, t.hsName, req.URL.Path, err, time.Since(start))
355356
} else {
356-
t.t.Logf("%s %s => %s (%s)", req.Method, req.URL.Path, res.Status, time.Since(start))
357+
t.t.Logf("%s %s%s => %s (%s)", req.Method, t.hsName, req.URL.Path, res.Status, time.Since(start))
357358
}
358359
return res, err
359360
}

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)