Skip to content

Commit

Permalink
Merge pull request #10 from Anviking/anviking/integration-test-tweaks
Browse files Browse the repository at this point in the history
Tweak integration tests
  • Loading branch information
paweljakubas authored Nov 12, 2024
2 parents ab725ec + f32dded commit ca0cf6f
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 214 deletions.
115 changes: 50 additions & 65 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ futures-util = "0.3"
bytes = "1.7.2"

[dev-dependencies]
assert_cmd = "2"
goldenfile = "1.7.3"
tempfile = "3.4"
port-selector = "0.1.6"
6 changes: 3 additions & 3 deletions src/bin/oura/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ use clap::Parser;
use std::process;

mod console;
mod daemon;
mod run_daemon;

#[derive(Parser)]
#[clap(name = "Oura")]
#[clap(bin_name = "oura")]
#[clap(author, version, about, long_about = None)]
enum Oura {
Daemon(daemon::Args),
Daemon(run_daemon::Args),
}

fn main() {
let args = Oura::parse();

let result = match args {
Oura::Daemon(x) => daemon::run(&x),
Oura::Daemon(x) => run_daemon::run(&x),
};

if let Err(err) = &result {
Expand Down
85 changes: 85 additions & 0 deletions src/bin/oura/run_daemon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use gasket::daemon::Daemon;
use oura::framework::*;
use std::net::SocketAddr;
use std::sync::Arc;
use tracing::info;
use oura::daemon::{run_daemon, ConfigRoot, MetricsConfig};

use crate::console;

fn setup_tracing() {
tracing::subscriber::set_global_default(
tracing_subscriber::FmtSubscriber::builder()
.with_max_level(tracing::Level::DEBUG)
.finish(),
)
.unwrap();
}

async fn serve_prometheus(
daemon: Arc<Daemon>,
metrics: Option<MetricsConfig>,
) -> Result<(), Error> {
if let Some(metrics) = metrics {
info!("starting metrics exporter");
let runtime = daemon.clone();

let addr: SocketAddr = metrics
.address
.as_deref()
.unwrap_or("0.0.0.0:9186")
.parse()
.map_err(Error::parse)?;

gasket_prometheus::serve(addr, runtime).await;
}

Ok(())
}

pub fn run(args: &Args) -> Result<(), Error> {
if !args.tui {
setup_tracing();
}

let config = ConfigRoot::new(&args.config).map_err(Error::config)?;
let metrics = config.metrics.clone();

let daemon = run_daemon(config)?;

info!("oura is running");

let daemon = Arc::new(daemon);

let tokio_rt = tokio::runtime::Builder::new_multi_thread()
.enable_io()
.enable_time()
.build()
.unwrap();

let prometheus = tokio_rt.spawn(serve_prometheus(daemon.clone(), metrics));
let tui = tokio_rt.spawn(console::render(daemon.clone(), args.tui));

daemon.block();

info!("oura is stopping");

daemon.teardown();
prometheus.abort();
tui.abort();

Ok(())
}


#[derive(clap::Args)]
#[clap(author, version, about, long_about = None)]
pub struct Args {
/// config file to load by the daemon
#[clap(long, value_parser)]
config: Option<std::path::PathBuf>,

/// display the terminal UI
#[clap(long, action)]
tui: bool,
}
Loading

0 comments on commit ca0cf6f

Please sign in to comment.