Trace configured agent inventory sources and observation pruning
This commit is contained in:
1 file changed
+14
-2
@@ -1,5 +1,5 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tracing::{debug, info, instrument, warn};
|
use tracing::{Instrument, debug, info, instrument, warn};
|
||||||
|
|
||||||
use crate::config::AgentConfig;
|
use crate::config::AgentConfig;
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
@@ -69,22 +69,31 @@ async fn dispatch_inventory(req: InventoryRequest, config: &AgentConfig) -> Resu
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(name = "agent_inventory", skip_all, fields(neighbors = tracing::field::Empty, leases = tracing::field::Empty, observations = tracing::field::Empty, devices = tracing::field::Empty))]
|
||||||
pub async fn inventory_for_config(
|
pub async fn inventory_for_config(
|
||||||
req: InventoryRequest,
|
req: InventoryRequest,
|
||||||
config: &AgentConfig,
|
config: &AgentConfig,
|
||||||
) -> Result<wakey_core::DeviceInventory> {
|
) -> Result<wakey_core::DeviceInventory> {
|
||||||
let query = req.into_inventory_query();
|
let query = req.into_inventory_query();
|
||||||
let neighbors = wakey::wakey_linux::devices::query_neighbors(&query).await?;
|
// This configured path serves both commands and periodic snapshots; keep
|
||||||
|
// phase spans here so neither caller bypasses source timing.
|
||||||
|
let neighbors = wakey::wakey_linux::devices::query_neighbors(&query)
|
||||||
|
.instrument(tracing::info_span!("inventory_neighbors"))
|
||||||
|
.await?;
|
||||||
|
tracing::Span::current().record("neighbors", neighbors.len());
|
||||||
let leases = wakey::wakey_linux::dhcp::read_dhcp_leases_with_names_from_paths(
|
let leases = wakey::wakey_linux::dhcp::read_dhcp_leases_with_names_from_paths(
|
||||||
&config.dhcp_leases_path,
|
&config.dhcp_leases_path,
|
||||||
&config.observation_store_path,
|
&config.observation_store_path,
|
||||||
&config.mac_name_cache_path,
|
&config.mac_name_cache_path,
|
||||||
)
|
)
|
||||||
|
.instrument(tracing::info_span!("inventory_dhcp_leases"))
|
||||||
.await?;
|
.await?;
|
||||||
|
tracing::Span::current().record("leases", leases.len());
|
||||||
match wakey::wakey_linux::observations::prune_stale_observations_from_path(
|
match wakey::wakey_linux::observations::prune_stale_observations_from_path(
|
||||||
&config.observation_store_path,
|
&config.observation_store_path,
|
||||||
config.observation_retention_days,
|
config.observation_retention_days,
|
||||||
)
|
)
|
||||||
|
.instrument(tracing::info_span!("inventory_observation_prune"))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(removed) if removed > 0 => {
|
Ok(removed) if removed > 0 => {
|
||||||
@@ -98,6 +107,7 @@ pub async fn inventory_for_config(
|
|||||||
let observations = match wakey::wakey_linux::observations::list_local_observations_from_path(
|
let observations = match wakey::wakey_linux::observations::list_local_observations_from_path(
|
||||||
&config.observation_store_path,
|
&config.observation_store_path,
|
||||||
)
|
)
|
||||||
|
.instrument(tracing::info_span!("inventory_hook_store"))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(observations) => observations
|
Ok(observations) => observations
|
||||||
@@ -109,6 +119,7 @@ pub async fn inventory_for_config(
|
|||||||
Vec::new()
|
Vec::new()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
tracing::Span::current().record("observations", observations.len());
|
||||||
debug!(
|
debug!(
|
||||||
neighbors = neighbors.len(),
|
neighbors = neighbors.len(),
|
||||||
leases = leases.len(),
|
leases = leases.len(),
|
||||||
@@ -123,6 +134,7 @@ pub async fn inventory_for_config(
|
|||||||
&query,
|
&query,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
tracing::Span::current().record("devices", inventory.devices.len());
|
||||||
debug!(
|
debug!(
|
||||||
rows = inventory.devices.len(),
|
rows = inventory.devices.len(),
|
||||||
"dispatched inventory command"
|
"dispatched inventory command"
|
||||||
|
|||||||
Reference in new issue
Block a user