Skip to content

Commit

Permalink
WIP: Add timeseries schema to CockroachDB on Nexus startup
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaecker committed Jun 27, 2024
1 parent 01d8b37 commit 7c19eb2
Show file tree
Hide file tree
Showing 25 changed files with 1,347 additions and 44 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.

4 changes: 2 additions & 2 deletions nexus/auth/src/authz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
//! | | | +---------------+-----------+-------------+-------------+---+ |
//! | | | | resource_type | role_name | resource_id | identity_id |...| |
//! | | | +---------------+-----------+-------------+-------------+---+ |
//! | | | | "project " | "viewer" | 234 | 123|...| |
//! | | | | "project " | "viewer" | 123 | 234|...| |
//! | | | +--^------------+--^--------+----------^--+-----------^-+---+ |
//! | | | | | | | |
//! +-|-|----+ | | +------------+
Expand All @@ -120,7 +120,7 @@
//! how we find these records and make them available for the authz check.
//!
//! Built-in users are only one possible target for role assignments. IdP users
//! (Silo users) an also be assigned roles. This all works the same way, except
//! (Silo users) can also be assigned roles. This all works the same way, except
//! that in that case `role_assignment.identity_id` refers to an entry in the
//! `silo_user` table rather than `user_builtin`. How do we know the
//! difference? There's also an `identity_type` column in the "role_assignment"
Expand Down
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
60 changes: 50 additions & 10 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1745,16 +1745,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 @@ -1771,6 +1761,50 @@ table! {
}
}

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

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,
}
}

table! {
timeseries_version_field (timeseries_name, version, field_name) {
timeseries_name -> Text,
version -> Int2,
field_name -> Text,
}
}

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 @@ -1862,3 +1896,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_version_field
);
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(77, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(78, 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(78, "add-timeseries-schema-tables"),
KnownVersion::new(77, "remove-view-for-v2p-mappings"),
KnownVersion::new(76, "lookup-region-snapshot-by-snapshot-id"),
KnownVersion::new(75, "add-cockroach-zone-id-to-node-id"),
Expand Down
Loading

0 comments on commit 7c19eb2

Please sign in to comment.