Skip to content

Commit 1b1fa67

Browse files
review: move make_client
1 parent 0228e40 commit 1b1fa67

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

oximeter/db/src/bin/oxdb/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use oximeter::{
1414
types::{Cumulative, Sample},
1515
Metric, Target,
1616
};
17-
use oximeter_db::{query, shells::make_client, Client, DbWrite};
17+
use oximeter_db::{make_client, query, Client, DbWrite};
1818
use slog::{debug, info, o, Drain, Level, Logger};
1919
use std::net::IpAddr;
2020
use uuid::Uuid;

oximeter/db/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// Copyright 2024 Oxide Computer Company
88

99
use crate::query::StringFieldSelector;
10+
use anyhow::Context as _;
1011
use chrono::DateTime;
1112
use chrono::Utc;
1213
use dropshot::EmptyScanParams;
@@ -23,9 +24,12 @@ pub use oximeter::Sample;
2324
use schemars::JsonSchema;
2425
use serde::Deserialize;
2526
use serde::Serialize;
27+
use slog::Logger;
2628
use std::collections::BTreeMap;
2729
use std::convert::TryFrom;
2830
use std::io;
31+
use std::net::IpAddr;
32+
use std::net::SocketAddr;
2933
use std::num::NonZeroU32;
3034
use std::path::PathBuf;
3135
use thiserror::Error;
@@ -242,6 +246,22 @@ pub struct TimeseriesPageSelector {
242246
pub offset: NonZeroU32,
243247
}
244248

249+
/// Create a client to the timeseries database, and ensure the database exists.
250+
#[cfg(any(feature = "oxql", feature = "sql", feature = "oxdb", test))]
251+
pub async fn make_client(
252+
address: IpAddr,
253+
port: u16,
254+
log: &Logger,
255+
) -> Result<Client, anyhow::Error> {
256+
let address = SocketAddr::new(address, port);
257+
let client = Client::new(address, &log);
258+
client
259+
.init_single_node_db()
260+
.await
261+
.context("Failed to initialize timeseries database")?;
262+
Ok(client)
263+
}
264+
245265
pub(crate) type TimeseriesKey = u64;
246266

247267
// TODO-cleanup: Add the timeseries version in to the computation of the key.

oximeter/db/src/shells/mod.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
// Copyright 2024 Oxide Computer Company
88

99
use crate::Client;
10-
use crate::DbWrite as _;
11-
use anyhow::Context as _;
1210
use dropshot::EmptyScanParams;
1311
use dropshot::WhichPage;
1412
use oximeter::TimeseriesSchema;
15-
use slog::Logger;
16-
use std::net::IpAddr;
17-
use std::net::SocketAddr;
1813

1914
#[cfg(any(feature = "oxql", test))]
2015
pub mod oxql;
@@ -130,21 +125,6 @@ pub async fn describe_timeseries(
130125
Ok(())
131126
}
132127

133-
/// Create a client to the timeseries database, and ensure the database exists.
134-
pub async fn make_client(
135-
address: IpAddr,
136-
port: u16,
137-
log: &Logger,
138-
) -> Result<Client, anyhow::Error> {
139-
let address = SocketAddr::new(address, port);
140-
let client = Client::new(address, &log);
141-
client
142-
.init_single_node_db()
143-
.await
144-
.context("Failed to initialize timeseries database")?;
145-
Ok(client)
146-
}
147-
148128
/// Prepare the columns for a timeseries or virtual table.
149129
pub(crate) fn prepare_columns(
150130
schema: &TimeseriesSchema,

oximeter/db/src/shells/oxql.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
77
// Copyright 2024 Oxide Computer
88

9-
use super::{list_timeseries, make_client, prepare_columns};
10-
use crate::{oxql::Table, Client, OxqlResult};
9+
use super::{list_timeseries, prepare_columns};
10+
use crate::{make_client, oxql::Table, Client, OxqlResult};
1111
use clap::Args;
1212
use crossterm::style::Stylize;
1313
use reedline::DefaultPrompt;

oximeter/db/src/shells/sql.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
77
// Copyright 2024 Oxide Computer Company
88

9-
use super::{make_client, prepare_columns};
9+
use super::prepare_columns;
1010
use crate::sql::{function_allow_list, QueryResult, Table};
11-
use crate::{Client, QuerySummary};
11+
use crate::{make_client, Client, QuerySummary};
1212
use clap::Args;
1313
use dropshot::EmptyScanParams;
1414
use dropshot::WhichPage;

0 commit comments

Comments
 (0)