Skip to content

Commit

Permalink
Add timeseries schema to CockroachDB on Nexus startup
Browse files Browse the repository at this point in the history
- Adds tables representing the timeseries schema. These currently track
  the core data about a schema that is fixed across versions; the set of
  fields, also across all versions; and then the mapping between the
  schema and their fields in each particular version.
- Add database models for these
- Add a build.rs to `oximeter` which sets up a const fn that returns all
  schema known at compile-time. Nexus uses this to determine which
  schema need to be loaded during population time.
- Add datastore methods for loading all those schema during population,
  and adds a populator using it.
- Adds more datatstore methods for fetching, listing, and upserting
  timeseries schema. There are a number of tests around these, but they
  are currently unused outside the datastore crate itself (other than
  the populator). The existing Nexus methods for those operations go
  through ClickHouse directly now, but they'll eventually be redirected
  to CockroachDB when the remainder of the switch is completed.
  • Loading branch information
bnaecker committed Jul 4, 2024
1 parent 30b6713 commit 5aa7625
Show file tree
Hide file tree
Showing 26 changed files with 2,186 additions and 49 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions nexus/db-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ tokio.workspace = true
uuid.workspace = true

db-macros.workspace = true
omicron-certificates.workspace = true
omicron-common.workspace = true
nexus-config.workspace = true
nexus-defaults.workspace = true
nexus-types.workspace = true
omicron-certificates.workspace = true
omicron-common.workspace = true
omicron-passwords.workspace = true
sled-agent-client.workspace = true
omicron-workspace-hack.workspace = true
oximeter.workspace = true
sled-agent-client.workspace = true

[dev-dependencies]
camino-tempfile.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ mod sled_underlay_subnet_allocation;
mod snapshot;
mod ssh_key;
mod switch;
mod timeseries_schema;
mod tuf_repo;
mod typed_uuid;
mod unsigned;
Expand Down Expand Up @@ -195,6 +196,7 @@ pub use ssh_key::*;
pub use switch::*;
pub use switch_interface::*;
pub use switch_port::*;
pub use timeseries_schema::*;
pub use tuf_repo::*;
pub use typed_uuid::to_db_typed_uuid;
pub use upstairs_repair::*;
Expand Down
62 changes: 52 additions & 10 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,16 +1751,6 @@ table! {
}
}

table! {
db_metadata (singleton) {
singleton -> Bool,
time_created -> Timestamptz,
time_modified -> Timestamptz,
version -> Text,
target_version -> Nullable<Text>,
}
}

table! {
migration (id) {
id -> Uuid,
Expand All @@ -1778,6 +1768,52 @@ table! {
}
}

table! {
timeseries_schema (timeseries_name) {
timeseries_name -> Text,
authz_scope -> crate::TimeseriesAuthzScopeEnum,
target_description -> Text,
metric_description -> Text,
datum_type -> crate::TimeseriesDatumTypeEnum,
units -> crate::TimeseriesUnitsEnum,
time_created -> Timestamptz,
time_modified -> Timestamptz,
generation -> Int8,
}
}

table! {
timeseries_field (timeseries_name, name) {
timeseries_name -> Text,
name -> Text,
type_ -> crate::TimeseriesFieldTypeEnum,
source -> crate::TimeseriesFieldSourceEnum,
description -> Text,
time_created -> Timestamptz,
time_modified -> Timestamptz,
generation -> Int8,
}
}

table! {
timeseries_field_by_version (timeseries_name, version, field_name) {
timeseries_name -> Text,
version -> Int2,
field_name -> Text,
generation -> Int8,
}
}

table! {
db_metadata (singleton) {
singleton -> Bool,
time_created -> Timestamptz,
time_modified -> Timestamptz,
version -> Text,
target_version -> Nullable<Text>,
}
}

allow_tables_to_appear_in_same_query!(instance, migration);
allow_tables_to_appear_in_same_query!(migration, vmm);
joinable!(instance -> migration (migration_id));
Expand Down Expand Up @@ -1869,3 +1905,9 @@ joinable!(instance_ssh_key -> instance (instance_id));
allow_tables_to_appear_in_same_query!(sled, sled_instance);

joinable!(network_interface -> probe (parent_id));

allow_tables_to_appear_in_same_query!(
timeseries_field,
timeseries_schema,
timeseries_field_by_version
);
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::BTreeMap;
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(81, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(82, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -29,6 +29,7 @@ static KNOWN_VERSIONS: Lazy<Vec<KnownVersion>> = Lazy::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(82, "add-timeseries-schema-tables"),
KnownVersion::new(81, "add-nullable-filesystem-pool"),
KnownVersion::new(80, "add-instance-id-to-migrations"),
KnownVersion::new(79, "nic-spoof-allow"),
Expand Down
Loading

0 comments on commit 5aa7625

Please sign in to comment.