Skip to content
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

Hide internal silos in utilization #4943

Merged
merged 9 commits into from
Feb 1, 2024
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(30, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(31, 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to be 32 so #4852 can be 31


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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, while this is fine to add, you don't actually need this line, right? In the query you're using it in SQL directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, perhaps. I thought this struct is what generated the type to use for the dsl but that might actually be from the table! call. Yeah, regardless, it shouldn't matter.


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
21 changes: 21 additions & 0 deletions schema/crdb/31.0.0/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ALTER VIEW omicron.public.silo_utilization
AS SELECT
c.id AS silo_id,
s.name AS silo_name,
s.discoverable as silo_discoverable,
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
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;
3 changes: 2 additions & 1 deletion schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ CREATE VIEW IF NOT EXISTS omicron.public.silo_utilization
AS SELECT
c.id AS silo_id,
s.name AS silo_name,
s.discoverable as silo_discoverable,
c.cpus_provisioned AS cpus_provisioned,
c.ram_provisioned AS memory_provisioned,
c.virtual_disk_bytes_provisioned AS storage_provisioned,
Expand Down Expand Up @@ -3418,7 +3419,7 @@ INSERT INTO omicron.public.db_metadata (
version,
target_version
) VALUES
( TRUE, NOW(), NOW(), '30.0.0', NULL)
( TRUE, NOW(), NOW(), '31.0.0', NULL)
ON CONFLICT DO NOTHING;

COMMIT;
Loading