Skip to content

Commit 09e43d8

Browse files
Fixes around feature-flagging, particularly in oxql, as well as uuid-kinds, sled-storage
1 parent 5671cd5 commit 09e43d8

File tree

15 files changed

+44
-39
lines changed

15 files changed

+44
-39
lines changed

nexus/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ num-integer.workspace = true
5151
once_cell.workspace = true
5252
openssl.workspace = true
5353
oximeter-client.workspace = true
54-
oximeter-db.workspace = true
54+
oximeter-db = { workspace = true, default-features = false, features = [ "oxql" ] }
5555
oxnet.workspace = true
5656
parse-display.workspace = true
5757
paste.workspace = true

oximeter/db/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ clap.workspace = true
1919
dropshot.workspace = true
2020
futures.workspace = true
2121
highway.workspace = true
22+
num.workspace = true
2223
omicron-common.workspace = true
2324
omicron-workspace-hack.workspace = true
2425
oximeter.workspace = true
@@ -45,10 +46,6 @@ optional = true
4546
workspace = true
4647
optional = true
4748

48-
[dependencies.num]
49-
workspace = true
50-
optional = true
51-
5249
[dependencies.peg]
5350
workspace = true
5451
optional = true
@@ -91,6 +88,7 @@ indexmap.workspace = true
9188
itertools.workspace = true
9289
omicron-test-utils.workspace = true
9390
slog-dtrace.workspace = true
91+
sqlformat.workspace = true
9492
sqlparser.workspace = true
9593
strum.workspace = true
9694
tempfile.workspace = true
@@ -107,7 +105,6 @@ sql = [
107105
]
108106
oxql = [
109107
"dep:crossterm",
110-
"dep:num",
111108
"dep:peg",
112109
"dep:reedline",
113110
"dep:tabled",

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

Lines changed: 3 additions & 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;
@@ -148,6 +148,7 @@ enum Subcommand {
148148
},
149149

150150
/// Enter the Oximeter Query Language shell for interactive querying.
151+
#[cfg(feature = "oxql")]
151152
Oxql {
152153
#[clap(flatten)]
153154
opts: oximeter_db::shells::oxql::ShellOptions,
@@ -350,6 +351,7 @@ async fn main() -> anyhow::Result<()> {
350351
oximeter_db::shells::sql::shell(args.address, args.port, log, opts)
351352
.await?
352353
}
354+
#[cfg(feature = "oxql")]
353355
Subcommand::Oxql { opts } => {
354356
oximeter_db::shells::oxql::shell(args.address, args.port, log, opts)
355357
.await?

oximeter/db/src/client/mod.rs

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

99
pub(crate) mod dbwrite;
10+
#[cfg(any(feature = "oxql", test))]
1011
pub(crate) mod oxql;
1112
pub(crate) mod query_summary;
1213
#[cfg(any(feature = "sql", test))]

oximeter/db/src/lib.rs

Lines changed: 21 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,11 @@ 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, SocketAddr};
2932
use std::num::NonZeroU32;
3033
use std::path::PathBuf;
3134
use thiserror::Error;
@@ -40,6 +43,7 @@ pub mod shells;
4043
#[cfg(any(feature = "sql", test))]
4144
pub mod sql;
4245

46+
#[cfg(any(feature = "oxql", test))]
4347
pub use client::oxql::OxqlResult;
4448
pub use client::query_summary::QuerySummary;
4549
pub use client::Client;
@@ -142,10 +146,12 @@ pub enum Error {
142146
#[error("SQL error")]
143147
Sql(#[from] sql::Error),
144148

149+
#[cfg(any(feature = "oxql", test))]
145150
#[error(transparent)]
146151
Oxql(oxql::Error),
147152
}
148153

154+
#[cfg(any(feature = "oxql", test))]
149155
impl From<crate::oxql::Error> for Error {
150156
fn from(e: crate::oxql::Error) -> Self {
151157
Error::Oxql(e)
@@ -239,6 +245,21 @@ pub struct TimeseriesPageSelector {
239245
pub offset: NonZeroU32,
240246
}
241247

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

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

oximeter/db/src/oxql/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use self::table::Table;
1919
pub use self::table::Timeseries;
2020
pub use anyhow::Error;
2121

22-
// Format a PEG parsing error into a nice anyhow error.
22+
/// Format a PEG parsing error into a nice anyhow error.
2323
fn fmt_parse_error(source: &str, err: PegError<LineCol>) -> Error {
2424
use std::fmt::Write;
2525
let mut out =

oximeter/db/src/query.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,12 @@ impl FieldSelector {
371371
}
372372
}
373373

374-
/// A stringly-typed selector for finding fields by name and comparsion with a given value.
374+
/// A stringly-typed selector for finding fields by name and comparsion with a
375+
/// given value.
375376
///
376-
/// This is used internally to parse comparisons written as strings, such as from the `oxdb`
377-
/// command-line tool or from another external source (Nexus API, for example).
377+
/// This is used internally to parse comparisons written as strings, such as
378+
/// from the `oxdb` command-line tool or from another external
379+
/// source (Nexus API, for example).
378380
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
379381
pub struct StringFieldSelector {
380382
name: String,

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;

oximeter/instruments/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ http-instruments = [
3636
"dep:oximeter",
3737
"dep:schemars",
3838
"dep:serde",
39+
"dep:slog",
3940
"dep:uuid"
4041
]
4142
kstat = [

sled-storage/src/manager_test_harness.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl Drop for StorageManagerTestHarness {
123123
impl StorageManagerTestHarness {
124124
/// Creates a new StorageManagerTestHarness with no associated disks.
125125
pub async fn new(log: &Logger) -> Self {
126+
#[cfg(all(test, feature = "testing"))]
126127
illumos_utils::USE_MOCKS.store(false, Ordering::SeqCst);
127128
let tmp = camino_tempfile::tempdir_in("/var/tmp")
128129
.expect("Failed to make temporary directory");

sled-storage/src/pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Pool {
2727
}
2828

2929
/// Return a Pool consisting of fake info
30-
#[cfg(feature = "testing")]
30+
#[cfg(all(test, feature = "testing"))]
3131
pub fn new_with_fake_info(name: ZpoolName, parent: DiskIdentity) -> Pool {
3232
let info = ZpoolInfo::new_hardcoded(name.to_string());
3333
Pool { name, info, parent }

uuid-kinds/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ paste.workspace = true
1919
[features]
2020
default = ["std"]
2121
serde = ["newtype-uuid/serde"]
22-
schemars08 = ["newtype-uuid/schemars08", "schemars"]
22+
schemars08 = ["newtype-uuid/schemars08", "schemars", "std"]
2323
std = ["newtype-uuid/std"]
2424
uuid-v4 = ["newtype-uuid/v4"]

uuid-kinds/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
#![cfg_attr(not(feature = "std"), no_std)]
6-
75
//! A registry for UUID kinds used in Omicron and related projects.
86
//!
97
//! See this crate's `README.adoc` for more information.
108
9+
#![cfg_attr(not(feature = "std"), no_std)]
10+
1111
// Export these types so that other users don't have to pull in newtype-uuid.
1212
#[doc(no_inline)]
1313
pub use newtype_uuid::{

0 commit comments

Comments
 (0)