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

Improve logging of http requests to aid debugging #3485

Merged
merged 9 commits into from
Jul 11, 2023

Conversation

BillCarsonFr
Copy link
Member

@BillCarsonFr BillCarsonFr commented Jun 19, 2023

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

Added simple logging for all requests made from the js-sdk to ease rageshakes investigation.

Fix element-hq/element-web#25570

Looks like that:

FetchHttpApi: GET --> http://localhost:8080/_matrix/client/r0/sync?filter=0&timeout=30000&since=s26_3787_3_8_29_1_12_38_0_1

udpated as per to remove url params that could contain secrets

FetchHttpApi: PUT --> /_matrix/client/v3/sendToDevice/m.room.encrypted/b8f4c87559504be794f3e1496a8970a5
rageshake.ts:77 FetchHttpApi:  <-- 200 8ms /_matrix/client/v3/sendToDevice/m.room.encrypted/b8f4c87559504be794f3e1496a8970a5
rageshake.ts:77 FetchHttpApi: PUT --> /_matrix/client/r0/rooms/!ZTAJxYLImTUucVDSZW%3Alocalhost%3A8480/typing/%40alice%3Alocalhost%3A8480
rageshake.ts:77 FetchHttpApi:  <-- 200 10ms /_matrix/client/r0/rooms/!ZTAJxYLImTUucVDSZW%3Alocalhost%3A8480/typing/%40alice%3Alocalhost%3A8480
rageshake.ts:77 FetchHttpApi:  <-- 200 2662ms /_matrix/client/r0/sync
rageshake.ts:77 FetchHttpApi: GET --> /_matrix/client/r0/sync
rageshake.ts:77 FetchHttpApi: PUT --> /_matrix/client/r0/rooms/!ZTAJxYLImTUucVDSZW%3Alocalhost%3A8480/typing/%40alice%3Alocalhost%3A8480
rageshake.ts:77 FetchHttpApi:  <-- 200 28ms /_matrix/client/r0/rooms/!ZTAJxYLImTUucVDSZW%3Alocalhost%3A8480/typing/%40alice%3Alocalhost%3A8480
rageshake.ts:77 FetchHttpApi:  <-- 200 247ms /_matrix/client/r0/sync
rageshake.ts:77 FetchHttpApi: GET --> /_matrix/client/r0/sync
rageshake.ts:77 FetchHttpApi: PUT --> /_matrix/client/v3/sendToDevice/m.room.encrypted/815dbfb5a7b54c9a9cfe09a8080a8704
rageshake.ts:77 FetchHttpApi:  <-- 200 10ms /_matrix/client/v3/sendToDevice/m.room.encrypted/815dbfb5a7b54c9a9cfe09a8080a8704
rageshake.ts:77 FetchHttpApi: PUT --> /_matrix/client/r0/rooms/!ZTAJxYLImTUucVDSZW%3Alocalhost%3A8480/send/m.room.encrypted/m1688377642353.0
rageshake.ts:77 FetchHttpApi:  <-- 200 30ms /_matrix/client/r0/rooms/!ZTAJxYLImTUucVDSZW%3Alocalhost%3A8480/send/m.room.encrypted/m1688377642353.0

This change is marked as an internal change (Task), so will not be included in the changelog.

Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query parameters can contain secrets, we can't just print them all

Most of the secrets are ephemeral but some aren't single-use.

src/http-api/fetch.ts Outdated Show resolved Hide resolved
@germain-gg germain-gg removed their request for review June 26, 2023 14:38
@BillCarsonFr
Copy link
Member Author

Query parameters can contain secrets, we can't just print them all

Most of the secrets are ephemeral but some aren't single-use.

I modified to just print out the url path

t3chguy
t3chguy previously requested changes Jul 3, 2023
src/http-api/fetch.ts Outdated Show resolved Hide resolved
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance of tests for this change?

@BillCarsonFr
Copy link
Member Author

Any chance of tests for this change?

I could refactor a bit and extract a sort of "HttpFetchLogger" and add some unit test, could allow to have simple unit test to see if it's handling URL as expected and doing the time correctly.

Or are you thinking about more integrated tests with sending a rageshake and checking for log reports in the RS files?

@t3chguy
Copy link
Member

t3chguy commented Jul 3, 2023

I was thinking of a basic unit test which just mocks/stubs logger, calls http-api and asserts that logger was called with expected log lines

@richvdh
Copy link
Member

richvdh commented Jul 7, 2023

It's a bit frustrating that real quality-of-life improvements like this get stuck behind a requirement for improved testing. Can we land it anyway without spending the time writing tests?

@t3chguy
Copy link
Member

t3chguy commented Jul 7, 2023

Given it has potential to leak secrets if it is broken I'd advocate for tests to assert that it does not...

@richvdh
Copy link
Member

richvdh commented Jul 7, 2023

Most of the secrets are ephemeral but some aren't single-use.

If there are non-single-use secrets in query params, that seems like a problem, as such secrets will also get logged server-side. What are you thinking of?

@t3chguy t3chguy added the T-Task Tasks for the team like planning label Jul 7, 2023
@t3chguy t3chguy changed the title Fix | Http requests are not included in Rageshakes (https://github.com/vector-im/element-web/issues/25570) Improve logging of http requests to aid debugging Jul 7, 2023
src/http-api/fetch.ts Outdated Show resolved Hide resolved
src/http-api/fetch.ts Outdated Show resolved Hide resolved
src/http-api/fetch.ts Outdated Show resolved Hide resolved
@richvdh richvdh requested a review from t3chguy July 11, 2023 15:51
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nits

I would have personally thought the logs would make more sense with the least granular thing first e.g.

FetchHttpApi: <-- $METHOD $URL [$TIME $STATUS/$ERROR]

For scanning logs I'd have thought keeping the method & url in a fixed column position would have been helpful

Fixed the test to not have status=undefined and not use 1234 for both the port and the time

spec/unit/http-api/fetch.spec.ts Outdated Show resolved Hide resolved
spec/unit/http-api/fetch.spec.ts Outdated Show resolved Hide resolved
spec/unit/http-api/fetch.spec.ts Outdated Show resolved Hide resolved
spec/unit/http-api/fetch.spec.ts Outdated Show resolved Hide resolved
richvdh and others added 2 commits July 11, 2023 18:19
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
@richvdh richvdh enabled auto-merge July 11, 2023 17:20
@richvdh richvdh added this pull request to the merge queue Jul 11, 2023
Merged via the queue into develop with commit 3385adf Jul 11, 2023
@richvdh richvdh deleted the valere/log_request_in_rs branch July 11, 2023 17:40
MadLittleMods added a commit that referenced this pull request Jul 11, 2023
github-merge-queue bot pushed a commit that referenced this pull request Jul 13, 2023
* Log query parameters on HTTP requests

Follow-up to #3485

* Only stringify once

See #3591 (comment)
richvdh added a commit that referenced this pull request Oct 4, 2023
Since #3485, we log every request anyway, so there's no need to log twice.,
github-merge-queue bot pushed a commit that referenced this pull request Oct 5, 2023
Since #3485, we log every request anyway, so there's no need to log twice.,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Task Tasks for the team like planning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTTP requests are not included in rageshakes
4 participants