Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak integration tests #10

Merged
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
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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