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

ref(registry): Remove global service registry #2022

Merged
merged 10 commits into from
Apr 13, 2023

Conversation

olksdr
Copy link
Contributor

@olksdr olksdr commented Apr 8, 2023

This PR finalizes migration to service dependencies injection instead of using the global registry.

In this part the changes mostly located in the endpoints, and their dependencies.

This also allowed to uncomment few ignored tests as they are no longer depend on the global registry or all the services.

related to: #1818
fixes: #1610

This PR finalizes migration to service dependencies injection instead of
using the global registry.

In this part the changes mostly localted in the endpoints, and their
dependencies.
@olksdr olksdr self-assigned this Apr 8, 2023
@olksdr olksdr requested a review from a team April 8, 2023 13:23
@jan-auer jan-auer changed the title ref(registry): Remove global service registry. ref(registry): Remove global service registry Apr 11, 2023
@@ -77,7 +78,7 @@ where
B: axum::body::HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<axum::BoxError>,
S: Send + Sync,
S: Send + Sync + ServiceRegistry,
Copy link
Member

Choose a reason for hiding this comment

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

Instead of this trait, you can make this non-generic and require ServiceState. This is also what we do in a few other extractors.

@@ -87,6 +90,7 @@ pub fn create_runtime(name: &str, threads: usize) -> Runtime {
pub struct ServiceState {
config: Arc<Config>,
Copy link
Member

Choose a reason for hiding this comment

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

ServiceState is cloned very often by axum, and also from us. Cloning it is somewhat expensive now, since we clone a lot of fields: All the runtimes, and then all fields in the registry. It would now make sense to change the internals of ServiceState to something like:

#[derive(Clone, Debug)]
struct ServiceState {
    inner: Arc<StateInner>,
}

impl ServiceState {
    // accessor methods for every service here, accessing through `self.inner.*`
}

#[derive(Debug)] // no Clone!
struct StateInner {
    // all Addrs here
    // all runtimes here
    // buffer guard
}

Copy link
Contributor

@iker-barriocanal iker-barriocanal left a comment

Choose a reason for hiding this comment

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

Out of scope for this PR, but test_store seems to me that it's related to tests. For this approach the PR looks good, a couple of questions to discuss wrt to the approach.

let project_cache = services.project_cache.clone();
let outcome_aggregator = services.outcome_aggregator.clone();
let test_store = services.test_store.clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that we clone all the services. Is it to avoid issues with a mutable reference? Or, why are we doing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The clone is very cheap here and in fact it's all the same objects, which just contains the inner rx channel and the counter for number of messages in the queue. This way each service can own the addresses of the services its communicate with.

@olksdr olksdr requested review from iker-barriocanal, jan-auer and a team April 11, 2023 10:43
@olksdr olksdr merged commit 3cffc8a into master Apr 13, 2023
@olksdr olksdr deleted the chore/migrate-more-global-registry branch April 13, 2023 08:00
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.

Fix tests depending on broken SystemRegistry behavior
3 participants