-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add .vscode to gitignore * Add proxy command (only starts webserver) * Add option to not add prometheus routes when starting web server * Implement option to proxy requests to prometheus * Resolve a clippy error * Add some comments * Update .gitignore Co-authored-by: Benno van den Berg <hatchan@users.noreply.github.com> * Update src/bin/am/commands/proxy.rs Co-authored-by: Benno van den Berg <hatchan@users.noreply.github.com> * Failed attempt to clone request to resolve lifetime issues * Revert "Failed attempt to clone request to resolve lifetime issues" This reverts commit 87f30a8. * Resolve clippy error * Update changelog --------- Co-authored-by: Benno van den Berg <hatchan@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
165 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use crate::server::start_web_server; | ||
use anyhow::{bail, Context, Result}; | ||
use clap::Parser; | ||
use directories::ProjectDirs; | ||
use std::net::SocketAddr; | ||
use tokio::select; | ||
use tokio::sync::watch; | ||
use tracing::info; | ||
use url::Url; | ||
|
||
#[derive(Parser, Clone)] | ||
pub struct CliArguments { | ||
/// The listen address for the web server of am. | ||
/// | ||
/// This includes am's HTTP API, the explorer and the proxy to the Prometheus, Gateway, etc. | ||
#[clap( | ||
short, | ||
long, | ||
env, | ||
default_value = "127.0.0.1:6789", | ||
alias = "explorer-address" | ||
)] | ||
listen_address: SocketAddr, | ||
|
||
/// The upstream Prometheus URL | ||
#[clap(long, env, alias = "prometheus-address")] | ||
prometheus_url: Option<Url>, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
struct Arguments { | ||
listen_address: SocketAddr, | ||
prometheus_url: Option<Url>, | ||
} | ||
|
||
impl Arguments { | ||
fn new(args: CliArguments) -> Self { | ||
Arguments { | ||
listen_address: args.listen_address, | ||
prometheus_url: args.prometheus_url, | ||
} | ||
} | ||
} | ||
|
||
pub async fn handle_command(args: CliArguments) -> Result<()> { | ||
let args = Arguments::new(args); | ||
|
||
// First let's retrieve the directory for our application to store data in. | ||
let project_dirs = | ||
ProjectDirs::from("", "autometrics", "am").context("Unable to determine home directory")?; | ||
let local_data = project_dirs.data_local_dir().to_owned(); | ||
|
||
// Make sure that the local data directory exists for our application. | ||
std::fs::create_dir_all(&local_data) | ||
.with_context(|| format!("Unable to create data directory: {:?}", local_data))?; | ||
|
||
let (tx, _) = watch::channel(None); | ||
|
||
// Start web server for hosting the explorer, am api and proxies to the enabled services. | ||
let web_server_task = async move { | ||
start_web_server(&args.listen_address, false, false, args.prometheus_url, tx).await | ||
}; | ||
|
||
select! { | ||
biased; | ||
|
||
_ = tokio::signal::ctrl_c() => { | ||
info!("SIGINT signal received, exiting..."); | ||
Ok(()) | ||
} | ||
|
||
Err(err) = web_server_task => { | ||
bail!("Web server exited with an error: {err:?}"); | ||
} | ||
|
||
else => { | ||
Ok(()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters