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

Isolate runserver CLI in client module and move AppState into views #9605

Merged
merged 9 commits into from
Nov 14, 2024

Conversation

leovalais
Copy link
Contributor

@leovalais leovalais commented Nov 6, 2024

Follow up of #9349

Moves in the client module the following commands:

  • health check
  • openapi generation
  • runserver

Reaching a proper split (import wise) of the run server command required a bit of refactoring. We want client to depend of views, and not the other way around. So we cannot use client definitions anywhere in views.

What's done to achieve that:

  • Introduce a ServerConfig structure that aggregates all server parameters.
  • Move AppState into views (still re-exported at crate-level, for now at least)
  • Add the config to the state.
  • Get rid of most occurrences of client definitions usage outside of the module. MapLayerConfig has been removed from the state, ValkeyConfig moved in mod valkey_utils, PostgresConfig and CoreConfig duplicated in mod views.

What's been done simultaneously:

  • Use the type url::Url instead of String where it makes sense
  • Remove unused CLI parameters
  • Remove useless Default implementations in client
  • Restrict client structs visibility where possible.

Next steps

  1. Move the big match in the run function in the client module
  2. Expose ROOT-URL and DYNAMIC_ASSET_PATH in clap and remove their accessor functions from client
  3. Move get_app_version in editoast_common
  4. Move valkey_utils in editoast_common (wdyt?)
  5. Remove db_pool_v1 from the AppState
  6. Replace most return Box::new(CliError::new(... by anyhow::bail! since anyhow's paradigm fits perfectly our error management on the client side
  7. Use the AppState.config.disable_authorization and remove AppState.disable_authorization
  8. The editoast_client crate is ready to be split!

(Some of these points could be included in the current PR, but I figured it's big enough already...)

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 17.43772% with 232 lines in your changes missing coverage. Please review.

Project coverage is 42.43%. Comparing base (da5c5b1) to head (c57059d).
Report is 11 commits behind head on dev.

Files with missing lines Patch % Lines
editoast/src/views/mod.rs 6.30% 104 Missing ⚠️
editoast/src/client/runserver.rs 0.00% 60 Missing ⚠️
editoast/src/client/healthcheck.rs 0.00% 20 Missing ⚠️
editoast/src/client/valkey_config.rs 0.00% 14 Missing ⚠️
editoast/src/client/postgres_config.rs 0.00% 10 Missing ⚠️
editoast/editoast_osrdyne_client/src/lib.rs 0.00% 7 Missing ⚠️
editoast/src/client/mod.rs 0.00% 4 Missing ⚠️
editoast/src/views/test_app.rs 88.88% 4 Missing ⚠️
editoast/src/map/layers.rs 66.66% 3 Missing ⚠️
editoast/src/client/infra_commands.rs 0.00% 2 Missing ⚠️
... and 2 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #9605      +/-   ##
============================================
- Coverage     42.49%   42.43%   -0.07%     
  Complexity     2272     2272              
============================================
  Files          1312     1314       +2     
  Lines        105608   105820     +212     
  Branches       3305     3305              
============================================
+ Hits          44881    44901      +20     
- Misses        58774    58966     +192     
  Partials       1953     1953              
Flag Coverage Δ
core 74.95% <ø> (ø)
editoast 73.26% <17.43%> (-0.47%) ⬇️
front 18.79% <ø> (ø)
gateway 2.18% <ø> (ø)
osrdyne 3.28% <ø> (ø)
railjson_generator 87.49% <ø> (ø)
tests 86.74% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added the area:editoast Work on Editoast Service label Nov 6, 2024
@leovalais leovalais marked this pull request as ready for review November 6, 2024 19:30
@leovalais leovalais requested a review from a team as a code owner November 6, 2024 19:30
@leovalais leovalais requested a review from Khoyo November 6, 2024 19:30
@leovalais leovalais force-pushed the lva/runserver-cli branch 2 times, most recently from 0bc1a49 to ac3ab65 Compare November 6, 2024 19:40
@leovalais
Copy link
Contributor Author

To merge after #9580, it shouldn't conflict, but just to be sure.

Copy link
Contributor

@Khoyo Khoyo left a comment

Choose a reason for hiding this comment

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

I have to ask... Why is it the client module if it contains the runserver cli?

@leovalais
Copy link
Contributor Author

@Khoyo We only have one binary for now. And it likely won't change until we have a proper split in crates. In which case it will be trivial to move the runserver CLI implementation into another bin.

The biggest part of this PR is actually to remove the dependency of client in views, which is plainly wrong according to our split, whether we have 1, 2, or more binaries.

Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

Looks fine, just a few minor comments.

editoast/src/valkey_utils.rs Outdated Show resolved Hide resolved
editoast/src/valkey_utils.rs Outdated Show resolved Hide resolved
editoast/src/valkey_utils.rs Outdated Show resolved Hide resolved
editoast/src/map/layers.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Khoyo Khoyo left a comment

Choose a reason for hiding this comment

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

Re: client, could we call it command? I really don't see how it is a client

Otherwise, LGTM. (But I only did a cursory review)

@leovalais
Copy link
Contributor Author

Agreed on the naming. It never really was a true "client" since it just runs commands on its own (no command forge a request that is sent to an editoast server). editoast_commands or editoast_cli would be better crate names indeed. Let's keep that in mind when we'll create it.

@leovalais
Copy link
Contributor Author

@woshilapin I rolled back the changes to the structure MapLayers since the max_zoom config is already available to each handler via the AppState.config. Diff in 85a983d (#9605). Let me know if that's ok so that I cleanup the git history a bit before merging.

@woshilapin
Copy link
Contributor

Looks good, even for the rolled back on MapLayers. You'll need to rebase because of this PR.

Introduces a `ServerConfig` struct to aggregate all server parameters.
We won't be able to use structs defined in `client` once it will be its
own crate.

Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
@leovalais leovalais enabled auto-merge November 14, 2024 21:38
@leovalais leovalais added this pull request to the merge queue Nov 14, 2024
Merged via the queue into dev with commit f7832c1 Nov 14, 2024
27 checks passed
@leovalais leovalais deleted the lva/runserver-cli branch November 14, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:editoast Work on Editoast Service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants