Skip to content
Draft
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
4 changes: 3 additions & 1 deletion orb-connd/src/connectivity_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::service::{self, ConndService, ProfileStorage};
use crate::systemd::Systemd;
use crate::{modem, reporters, OrbCapabilities};
use color_eyre::eyre::{Context, Result};
use orb_dogd::MetricEmitter;
use orb_dogd::{MetricEmitter, NO_TAGS};
use orb_info::orb_os_release::OrbOsRelease;
use speare::mini::{self, OnErr};
use speare::Backoff;
Expand Down Expand Up @@ -99,6 +99,8 @@ pub async fn program(
.await?;

if let OrbCapabilities::CellularAndWifi = cap {
let _ = statsd_client.gauge("orb.platform.connd.lte_capable", 1.0, NO_TAGS);

speare
.task_with()
.args(modem::Args {
Expand Down
46 changes: 38 additions & 8 deletions orb-connd/src/reporters/active_connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ use color_eyre::eyre::{bail, eyre, Context, ContextCompat};
use color_eyre::Result;
use futures::StreamExt;
use oes::NetworkInterface;
use orb_dogd::MetricEmitter;
use speare::mini;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
use tokio::{fs, time};
use tracing::{error, info, warn};

pub struct Args {
pub struct Args<M: MetricEmitter> {
pub nm: NetworkManager,
pub resolved: Resolved,
pub zsender: zenorb::Sender,
pub procfs: PathBuf,
pub sysfs: PathBuf,
pub metrics: Arc<M>,
}

pub async fn report(ctx: mini::Ctx<Args>) -> Result<()> {
pub async fn report<M>(ctx: mini::Ctx<Args<M>>) -> Result<()>
where
M: MetricEmitter,
{
info!("starting active connections reporter");

async {
Expand Down Expand Up @@ -56,6 +62,8 @@ pub async fn report(ctx: mini::Ctx<Args>) -> Result<()> {
.await
.wrap_err("building active connections report")?;

emit_metrics(&report, ctx.metrics.as_ref());

publish_report(&ctx, report)
.await
.wrap_err("publishing active connections report")?;
Expand Down Expand Up @@ -99,6 +107,8 @@ pub async fn report(ctx: mini::Ctx<Args>) -> Result<()> {
.await
.wrap_err("building active connections report")?;

emit_metrics(&report, ctx.metrics.as_ref());

publish_report(&ctx, report)
.await
.wrap_err("publishing active connections report")?;
Expand All @@ -113,12 +123,15 @@ pub async fn report(ctx: mini::Ctx<Args>) -> Result<()> {
}

/// build report based on NM inputs and system inspection
async fn build_report(
async fn build_report<M>(
primary: &Option<network_manager::Connection>,
connection_state: ConnectionState,
active_conns: &Vec<ActiveConn>,
ctx: &mini::Ctx<Args>,
) -> Result<ActiveConnections> {
ctx: &mini::Ctx<Args<M>>,
) -> Result<ActiveConnections>
where
M: MetricEmitter,
{
let connectivity_uri = ctx.nm.connectivity_check_uri().await?;
let hostname = hostname_from_uri(&connectivity_uri).map(str::to_string);
let mut connections = Vec::new();
Expand Down Expand Up @@ -197,10 +210,27 @@ struct Connection {
http_check: Result<ConnHttpCheck, String>,
}

async fn publish_report(
ctx: &mini::Ctx<Args>,
fn emit_metrics(report: &ActiveConnections, metrics: &impl MetricEmitter) {
for c in &report.connections {
if c.primary {
let _ = metrics.gauge(
"orb.platform.connd.primary_conn",
1.0,
[format!("kind:{}", c.iface)],
);

return;
}
}
}

async fn publish_report<M>(
ctx: &mini::Ctx<Args<M>>,
report: ActiveConnections,
) -> Result<()> {
) -> Result<()>
where
M: MetricEmitter,
{
info!("{report:#?}");

let report: oes::ActiveConnections = report.try_into()?;
Expand Down
1 change: 1 addition & 0 deletions orb-connd/src/reporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub async fn spawn(
zsender,
sysfs,
procfs,
metrics: statsd.clone(),
})
.on_err(static_backoff(15))
.spawn(active_connections::report)?;
Expand Down
Loading