Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/sof-observer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,19 @@ use std::net::SocketAddr;
async fn main() -> Result<(), sof::runtime::RuntimeError> {
let setup = sof::runtime::RuntimeSetup::new()
.with_bind_addr(SocketAddr::from(([0, 0, 0, 0], 8001)))
.with_observability_bind_addr(SocketAddr::from(([127, 0, 0, 1], 9108)))
.with_startup_step_logs(true);
sof::runtime::run_async_with_setup(&setup).await
}
```

When `SOF_OBSERVABILITY_BIND` (or `RuntimeSetup::with_observability_bind_addr`) is set, the
packaged runtime also serves:

- `/metrics`
- `/healthz`
- `/readyz`

Or apply one typed gossip/ingest profile instead of stringly env overrides:

```rust
Expand Down
2 changes: 2 additions & 0 deletions crates/sof-observer/src/app/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
mod base;
mod common;
mod gossip;
mod observability;
mod relay;
mod repair;

pub use base::*;
pub use common::*;
pub use gossip::*;
pub use observability::*;
pub use relay::*;
pub use repair::*;
9 changes: 9 additions & 0 deletions crates/sof-observer/src/app/config/observability.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::net::SocketAddr;

use super::read_env_var;

/// Reads the runtime-owned observability bind address from `SOF_OBSERVABILITY_BIND`.
#[must_use]
pub fn read_observability_bind_addr() -> Option<SocketAddr> {
read_env_var("SOF_OBSERVABILITY_BIND").and_then(|value| value.parse::<SocketAddr>().ok())
}
64 changes: 58 additions & 6 deletions crates/sof-observer/src/app/runtime/entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,40 @@ async fn run_async_with_hosts_and_optional_shutdown(
derived_state_host: DerivedStateHost,
shutdown_signal: Option<ShutdownSignal>,
) -> Result<(), RuntimeEntrypointError> {
runloop::run_async_with_hosts(
let observability = if let Some(bind_addr) = read_observability_bind_addr() {
let service = RuntimeObservabilityService::start(
bind_addr,
extension_host.clone(),
derived_state_host.clone(),
)
.await
.map_err(|source| RuntimeEntrypointError::Runloop {
reason: format!("failed to start observability endpoint on {bind_addr}: {source}"),
})?;
tracing::info!(
bind_addr = %service.local_addr(),
"runtime observability endpoint enabled"
);
Some(service)
} else {
None
};
let observability_handle = observability
.as_ref()
.map(RuntimeObservabilityService::handle)
.cloned();
let result = runloop::run_async_with_hosts(
plugin_host,
extension_host,
derived_state_host,
shutdown_signal,
observability_handle,
)
.await
.map_err(|source| RuntimeEntrypointError::Runloop {
.await;
if let Some(service) = observability {
service.shutdown().await;
}
result.map_err(|source| RuntimeEntrypointError::Runloop {
reason: source.to_string(),
})
}
Expand Down Expand Up @@ -257,15 +283,41 @@ pub(crate) async fn run_async_with_hosts_and_kernel_bypass_ingress(
shutdown_signal: Option<ShutdownSignal>,
packet_ingest_rx: ingest::RawPacketBatchReceiver,
) -> Result<(), RuntimeEntrypointError> {
runloop::run_async_with_hosts_and_kernel_bypass_ingress(
let observability = if let Some(bind_addr) = read_observability_bind_addr() {
let service = RuntimeObservabilityService::start(
bind_addr,
extension_host.clone(),
derived_state_host.clone(),
)
.await
.map_err(|source| RuntimeEntrypointError::Runloop {
reason: format!("failed to start observability endpoint on {bind_addr}: {source}"),
})?;
tracing::info!(
bind_addr = %service.local_addr(),
"runtime observability endpoint enabled"
);
Some(service)
} else {
None
};
let observability_handle = observability
.as_ref()
.map(RuntimeObservabilityService::handle)
.cloned();
let result = runloop::run_async_with_hosts_and_kernel_bypass_ingress(
plugin_host,
extension_host,
derived_state_host,
shutdown_signal,
observability_handle,
packet_ingest_rx,
)
.await
.map_err(|source| RuntimeEntrypointError::Runloop {
.await;
if let Some(service) = observability {
service.shutdown().await;
}
result.map_err(|source| RuntimeEntrypointError::Runloop {
reason: source.to_string(),
})
}
2 changes: 2 additions & 0 deletions crates/sof-observer/src/app/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod bootstrap;
mod dataset;
mod entrypoints;
mod logging;
mod observability;
mod prelude;
mod runloop;
#[cfg(test)]
Expand All @@ -20,6 +21,7 @@ pub(crate) use entrypoints::{
run_async_with_plugin_host_and_kernel_bypass_ingress,
};
use logging::init_tracing;
use observability::{RuntimeObservabilityHandle, RuntimeObservabilityService};
use prelude::*;

#[cfg(feature = "gossip-bootstrap")]
Expand Down
Loading
Loading