-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat(actix): New Register [INGEST-1494] #1421
Conversation
0fcb4d2
to
d15a3b6
Compare
lgtm |
@@ -36,7 +33,7 @@ impl Healthcheck { | |||
/// | |||
/// Panics if the service was not started using [`Healthcheck::start`] prior to this being used. | |||
pub fn from_registry() -> Addr<Self> { | |||
ADDRESS.read().as_ref().unwrap().clone() | |||
REGISTRY.get().unwrap().healthcheck.clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could make this method generic on Service
somehow. In C++ you could do std::get<T>
to access a tuple by type, in Rust I would not know how to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we wondered this as well but could not figure it out without dynamic dispatch (TypeId
) but that would slow this down. I'm not sure how to do this at compile time, but it so feels like this should be possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being late with this review. A few comments attached that can be addressed in a follow-up PR.
|
||
use relay_aws_extension::AwsExtension; | ||
use relay_config::Config; | ||
use relay_metrics::Aggregator; | ||
use relay_redis::RedisPool; | ||
use relay_system::Addr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please merge this input with the one below.
@@ -26,6 +28,8 @@ use crate::middlewares::{ | |||
}; | |||
use crate::{endpoints, utils}; | |||
|
|||
pub static REGISTRY: OnceBox<Registry> = OnceBox::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this non-public and hide the implementation detail that this uses a OnceBox
. Especially, this is considered infallible, and the unwrap
should be hidden behind an accessor method:
impl Registry {
fn get() -> &Self {
// some comment on why we think this is safe (once it is safe)
REGISTRY.get().unwrap()
}
}
@@ -105,6 +109,11 @@ impl From<Context<ServerErrorKind>> for ServerError { | |||
} | |||
} | |||
|
|||
#[derive(Clone, Debug)] | |||
pub struct Registry { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add documentation to this type.
@@ -36,7 +33,7 @@ impl Healthcheck { | |||
/// | |||
/// Panics if the service was not started using [`Healthcheck::start`] prior to this being used. | |||
pub fn from_registry() -> Addr<Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These static from_registry
functions were a workaround to replace the trait method on actix::SystemService
. Now that all our services are expected to be in the registry, we could move this to a mandatory Service::from_registry
trait method which enforces that this is implemented for every service in the same way. Also, this means that we no longer have to copy-paste the doc comment.
Alternatively, we might not even need from_registry
anymore. It's now as simple as:
Registry::get().healthcheck.send(_);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a ::from_registry()
forces you to import the service type, this variation makes everyone import the Registry
. The only argument I'm able to come up is that importing the service type makes it easier to discover in the code where the service is being used, so that would argue for keeping ::from_regsitry()
. +1 to making it a trait method though.
General
With the generic
Addr
in place since #1405 this PRmakes a new Register for the Services, which replaces
the current hardcoded solution.
Design choices
Arc<Option<Register>>
however, this didn't work as
Arc::new
is notconst fn
.To avoid this
lazy_static
was used however that inturn didn't work as
DerefMut
was required andlazy_static
only implementsDeref
.OnceBox
is currently used for the Register which isinitialised at the end of
ServiceState::start()
thisavoids the need for any
Options
but also could causeissues in the future as the current
registry
is createdat the beginning of the function and then gradually populated.
A similar approach might need to be used in case of issues.
Future Steps
Register
out of the way the next actor can be upgraded.A good choice for that is the
Upstream
Actor.