Skip to content

Commit

Permalink
Hide internal silos in utilization (#4943)
Browse files Browse the repository at this point in the history
Fixes #4708.

I've updated the `/v1/system/utilization/silos` endpoint to only return
non-discoverable silos if they have a quota set. I believe the
`default-silo` _does_ get a quota set currently which is non-ideal, but
that should be the only one that shows up on the list.

I need specific eyes on the migration b/c I've never written a view
migration before.
  • Loading branch information
zephraph authored Feb 1, 2024
1 parent 22dbd54 commit 6a82336
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 4 deletions.
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use omicron_common::api::external::SemverVersion;
///
/// This should be updated whenever the schema is changed. For more details,
/// refer to: schema/crdb/README.adoc
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(31, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(32, 0, 0);

table! {
disk (id) {
Expand Down Expand Up @@ -431,6 +431,7 @@ table! {
silo_utilization(silo_id) {
silo_id -> Uuid,
silo_name -> Text,
silo_discoverable -> Bool,
cpus_provisioned -> Int8,
memory_provisioned -> Int8,
storage_provisioned -> Int8,
Expand Down
1 change: 1 addition & 0 deletions nexus/db-model/src/utilization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use uuid::Uuid;
pub struct SiloUtilization {
pub silo_id: Uuid,
pub silo_name: Name,
pub silo_discoverable: bool,

pub cpus_allocated: i64,
pub memory_allocated: ByteCount,
Expand Down
8 changes: 8 additions & 0 deletions nexus/db-queries/src/db/datastore/utilization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::db::model::Name;
use crate::db::model::SiloUtilization;
use crate::db::pagination::paginated;
use async_bb8_diesel::AsyncRunQueryDsl;
use diesel::BoolExpressionMethods;
use diesel::{ExpressionMethods, QueryDsl, SelectableHelper};
use omicron_common::api::external::http_pagination::PaginatedBy;
use omicron_common::api::external::Error;
Expand Down Expand Up @@ -50,6 +51,13 @@ impl DataStore {
),
}
.select(SiloUtilization::as_select())
.filter(
dsl::silo_discoverable
.eq(true)
.or(dsl::cpus_allocated.gt(0))
.or(dsl::memory_allocated.gt(0))
.or(dsl::storage_allocated.gt(0)),
)
.load_async(&*self.pool_connection_authorized(opctx).await?)
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
Expand Down
43 changes: 42 additions & 1 deletion nexus/tests/integration_tests/utilization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ async fn test_utilization(cptestctx: &ControlPlaneTestContext) {

create_default_ip_pool(&client).await;

// set high quota for test silo
let _ = NexusRequest::object_put(
client,
"/v1/system/silos/test-suite-silo/quotas",
Some(&params::SiloQuotasCreate::arbitrarily_high_default()),
)
.authn_as(AuthnMode::PrivilegedUser)
.execute()
.await;

let current_util = objects_list_page_authz::<SiloUtilization>(
client,
"/v1/system/utilization/silos",
)
.await
.items;

// `default-silo` should be the only silo that shows up because
// it has a default quota set
assert_eq!(current_util.len(), 2);

assert_eq!(current_util[0].silo_name, "default-silo");
Expand All @@ -47,7 +59,36 @@ async fn test_utilization(cptestctx: &ControlPlaneTestContext) {

assert_eq!(current_util[1].silo_name, "test-suite-silo");
assert_eq!(current_util[1].provisioned, SiloQuotasCreate::empty().into());
assert_eq!(current_util[1].allocated, SiloQuotasCreate::empty().into());
assert_eq!(
current_util[1].allocated,
SiloQuotasCreate::arbitrarily_high_default().into()
);

let _ = NexusRequest::object_put(
client,
"/v1/system/silos/test-suite-silo/quotas",
Some(&params::SiloQuotasCreate::empty()),
)
.authn_as(AuthnMode::PrivilegedUser)
.execute()
.await;

let current_util = objects_list_page_authz::<SiloUtilization>(
client,
"/v1/system/utilization/silos",
)
.await
.items;

// Now that default-silo is the only one with a quota, it should be the only result
assert_eq!(current_util.len(), 1);

assert_eq!(current_util[0].silo_name, "default-silo");
assert_eq!(current_util[0].provisioned, SiloQuotasCreate::empty().into());
assert_eq!(
current_util[0].allocated,
SiloQuotasCreate::arbitrarily_high_default().into()
);

let _ = create_project(&client, &PROJECT_NAME).await;
let _ = create_instance(client, &PROJECT_NAME, &INSTANCE_NAME).await;
Expand Down
22 changes: 22 additions & 0 deletions schema/crdb/32.0.0/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE OR REPLACE VIEW omicron.public.silo_utilization
AS SELECT
c.id AS silo_id,
s.name AS silo_name,
c.cpus_provisioned AS cpus_provisioned,
c.ram_provisioned AS memory_provisioned,
c.virtual_disk_bytes_provisioned AS storage_provisioned,
q.cpus AS cpus_allocated,
q.memory_bytes AS memory_allocated,
q.storage_bytes AS storage_allocated,
-- This is the added column
s.discoverable as silo_discoverable
FROM
omicron.public.virtual_provisioning_collection AS c
RIGHT JOIN omicron.public.silo_quotas AS q
ON c.id = q.silo_id
INNER JOIN omicron.public.silo AS s
ON c.id = s.id
WHERE
c.collection_type = 'Silo'
AND
s.time_deleted IS NULL;
5 changes: 3 additions & 2 deletions schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ AS SELECT
c.virtual_disk_bytes_provisioned AS storage_provisioned,
q.cpus AS cpus_allocated,
q.memory_bytes AS memory_allocated,
q.storage_bytes AS storage_allocated
q.storage_bytes AS storage_allocated,
s.discoverable as silo_discoverable
FROM
omicron.public.virtual_provisioning_collection AS c
RIGHT JOIN omicron.public.silo_quotas AS q
Expand Down Expand Up @@ -3442,7 +3443,7 @@ INSERT INTO omicron.public.db_metadata (
version,
target_version
) VALUES
( TRUE, NOW(), NOW(), '31.0.0', NULL)
( TRUE, NOW(), NOW(), '32.0.0', NULL)
ON CONFLICT DO NOTHING;

COMMIT;

0 comments on commit 6a82336

Please sign in to comment.