pub struct StatsServer { /* private fields */ }Expand description
A bound TCP listener serving the stats endpoint.
Construct via StatsServer::bind then call
StatsServer::run to accept connections in a loop, or
StatsServer::accept_one for one-shot tests.
§Examples
use std::sync::Arc;
use dynomite::stats::{Snapshot, StatsServer};
use parking_lot::Mutex;
let sink = Arc::new(Mutex::new(Snapshot::default()));
let server = StatsServer::bind("127.0.0.1:0".parse().unwrap(), sink).await?;
let _addr = server.local_addr()?;Implementations§
Source§impl StatsServer
impl StatsServer
Sourcepub async fn bind(
addr: SocketAddr,
source: Arc<Mutex<Snapshot>>,
) -> Result<Self>
pub async fn bind( addr: SocketAddr, source: Arc<Mutex<Snapshot>>, ) -> Result<Self>
Bind a listener at addr. Returns the bound server alongside
its actual local address (useful when binding to port 0).
§Examples
use std::sync::Arc;
use dynomite::stats::{Snapshot, StatsServer};
use parking_lot::Mutex;
let sink = Arc::new(Mutex::new(Snapshot::default()));
let _server = StatsServer::bind("127.0.0.1:0".parse().unwrap(), sink).await?;Sourcepub fn with_cluster_info_provider(self, provider: ClusterInfoProvider) -> Self
pub fn with_cluster_info_provider(self, provider: ClusterInfoProvider) -> Self
Attach a ClusterInfoProvider so the server answers
GET /cluster-info.txt with a freshly assembled
snapshot. When no provider is registered the route
returns 503 Service Unavailable.
§Examples
use std::sync::Arc;
use dynomite::admin::cluster_info::ClusterInfoSnapshot;
use dynomite::stats::{Snapshot, StatsServer};
use parking_lot::Mutex;
let sink = Arc::new(Mutex::new(Snapshot::default()));
let server = StatsServer::bind("127.0.0.1:0".parse().unwrap(), sink)
.await?
.with_cluster_info_provider(Arc::new(ClusterInfoSnapshot::synthetic));
drop(server);Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local socket address the server is listening on.
§Examples
use std::sync::Arc;
use dynomite::stats::{Snapshot, StatsServer};
use parking_lot::Mutex;
let sink = Arc::new(Mutex::new(Snapshot::default()));
let server = StatsServer::bind("127.0.0.1:0".parse().unwrap(), sink).await?;
let addr = server.local_addr()?;
assert!(addr.port() != 0);Sourcepub async fn accept_one(&self) -> Result<()>
pub async fn accept_one(&self) -> Result<()>
Accept a single connection, serve one HTTP/1.1 request, and return.
§Examples
use std::sync::Arc;
use dynomite::stats::{Snapshot, StatsServer};
use parking_lot::Mutex;
let sink = Arc::new(Mutex::new(Snapshot::default()));
let server = StatsServer::bind("127.0.0.1:0".parse().unwrap(), sink).await?;
server.accept_one().await?;Sourcepub async fn run(self) -> Result<()>
pub async fn run(self) -> Result<()>
Run the accept loop until cancelled. Each connection is handled on a fresh task so a slow client cannot stall the listener.
§Examples
use std::sync::Arc;
use dynomite::stats::{Snapshot, StatsServer};
use parking_lot::Mutex;
let sink = Arc::new(Mutex::new(Snapshot::default()));
let server = StatsServer::bind("127.0.0.1:0".parse().unwrap(), sink).await?;
let _ = tokio::spawn(async move { server.run().await });Auto Trait Implementations§
impl !Freeze for StatsServer
impl !RefUnwindSafe for StatsServer
impl Send for StatsServer
impl Sync for StatsServer
impl Unpin for StatsServer
impl UnsafeUnpin for StatsServer
impl !UnwindSafe for StatsServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more