Skip to content

Fixes around feature-flagging, particularly in oxql, as well as uuid-kinds, sled-storage #6036

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

Merged
merged 1 commit into from
Jul 10, 2024
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
2 changes: 1 addition & 1 deletion nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ num-integer.workspace = true
once_cell.workspace = true
openssl.workspace = true
oximeter-client.workspace = true
oximeter-db.workspace = true
oximeter-db = { workspace = true, default-features = false, features = [ "oxql" ] }
oxnet.workspace = true
parse-display.workspace = true
paste.workspace = true
Expand Down
7 changes: 2 additions & 5 deletions oximeter/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ clap.workspace = true
dropshot.workspace = true
futures.workspace = true
highway.workspace = true
num.workspace = true
omicron-common.workspace = true
omicron-workspace-hack.workspace = true
oximeter.workspace = true
Expand All @@ -45,10 +46,6 @@ optional = true
workspace = true
optional = true

[dependencies.num]
workspace = true
optional = true

[dependencies.peg]
workspace = true
optional = true
Expand Down Expand Up @@ -91,6 +88,7 @@ indexmap.workspace = true
itertools.workspace = true
omicron-test-utils.workspace = true
slog-dtrace.workspace = true
sqlformat.workspace = true
sqlparser.workspace = true
strum.workspace = true
tempfile.workspace = true
Expand All @@ -107,7 +105,6 @@ sql = [
]
oxql = [
"dep:crossterm",
"dep:num",
"dep:peg",
"dep:reedline",
"dep:tabled",
Expand Down
4 changes: 3 additions & 1 deletion oximeter/db/src/bin/oxdb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use oximeter::{
types::{Cumulative, Sample},
Metric, Target,
};
use oximeter_db::{query, shells::make_client, Client, DbWrite};
use oximeter_db::{make_client, query, Client, DbWrite};
use slog::{debug, info, o, Drain, Level, Logger};
use std::net::IpAddr;
use uuid::Uuid;
Expand Down Expand Up @@ -148,6 +148,7 @@ enum Subcommand {
},

/// Enter the Oximeter Query Language shell for interactive querying.
#[cfg(feature = "oxql")]
Oxql {
#[clap(flatten)]
opts: oximeter_db::shells::oxql::ShellOptions,
Expand Down Expand Up @@ -350,6 +351,7 @@ async fn main() -> anyhow::Result<()> {
oximeter_db::shells::sql::shell(args.address, args.port, log, opts)
.await?
}
#[cfg(feature = "oxql")]
Subcommand::Oxql { opts } => {
oximeter_db::shells::oxql::shell(args.address, args.port, log, opts)
.await?
Expand Down
1 change: 1 addition & 0 deletions oximeter/db/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Copyright 2024 Oxide Computer Company

pub(crate) mod dbwrite;
#[cfg(any(feature = "oxql", test))]
pub(crate) mod oxql;
pub(crate) mod query_summary;
#[cfg(any(feature = "sql", test))]
Expand Down
21 changes: 21 additions & 0 deletions oximeter/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Copyright 2024 Oxide Computer Company

use crate::query::StringFieldSelector;
use anyhow::Context as _;
use chrono::DateTime;
use chrono::Utc;
use dropshot::EmptyScanParams;
Expand All @@ -23,9 +24,11 @@ pub use oximeter::Sample;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use slog::Logger;
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::io;
use std::net::{IpAddr, SocketAddr};
use std::num::NonZeroU32;
use std::path::PathBuf;
use thiserror::Error;
Expand All @@ -40,6 +43,7 @@ pub mod shells;
#[cfg(any(feature = "sql", test))]
pub mod sql;

#[cfg(any(feature = "oxql", test))]
pub use client::oxql::OxqlResult;
pub use client::query_summary::QuerySummary;
pub use client::Client;
Expand Down Expand Up @@ -142,10 +146,12 @@ pub enum Error {
#[error("SQL error")]
Sql(#[from] sql::Error),

#[cfg(any(feature = "oxql", test))]
#[error(transparent)]
Oxql(oxql::Error),
}

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

/// Create a client to the timeseries database, and ensure the database exists.
pub 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_single_node_db()
.await
.context("Failed to initialize timeseries database")?;
Ok(client)
}

pub(crate) type TimeseriesKey = u64;

// TODO-cleanup: Add the timeseries version in to the computation of the key.
Expand Down
2 changes: 1 addition & 1 deletion oximeter/db/src/oxql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use self::table::Table;
pub use self::table::Timeseries;
pub use anyhow::Error;

// Format a PEG parsing error into a nice anyhow error.
/// Format a PEG parsing error into a nice anyhow error.
fn fmt_parse_error(source: &str, err: PegError<LineCol>) -> Error {
use std::fmt::Write;
let mut out =
Expand Down
8 changes: 5 additions & 3 deletions oximeter/db/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,12 @@ impl FieldSelector {
}
}

/// A stringly-typed selector for finding fields by name and comparsion with a given value.
/// A stringly-typed selector for finding fields by name and comparsion with a
/// given value.
///
/// This is used internally to parse comparisons written as strings, such as from the `oxdb`
/// command-line tool or from another external source (Nexus API, for example).
/// This is used internally to parse comparisons written as strings, such as
/// from the `oxdb` command-line tool or from another external
/// source (Nexus API, for example).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct StringFieldSelector {
name: String,
Expand Down
20 changes: 0 additions & 20 deletions oximeter/db/src/shells/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
// Copyright 2024 Oxide Computer Company

use crate::Client;
use crate::DbWrite as _;
use anyhow::Context as _;
use dropshot::EmptyScanParams;
use dropshot::WhichPage;
use oximeter::TimeseriesSchema;
use slog::Logger;
use std::net::IpAddr;
use std::net::SocketAddr;

#[cfg(any(feature = "oxql", test))]
pub mod oxql;
Expand Down Expand Up @@ -130,21 +125,6 @@ pub async fn describe_timeseries(
Ok(())
}

/// Create a client to the timeseries database, and ensure the database exists.
pub 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_single_node_db()
.await
.context("Failed to initialize timeseries database")?;
Ok(client)
}

/// Prepare the columns for a timeseries or virtual table.
pub(crate) fn prepare_columns(
schema: &TimeseriesSchema,
Expand Down
4 changes: 2 additions & 2 deletions oximeter/db/src/shells/oxql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

// Copyright 2024 Oxide Computer

use super::{list_timeseries, make_client, prepare_columns};
use crate::{oxql::Table, Client, OxqlResult};
use super::{list_timeseries, prepare_columns};
use crate::{make_client, oxql::Table, Client, OxqlResult};
use clap::Args;
use crossterm::style::Stylize;
use reedline::DefaultPrompt;
Expand Down
4 changes: 2 additions & 2 deletions oximeter/db/src/shells/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Copyright 2024 Oxide Computer Company

use super::{make_client, prepare_columns};
use super::prepare_columns;
use crate::sql::{function_allow_list, QueryResult, Table};
use crate::{Client, QuerySummary};
use crate::{make_client, Client, QuerySummary};
use clap::Args;
use dropshot::EmptyScanParams;
use dropshot::WhichPage;
Expand Down
1 change: 1 addition & 0 deletions oximeter/instruments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ http-instruments = [
"dep:oximeter",
"dep:schemars",
"dep:serde",
"dep:slog",
"dep:uuid"
]
kstat = [
Expand Down
1 change: 1 addition & 0 deletions sled-storage/src/manager_test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl Drop for StorageManagerTestHarness {
impl StorageManagerTestHarness {
/// Creates a new StorageManagerTestHarness with no associated disks.
pub async fn new(log: &Logger) -> Self {
#[cfg(all(test, feature = "testing"))]
illumos_utils::USE_MOCKS.store(false, Ordering::SeqCst);
let tmp = camino_tempfile::tempdir_in("/var/tmp")
.expect("Failed to make temporary directory");
Expand Down
2 changes: 1 addition & 1 deletion sled-storage/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Pool {
}

/// Return a Pool consisting of fake info
#[cfg(feature = "testing")]
#[cfg(all(test, feature = "testing"))]
pub fn new_with_fake_info(name: ZpoolName, parent: DiskIdentity) -> Pool {
let info = ZpoolInfo::new_hardcoded(name.to_string());
Pool { name, info, parent }
Expand Down
2 changes: 1 addition & 1 deletion uuid-kinds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ paste.workspace = true
[features]
default = ["std"]
serde = ["newtype-uuid/serde"]
schemars08 = ["newtype-uuid/schemars08", "schemars"]
schemars08 = ["newtype-uuid/schemars08", "schemars", "std"]
std = ["newtype-uuid/std"]
uuid-v4 = ["newtype-uuid/v4"]
4 changes: 2 additions & 2 deletions uuid-kinds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![cfg_attr(not(feature = "std"), no_std)]

//! A registry for UUID kinds used in Omicron and related projects.
//!
//! See this crate's `README.adoc` for more information.

#![cfg_attr(not(feature = "std"), no_std)]

// Export these types so that other users don't have to pull in newtype-uuid.
#[doc(no_inline)]
pub use newtype_uuid::{
Expand Down
Loading