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

Add CLI parameter for ClickHouse IP address to oxdb #1245

Merged
merged 1 commit into from
Jun 30, 2022
Merged
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
49 changes: 38 additions & 11 deletions oximeter/db/src/bin/oxdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use oximeter::{
};
use oximeter_db::{query, Client, DbWrite};
use slog::{debug, info, o, Drain, Level, Logger};
use std::net::IpAddr;
use std::net::SocketAddr;
use uuid::Uuid;

Expand Down Expand Up @@ -53,6 +54,10 @@ fn level_from_str(s: &str) -> Result<Level, anyhow::Error> {
/// Tools for developing with the Oximeter timeseries database.
#[derive(Debug, Parser)]
struct OxDb {
/// IP address at which to connect to the database
#[clap(short, long, default_value = "::1")]
address: IpAddr,

/// Port on which to connect to the database
#[clap(short, long, default_value = "8123", action)]
port: u16,
Expand Down Expand Up @@ -135,8 +140,12 @@ enum Subcommand {
},
}

async fn make_client(port: u16, log: &Logger) -> Result<Client, anyhow::Error> {
let address = SocketAddr::new("::1".parse().unwrap(), port);
async fn make_client(
address: IpAddr,
port: u16,
log: &Logger,
) -> Result<Client, anyhow::Error> {
let address = SocketAddr::new(address, port);
let client = Client::new(address, &log);
client
.init_db()
Expand Down Expand Up @@ -199,12 +208,13 @@ async fn insert_samples(
}

async fn populate(
address: IpAddr,
port: u16,
log: Logger,
args: PopulateArgs,
) -> Result<(), anyhow::Error> {
info!(log, "populating Oximeter database");
let client = make_client(port, &log).await?;
let client = make_client(address, port, &log).await?;
let n_timeseries = args.n_projects * args.n_instances * args.n_cpus;
debug!(
log,
Expand Down Expand Up @@ -251,20 +261,25 @@ async fn populate(
Ok(())
}

async fn wipe_db(port: u16, log: Logger) -> Result<(), anyhow::Error> {
let client = make_client(port, &log).await?;
async fn wipe_db(
address: IpAddr,
port: u16,
log: Logger,
) -> Result<(), anyhow::Error> {
let client = make_client(address, port, &log).await?;
client.wipe_db().await.context("Failed to wipe database")
}

async fn query(
address: IpAddr,
port: u16,
log: Logger,
timeseries_name: String,
filters: Vec<String>,
start: Option<query::Timestamp>,
end: Option<query::Timestamp>,
) -> Result<(), anyhow::Error> {
let client = make_client(port, &log).await?;
let client = make_client(address, port, &log).await?;
let filters = filters.iter().map(|s| s.as_str()).collect::<Vec<_>>();
let timeseries = client
.select_timeseries_with(
Expand All @@ -291,9 +306,13 @@ async fn main() {
match args.cmd {
Subcommand::Describe => describe_data(),
Subcommand::Populate { populate_args } => {
populate(args.port, log, populate_args).await.unwrap();
populate(args.address, args.port, log, populate_args)
.await
.unwrap();
}
Subcommand::Wipe => {
wipe_db(args.address, args.port, log).await.unwrap()
}
Subcommand::Wipe => wipe_db(args.port, log).await.unwrap(),
Subcommand::Query {
timeseries_name,
filters,
Expand All @@ -312,9 +331,17 @@ async fn main() {
(_, Some(end)) => Some(query::Timestamp::Exclusive(end)),
(None, None) => None,
};
query(args.port, log, timeseries_name, filters, start, end)
.await
.unwrap();
query(
args.address,
args.port,
log,
timeseries_name,
filters,
start,
end,
)
.await
.unwrap();
}
}
}