-
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
Changes from all commits
02f3758
f9c4f49
89ec114
de485b9
730621f
1084418
50b314b
3c7b284
9640382
2123638
b754a67
f8d411e
7ce0ef0
d15a3b6
ebae77d
ff9b9b5
2c6c435
8fb8888
8a6ae80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ use std::sync::atomic::{AtomicBool, Ordering}; | |
use std::sync::Arc; | ||
|
||
use actix::SystemService; | ||
use parking_lot::RwLock; | ||
use tokio::sync::{mpsc, oneshot}; | ||
|
||
use relay_config::{Config, RelayMode}; | ||
|
@@ -11,12 +10,10 @@ use relay_statsd::metric; | |
use relay_system::{compat, Controller}; | ||
|
||
use crate::actors::upstream::{IsAuthenticated, IsNetworkOutage, UpstreamRelay}; | ||
use crate::service::REGISTRY; | ||
use crate::statsd::RelayGauges; | ||
use relay_system::{Addr, Service, ServiceMessage}; | ||
|
||
/// Singleton of the `Healthcheck` service. | ||
static ADDRESS: RwLock<Option<Addr<Healthcheck>>> = RwLock::new(None); | ||
|
||
#[derive(Debug)] | ||
pub struct Healthcheck { | ||
is_shutting_down: AtomicBool, | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we could make this method generic on There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( |
||
} | ||
|
||
/// Creates a new instance of the Healthcheck service. | ||
|
@@ -88,7 +85,6 @@ impl Healthcheck { | |
let (tx, mut rx) = mpsc::unbounded_channel::<HealthcheckMessages>(); | ||
|
||
let addr = Addr { tx }; | ||
*ADDRESS.write() = Some(addr.clone()); | ||
|
||
let service = Arc::new(self); | ||
let main_service = service.clone(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ use actix_web::{server, App}; | |
use failure::ResultExt; | ||
use failure::{Backtrace, Context, Fail}; | ||
use listenfd::ListenFd; | ||
use once_cell::race::OnceBox; | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Please merge this input with the one below. |
||
use relay_system::{Configure, Controller}; | ||
|
||
use crate::actors::envelopes::{BufferGuard, EnvelopeManager}; | ||
|
@@ -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 commentThe 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 impl Registry {
fn get() -> &Self {
// some comment on why we think this is safe (once it is safe)
REGISTRY.get().unwrap()
}
} |
||
|
||
/// Common error type for the relay server. | ||
#[derive(Debug)] | ||
pub struct ServerError { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Please add documentation to this type. |
||
pub healthcheck: Addr<Healthcheck>, | ||
} | ||
|
||
/// Server state. | ||
#[derive(Clone)] | ||
pub struct ServiceState { | ||
|
@@ -150,7 +159,7 @@ impl ServiceState { | |
let project_cache = Arbiter::start(|_| project_cache); | ||
registry.set(project_cache.clone()); | ||
|
||
Healthcheck::new(config.clone()).start(); // TODO(tobias): Registry is implicit | ||
let healthcheck = Healthcheck::new(config.clone()).start(); | ||
registry.set(RelayCache::new(config.clone()).start()); | ||
|
||
let aggregator = Aggregator::new(config.aggregator_config(), project_cache.recipient()); | ||
|
@@ -162,6 +171,8 @@ impl ServiceState { | |
} | ||
} | ||
|
||
REGISTRY.set(Box::new(Registry { healthcheck })).unwrap(); | ||
|
||
Ok(ServiceState { | ||
buffer_guard: buffer, | ||
config, | ||
|
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 onactix::SystemService
. Now that all our services are expected to be in the registry, we could move this to a mandatoryService::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: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 theRegistry
. 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.