Skip to content

Commit 6a82336

Browse files
authored
Hide internal silos in utilization (#4943)
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.
1 parent 22dbd54 commit 6a82336

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

nexus/db-model/src/schema.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use omicron_common::api::external::SemverVersion;
1313
///
1414
/// This should be updated whenever the schema is changed. For more details,
1515
/// refer to: schema/crdb/README.adoc
16-
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(31, 0, 0);
16+
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(32, 0, 0);
1717

1818
table! {
1919
disk (id) {
@@ -431,6 +431,7 @@ table! {
431431
silo_utilization(silo_id) {
432432
silo_id -> Uuid,
433433
silo_name -> Text,
434+
silo_discoverable -> Bool,
434435
cpus_provisioned -> Int8,
435436
memory_provisioned -> Int8,
436437
storage_provisioned -> Int8,

nexus/db-model/src/utilization.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use uuid::Uuid;
99
pub struct SiloUtilization {
1010
pub silo_id: Uuid,
1111
pub silo_name: Name,
12+
pub silo_discoverable: bool,
1213

1314
pub cpus_allocated: i64,
1415
pub memory_allocated: ByteCount,

nexus/db-queries/src/db/datastore/utilization.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::db::model::Name;
88
use crate::db::model::SiloUtilization;
99
use crate::db::pagination::paginated;
1010
use async_bb8_diesel::AsyncRunQueryDsl;
11+
use diesel::BoolExpressionMethods;
1112
use diesel::{ExpressionMethods, QueryDsl, SelectableHelper};
1213
use omicron_common::api::external::http_pagination::PaginatedBy;
1314
use omicron_common::api::external::Error;
@@ -50,6 +51,13 @@ impl DataStore {
5051
),
5152
}
5253
.select(SiloUtilization::as_select())
54+
.filter(
55+
dsl::silo_discoverable
56+
.eq(true)
57+
.or(dsl::cpus_allocated.gt(0))
58+
.or(dsl::memory_allocated.gt(0))
59+
.or(dsl::storage_allocated.gt(0)),
60+
)
5361
.load_async(&*self.pool_connection_authorized(opctx).await?)
5462
.await
5563
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))

nexus/tests/integration_tests/utilization.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,25 @@ async fn test_utilization(cptestctx: &ControlPlaneTestContext) {
2929

3030
create_default_ip_pool(&client).await;
3131

32+
// set high quota for test silo
33+
let _ = NexusRequest::object_put(
34+
client,
35+
"/v1/system/silos/test-suite-silo/quotas",
36+
Some(&params::SiloQuotasCreate::arbitrarily_high_default()),
37+
)
38+
.authn_as(AuthnMode::PrivilegedUser)
39+
.execute()
40+
.await;
41+
3242
let current_util = objects_list_page_authz::<SiloUtilization>(
3343
client,
3444
"/v1/system/utilization/silos",
3545
)
3646
.await
3747
.items;
3848

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

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

4860
assert_eq!(current_util[1].silo_name, "test-suite-silo");
4961
assert_eq!(current_util[1].provisioned, SiloQuotasCreate::empty().into());
50-
assert_eq!(current_util[1].allocated, SiloQuotasCreate::empty().into());
62+
assert_eq!(
63+
current_util[1].allocated,
64+
SiloQuotasCreate::arbitrarily_high_default().into()
65+
);
66+
67+
let _ = NexusRequest::object_put(
68+
client,
69+
"/v1/system/silos/test-suite-silo/quotas",
70+
Some(&params::SiloQuotasCreate::empty()),
71+
)
72+
.authn_as(AuthnMode::PrivilegedUser)
73+
.execute()
74+
.await;
75+
76+
let current_util = objects_list_page_authz::<SiloUtilization>(
77+
client,
78+
"/v1/system/utilization/silos",
79+
)
80+
.await
81+
.items;
82+
83+
// Now that default-silo is the only one with a quota, it should be the only result
84+
assert_eq!(current_util.len(), 1);
85+
86+
assert_eq!(current_util[0].silo_name, "default-silo");
87+
assert_eq!(current_util[0].provisioned, SiloQuotasCreate::empty().into());
88+
assert_eq!(
89+
current_util[0].allocated,
90+
SiloQuotasCreate::arbitrarily_high_default().into()
91+
);
5192

5293
let _ = create_project(&client, &PROJECT_NAME).await;
5394
let _ = create_instance(client, &PROJECT_NAME, &INSTANCE_NAME).await;

schema/crdb/32.0.0/up.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CREATE OR REPLACE VIEW omicron.public.silo_utilization
2+
AS SELECT
3+
c.id AS silo_id,
4+
s.name AS silo_name,
5+
c.cpus_provisioned AS cpus_provisioned,
6+
c.ram_provisioned AS memory_provisioned,
7+
c.virtual_disk_bytes_provisioned AS storage_provisioned,
8+
q.cpus AS cpus_allocated,
9+
q.memory_bytes AS memory_allocated,
10+
q.storage_bytes AS storage_allocated,
11+
-- This is the added column
12+
s.discoverable as silo_discoverable
13+
FROM
14+
omicron.public.virtual_provisioning_collection AS c
15+
RIGHT JOIN omicron.public.silo_quotas AS q
16+
ON c.id = q.silo_id
17+
INNER JOIN omicron.public.silo AS s
18+
ON c.id = s.id
19+
WHERE
20+
c.collection_type = 'Silo'
21+
AND
22+
s.time_deleted IS NULL;

schema/crdb/dbinit.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ AS SELECT
862862
c.virtual_disk_bytes_provisioned AS storage_provisioned,
863863
q.cpus AS cpus_allocated,
864864
q.memory_bytes AS memory_allocated,
865-
q.storage_bytes AS storage_allocated
865+
q.storage_bytes AS storage_allocated,
866+
s.discoverable as silo_discoverable
866867
FROM
867868
omicron.public.virtual_provisioning_collection AS c
868869
RIGHT JOIN omicron.public.silo_quotas AS q
@@ -3442,7 +3443,7 @@ INSERT INTO omicron.public.db_metadata (
34423443
version,
34433444
target_version
34443445
) VALUES
3445-
( TRUE, NOW(), NOW(), '31.0.0', NULL)
3446+
( TRUE, NOW(), NOW(), '32.0.0', NULL)
34463447
ON CONFLICT DO NOTHING;
34473448

34483449
COMMIT;

0 commit comments

Comments
 (0)