Skip to content

HTTP request logs screen#1442

Merged
veloce merged 21 commits intolichess-org:mainfrom
vincendep:feat/http-request-logs
Mar 24, 2025
Merged

HTTP request logs screen#1442
veloce merged 21 commits intolichess-org:mainfrom
vincendep:feat/http-request-logs

Conversation

@vincendep
Copy link
Copy Markdown
Contributor

@vincendep vincendep commented Feb 14, 2025

Specs:

  • Color in red response with code > 300.
  • Add a button to clear the logs
  • Use ListView with pagination (100 items per page?)

Implemetation:

  • should not reuse the existing http logger which was added for debugging locally during development
  • should wrap the default client returned in httpClientFactory to intercept all requests
  • save records in sqlite with a short retention period (7 days)
  • probably wise to save records by batches (like every 10?);
  • use app lifecycle events to save a pending incomplete batch when app is about to be exited (ie. put in background)

This PR closes #699

@vincendep vincendep marked this pull request as draft February 14, 2025 16:50
@vincendep vincendep force-pushed the feat/http-request-logs branch from 1d6c4f3 to d184926 Compare February 18, 2025 15:03
@vincendep
Copy link
Copy Markdown
Contributor Author

vincendep commented Feb 19, 2025

Hi @veloce, could I've some feedback if I am on track or not? Following, I'll list what is currently missing in this PR:

  • Fix failing tests
  • Add Widget test for HttpLogScreen
  • Implement batch support in HttpLogStorage
  • Flush batch in AppLifecycle events
  • Improve throttling/debounce fetching logic
  • Polish UI: add empty screen, initial screen etc...
  • Improve Accessibility

Copy link
Copy Markdown
Contributor

@veloce veloce left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this!

You're definitely on the right track. UI looks neat! (only feedback is that the status code is not aligned with the url).

Haven't looked in detail to the code, but I'm not sure why you want to improve the throttling logic to get the logs? Seems not really necessary but I may miss sth.

In the log screen, I'd add a confirm dialog when tapping the delete button.

@vincendep vincendep marked this pull request as ready for review February 22, 2025 21:56
@vincendep
Copy link
Copy Markdown
Contributor Author

Hi @veloce. Regarding the throttling logic, my previous implementation was buggy but now seems to be fixed. I also added a confirmation dialog to delete the logs, then are missing only batching and internationalisation.

@vincendep vincendep force-pushed the feat/http-request-logs branch from 2e3f4fb to 8b62bdb Compare February 24, 2025 12:34
@veloce
Copy link
Copy Markdown
Contributor

veloce commented Feb 26, 2025

Hi @veloce. Regarding the throttling logic, my previous implementation was buggy but now seems to be fixed. I also added a confirmation dialog to delete the logs, then are missing only batching and internationalisation.

Thanks! will review asap.

Batching could be done in another PR I suppose (if we ever need it).

Copy link
Copy Markdown
Contributor

@veloce veloce left a comment

Choose a reason for hiding this comment

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

Nice work!

Internationalisation is not needed yet for this feature. We can leave the hardcoded English strings.

A widget test that test the whole log screen would be nice. Nothing fancy, but perhaps something like a test that loads the whole app (you can find example in app_test.dart), then navigates to the log screen and see the startup requests. That would test the whole logging logic at once and having a test that shows the number of requests made during app startup is not bad as well.
No need to test pagination or deletion.

}, conflictAlgorithm: ConflictAlgorithm.replace);
}

Future<void> update(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need this, do we?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At the moment http logs are saved when a request is made and then updated with the status code when the response is received.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you would like to use the save method in an upsert manner I have to understand how to manage primary key column that is used as a cursor for the pagination logic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No I just thought the log would never need to be updated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah maybe was better to save the log directly when receiving the response...only difference is that we cannot save unanswered http requests.

@vincendep
Copy link
Copy Markdown
Contributor Author

Sure I'll add some tests 👌🏻

_createCorrespondenceGameTableV1(batch);
_createChatReadMessagesTableV1(batch);
_createGameTableV2(batch);
_createHttpLogTableV1(batch);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It should be _createHttpLogTableV4 imo (as in created in version 4).

Client call() {
const HttpClientFactory({this.onCreate});

final Client Function(Client client)? onCreate;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would be better named wrapClient or wrapper.

@vincendep vincendep force-pushed the feat/http-request-logs branch from 7bb35aa to 156faf9 Compare March 4, 2025 12:39
@veloce
Copy link
Copy Markdown
Contributor

veloce commented Mar 11, 2025

@vincendep do you wish to continue working on this PR? there are a couple of renaming, and a test missing still.

@vincendep
Copy link
Copy Markdown
Contributor Author

Hi @veloce, I would like to continue but at the moment I don't know when I will be able to do it.

@veloce
Copy link
Copy Markdown
Contributor

veloce commented Mar 11, 2025

Since it's almost done, if you prefer, I can take it over. I can add the test and merge this.

@vincendep
Copy link
Copy Markdown
Contributor Author

No problem at all, as you wish.

@veloce veloce merged commit 2cafeab into lichess-org:main Mar 24, 2025
1 check passed
@vincendep vincendep deleted the feat/http-request-logs branch April 14, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an http request logs screen

2 participants