Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
b1f9749
First pass of resource utilization
smklein Oct 3, 2022
d14f8fc
less weird formatting
smklein Oct 3, 2022
0430d1a
Tweak CTE to avoid using 'OR'; prefer 'UNION' to avoid full table scans
smklein Oct 4, 2022
e8c937f
Merge with snapshots
smklein Oct 4, 2022
55c1e81
Add test
smklein Oct 4, 2022
98467b2
test snapshot usage accounting
smklein Oct 4, 2022
f838365
Emit disk usage info to clickhouse
smklein Oct 5, 2022
f1e4293
Add external API endpoint for querying metrics endpoints
smklein Oct 5, 2022
fda4c3c
fix json spec, minor tweaks
smklein Oct 5, 2022
b20fefd
Fix unauth tests
smklein Oct 5, 2022
5ff619e
Boost timeout to not miss utilization
smklein Oct 5, 2022
acb91ee
Merge branch 'main' into resource-usage
smklein Oct 6, 2022
5c33dba
Add CPUs provisioned
smklein Oct 6, 2022
4c48467
Add resource usage for non-default silo, add fleet to DB
smklein Oct 7, 2022
356d4fc
Silos know which fleets they belong to, fleet resource accounting
smklein Oct 7, 2022
ba874bb
Okay, fleet 'resource_usage' now created / tested, should be working
smklein Oct 7, 2022
e0f9919
Actually use CPU accounting saga node
smklein Oct 7, 2022
229480b
Add test for CPU usage
smklein Oct 7, 2022
d2c5d9d
RAM provisionining metrics are plumbed
smklein Oct 7, 2022
2d6f145
minor docs / label updates
smklein Oct 7, 2022
36f7f8f
Merge branch 'main' into resource-usage
smklein Oct 7, 2022
df4bd2f
physical_disk accounting updated to virtual_disk accounting
smklein Oct 7, 2022
2b30f2b
fix endpoint
smklein Oct 7, 2022
e0dd385
Make 'test_disk_metrics' less flaky
smklein Oct 8, 2022
613e820
Add resource_type
smklein Oct 8, 2022
0036869
Safer conversions, less unwrap
smklein Oct 8, 2022
f3e9d7b
Use authz::project instead of project_id
smklein Oct 8, 2022
4c237e1
Revert "Use authz::project instead of project_id"
smklein Oct 8, 2022
9e3e6ea
No project_id to volume_delete
smklein Oct 8, 2022
c0b7d85
Add test for idempotent fleet initialization
smklein Oct 8, 2022
83d8d9f
More transactions
smklein Oct 8, 2022
95bdaff
updated comment
smklein Oct 8, 2022
f05296e
Add 404 handling for resource usage
smklein Oct 8, 2022
9a758c2
comments
smklein Oct 8, 2022
8d153f6
http entrypoints naming
smklein Oct 8, 2022
91a1b9d
More endpoint updates
smklein Oct 8, 2022
c693630
rename 'ResourceUsage' to 'VirtualResourceProvisioning'
smklein Oct 9, 2022
88c1b0d
Merge branch 'main' into resource-usage (Compiling)
smklein Dec 7, 2022
eaf9fb3
usage -> Provision, update openapi
smklein Dec 7, 2022
acd4d77
link to query
smklein Dec 7, 2022
ec48ea0
VERY WIP - MOVE ACCOUNTING FOR DISKS/INSTANCES CLOSER TO CREATION/DEL…
smklein Dec 7, 2022
a414206
Merge branch 'main' into resource-usage
smklein Dec 9, 2022
2653911
fmt
smklein Dec 9, 2022
c8a2031
Distinguish between 'resource' and 'collection'. Add CTE to make upda…
smklein Dec 13, 2022
db41a2a
Rename virtual_resource_provisioning to collection vs resource
smklein Dec 13, 2022
1371404
Merge branch 'main' into resource-usage
smklein Dec 14, 2022
70facfb
Merge branch 'main' into resource-usage
smklein Dec 15, 2022
206572d
Remove fleet from DB
smklein Dec 15, 2022
82c6378
Still need to insert collection record for fleet
smklein Dec 15, 2022
e398fe1
Comments, distinguish between disk and snapshots
smklein Dec 15, 2022
29edafd
Just starting to make snapshot delete a saga
smklein Dec 16, 2022
081f649
Merge branch 'main' into resource-usage
smklein Dec 26, 2022
f382a73
Patch tests, pull in some saga-ification PRs
smklein Dec 26, 2022
5f5f15e
Transactions, deleting collections, validate collection empty on delete
smklein Dec 27, 2022
999585c
Remove fleet from views
smklein Dec 27, 2022
abf9923
Merge branch 'main' into resource-usage
smklein Dec 27, 2022
27b2c62
Merge branch 'main' into resource-usage
smklein Jan 6, 2023
109172d
Add resource accounting to saga idempotency/unwind tests
smklein Jan 6, 2023
2cada78
cleanup on project delete
smklein Jan 6, 2023
021744c
Merge branch 'main' into resource-usage
smklein Jan 6, 2023
fbc1fe4
cleanup tests
smklein Jan 6, 2023
dd326e8
testonly
smklein Jan 6, 2023
2e1c25a
Add more tests, oximeter test API
smklein Jan 9, 2023
84308a7
Merge branch 'main' into resource-usage
smklein Jan 9, 2023
4db6b9f
fix disk_delete test parameters
smklein Jan 9, 2023
14b3580
Merge branch 'main' into resource-usage
smklein Jan 11, 2023
254c2ec
Derive display
smklein Jan 11, 2023
76704e7
to ByteCount
smklein Jan 11, 2023
4e6ea23
silo not found when inserting returns 404
smklein Jan 11, 2023
e954c77
system_metric_lookup in app layer
smklein Jan 11, 2023
fc81ada
Remove ResourceType::VirtualProvision
smklein Jan 11, 2023
6837d17
Simplify nexus testing logic
smklein Jan 11, 2023
ae86c33
tweak some test timings to fight flakes when under load
smklein Jan 11, 2023
91fd7b8
De-duplicate Nexus metrics producer
smklein Jan 11, 2023
ee529d7
Merge branch 'main' into resource-usage
smklein Jan 13, 2023
292ee96
Local to txn
smklein Jan 13, 2023
2ab2a3f
fix tests
smklein Jan 13, 2023
5f534d6
Add a Nexus internal API endpoint for disk remove read only parent (#…
leftwo Jan 13, 2023
ade45d5
[wicket] add missing serde feature on hex dependency (#2163)
sunshowers Jan 13, 2023
eaef871
[wicket] move wizard into its own file (#2164)
sunshowers Jan 13, 2023
516acbc
[wicket] fix call to get_prev_component_id (#2167)
sunshowers Jan 14, 2023
338cbd0
[wicket] add an upload command (#2165)
sunshowers Jan 14, 2023
5935d13
Bump trybuild from 1.0.75 to 1.0.76 (#2172)
dependabot[bot] Jan 16, 2023
a02eca7
Bump clap from 4.0.32 to 4.1.1 (#2168)
dependabot[bot] Jan 16, 2023
b1f3879
Bump debug-ignore from 1.0.3 to 1.0.5 (#2173)
dependabot[bot] Jan 17, 2023
6476827
Bump dropshot from `ce5deee` to `120e168` (#2170)
dependabot[bot] Jan 17, 2023
a10f930
Bump progenitor from `634bf98` to `1ef131a` (#2174)
dependabot[bot] Jan 17, 2023
b3d3849
Bump indicatif from 0.17.2 to 0.17.3 (#2171)
dependabot[bot] Jan 17, 2023
653479b
Docs on ALLOW_FULL_TABLE_SCAN_SQL
smklein Jan 18, 2023
3db02c7
fix mis-merge
smklein Jan 18, 2023
f96cb95
Collect timestamps for Oximeter in CRDB to act as tie-breaker
smklein Jan 18, 2023
5f49bc3
Merge branch 'main' into resource-usage
smklein Jan 18, 2023
57c7389
Fix bad merge
smklein Jan 18, 2023
e18210e
mitigate races in metrics test
smklein Jan 18, 2023
a1feec2
Merge branch 'main' into resource-usage
smklein Jan 18, 2023
52af08a
Merge branch 'main' into resource-usage
smklein Jan 18, 2023
9f498f0
metrics test needs a wider time window, especially when under load
smklein Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions common/src/sql/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,64 @@ CREATE INDEX ON omicron.public.service (
sled_id
);

-- A table describing virtual resource provisioning which may be associated
-- with a collection of objects, including:
-- - Projects
-- - Organizations
-- - Silos
-- - Fleet
CREATE TABLE omicron.public.virtual_provisioning_collection (
-- Should match the UUID of the corresponding collection.
id UUID PRIMARY KEY,
time_modified TIMESTAMPTZ NOT NULL DEFAULT NOW(),

-- Identifies the type of the collection.
collection_type STRING(63) NOT NULL,

-- The amount of physical disk space which has been provisioned
-- on behalf of the collection.
virtual_disk_bytes_provisioned INT8 NOT NULL,

-- The number of CPUs provisioned by VMs.
cpus_provisioned INT8 NOT NULL,

-- The amount of RAM provisioned by VMs.
ram_provisioned INT8 NOT NULL
);

-- A table describing a single virtual resource which has been provisioned.
-- This may include:
-- - Disks
-- - Instances
-- - Snapshots
--
-- NOTE: You might think to yourself: "This table looks an awful lot like
-- the 'virtual_provisioning_collection' table, could they be condensed into
-- a single table?"
-- The answer to this question is unfortunately: "No". We use CTEs to both
-- UPDATE the collection table while INSERTing rows in the resource table, and
-- this would not be allowed if they came from the same table due to:
-- https://www.cockroachlabs.com/docs/v22.2/known-limitations#statements-containing-multiple-modification-subqueries-of-the-same-table-are-disallowed
-- However, by using separate tables, the CTE is able to function correctly.
CREATE TABLE omicron.public.virtual_provisioning_resource (
-- Should match the UUID of the corresponding collection.
id UUID PRIMARY KEY,
time_modified TIMESTAMPTZ NOT NULL DEFAULT NOW(),

-- Identifies the type of the resource.
resource_type STRING(63) NOT NULL,

-- The amount of physical disk space which has been provisioned
-- on behalf of the resource.
virtual_disk_bytes_provisioned INT8 NOT NULL,

-- The number of CPUs provisioned.
cpus_provisioned INT8 NOT NULL,

-- The amount of RAM provisioned.
ram_provisioned INT8 NOT NULL
);

/*
* ZPools of Storage, attached to Sleds.
* Typically these are backed by a single physical disk.
Expand Down
17 changes: 15 additions & 2 deletions nexus/db-model/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ use nexus_types::identity::Resource;
use omicron_common::address::PROPOLIS_PORT;
use omicron_common::api::external;
use omicron_common::api::internal;
use serde::Deserialize;
use serde::Serialize;
use std::net::SocketAddr;
use uuid::Uuid;

/// An Instance (VM).
#[derive(Queryable, Insertable, Debug, Selectable, Resource)]
#[derive(
Queryable, Insertable, Debug, Selectable, Resource, Serialize, Deserialize,
)]
#[diesel(table_name = instance)]
pub struct Instance {
#[diesel(embed)]
Expand Down Expand Up @@ -84,7 +88,16 @@ impl DatastoreAttachTargetConfig<Disk> for Instance {
/// metadata
///
/// This state is owned by the sled agent running that Instance.
#[derive(Clone, Debug, AsChangeset, Selectable, Insertable, Queryable)]
#[derive(
Clone,
Debug,
AsChangeset,
Selectable,
Insertable,
Queryable,
Serialize,
Deserialize,
)]
#[diesel(table_name = instance)]
pub struct InstanceRuntimeState {
/// runtime state of the Instance
Expand Down
6 changes: 5 additions & 1 deletion nexus/db-model/src/instance_cpu_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ use diesel::pg::Pg;
use diesel::serialize::{self, ToSql};
use diesel::sql_types;
use omicron_common::api::external;
use serde::Deserialize;
use serde::Serialize;
use std::convert::TryFrom;

#[derive(Copy, Clone, Debug, AsExpression, FromSqlRow)]
#[derive(
Copy, Clone, Debug, AsExpression, FromSqlRow, Serialize, Deserialize,
)]
#[diesel(sql_type = sql_types::BigInt)]
pub struct InstanceCpuCount(pub external::InstanceCpuCount);

Expand Down
4 changes: 3 additions & 1 deletion nexus/db-model/src/instance_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

use super::impl_enum_wrapper;
use omicron_common::api::external;
use serde::Deserialize;
use serde::Serialize;
use std::io::Write;

impl_enum_wrapper!(
#[derive(SqlType, Debug)]
#[diesel(postgres_type(name = "instance_state"))]
pub struct InstanceStateEnum;

#[derive(Clone, Debug, PartialEq, AsExpression, FromSqlRow)]
#[derive(Clone, Debug, PartialEq, AsExpression, FromSqlRow, Serialize, Deserialize)]
#[diesel(sql_type = InstanceStateEnum)]
pub struct InstanceState(pub external::InstanceState);

Expand Down
4 changes: 4 additions & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ mod ssh_key;
mod u16;
mod update_artifact;
mod user_builtin;
mod virtual_provisioning_collection;
mod virtual_provisioning_resource;
mod vni;
mod volume;
mod vpc;
Expand Down Expand Up @@ -126,6 +128,8 @@ pub use snapshot::*;
pub use ssh_key::*;
pub use update_artifact::*;
pub use user_builtin::*;
pub use virtual_provisioning_collection::*;
pub use virtual_provisioning_resource::*;
pub use vni::*;
pub use volume::*;
pub use vpc::*;
Expand Down
1 change: 1 addition & 0 deletions nexus/db-model/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
//! Subqueries used in CTEs.

pub mod region_allocation;
pub mod virtual_provisioning_collection_update;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Describes the resource provisioning update CTE
//!
//! Refer to <nexus/src/db/queries/virtual_provisioning_collection_update.rs>
//! for the construction of this query.

use crate::schema::organization;
use crate::schema::silo;
use crate::schema::virtual_provisioning_collection;

table! {
parent_org {
id -> Uuid,
}
}

table! {
parent_silo {
id -> Uuid,
}
}

table! {
all_collections {
id -> Uuid,
}
}

table! {
do_update (update) {
update -> Bool,
}
}

diesel::allow_tables_to_appear_in_same_query!(organization, parent_org,);
diesel::allow_tables_to_appear_in_same_query!(silo, parent_silo,);

diesel::allow_tables_to_appear_in_same_query!(
virtual_provisioning_collection,
parent_org,
parent_silo,
all_collections,
do_update,
);
1 change: 0 additions & 1 deletion nexus/db-model/src/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use uuid::Uuid;
pub struct Rack {
#[diesel(embed)]
pub identity: RackIdentity,

pub initialized: bool,
pub tuf_base_url: Option<String>,
}
Expand Down
30 changes: 30 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,36 @@ table! {
}
}

table! {
virtual_provisioning_collection {
id -> Uuid,
// This type isn't actually "Nullable" - it's just handy to use the
// same type for insertion and querying, and doing so requires this
// field to appear optional so we can let this (default) field appear
// optional.
time_modified -> Nullable<Timestamptz>,
collection_type -> Text,
virtual_disk_bytes_provisioned -> Int8,
cpus_provisioned -> Int8,
ram_provisioned -> Int8,
}
}

table! {
virtual_provisioning_resource {
id -> Uuid,
// This type isn't actually "Nullable" - it's just handy to use the
// same type for insertion and querying, and doing so requires this
// field to appear optional so we can let this (default) field appear
// optional.
time_modified -> Nullable<Timestamptz>,
resource_type -> Text,
virtual_disk_bytes_provisioned -> Int8,
cpus_provisioned -> Int8,
ram_provisioned -> Int8,
}
}

table! {
zpool (id) {
id -> Uuid,
Expand Down
53 changes: 53 additions & 0 deletions nexus/db-model/src/virtual_provisioning_collection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::schema::virtual_provisioning_collection;
use crate::ByteCount;
use chrono::{DateTime, Utc};
use omicron_common::api::external;
use parse_display::Display;
use uuid::Uuid;

#[derive(Debug, Display)]
pub enum CollectionTypeProvisioned {
Project,
Organization,
Silo,
Fleet,
}

/// Describes virtual_provisioning_collection for a collection
#[derive(Clone, Selectable, Queryable, Insertable, Debug)]
#[diesel(table_name = virtual_provisioning_collection)]
#[diesel(treat_none_as_default_value = true)]
pub struct VirtualProvisioningCollection {
pub id: Uuid,
pub time_modified: Option<DateTime<Utc>>,
pub collection_type: String,

pub virtual_disk_bytes_provisioned: ByteCount,
pub cpus_provisioned: i64,
pub ram_provisioned: ByteCount,
}

impl VirtualProvisioningCollection {
pub fn new(id: Uuid, collection_type: CollectionTypeProvisioned) -> Self {
Self {
id,
time_modified: None,
collection_type: collection_type.to_string(),
virtual_disk_bytes_provisioned: ByteCount(
external::ByteCount::from(0),
),
cpus_provisioned: 0,
ram_provisioned: ByteCount(external::ByteCount::from(0)),
}
}

pub fn is_empty(&self) -> bool {
self.virtual_disk_bytes_provisioned.to_bytes() == 0
&& self.cpus_provisioned == 0
&& self.ram_provisioned.to_bytes() == 0
}
}
55 changes: 55 additions & 0 deletions nexus/db-model/src/virtual_provisioning_resource.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::schema::virtual_provisioning_resource;
use crate::ByteCount;
use chrono::{DateTime, Utc};
use omicron_common::api::external;
use uuid::Uuid;

#[derive(Debug)]
pub enum ResourceTypeProvisioned {
Instance,
Disk,
Snapshot,
}

impl std::fmt::Display for ResourceTypeProvisioned {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ResourceTypeProvisioned::Instance => write!(f, "instance"),
ResourceTypeProvisioned::Disk => write!(f, "disk"),
ResourceTypeProvisioned::Snapshot => write!(f, "snapshot"),
}
}
}

/// Describes virtual_provisioning_resource for a resource.
#[derive(Clone, Selectable, Queryable, Insertable, Debug)]
#[diesel(table_name = virtual_provisioning_resource)]
#[diesel(treat_none_as_default_value = true)]
pub struct VirtualProvisioningResource {
pub id: Uuid,
pub time_modified: Option<DateTime<Utc>>,
pub resource_type: String,

pub virtual_disk_bytes_provisioned: ByteCount,
pub cpus_provisioned: i64,
pub ram_provisioned: ByteCount,
}

impl VirtualProvisioningResource {
pub fn new(id: Uuid, resource_type: ResourceTypeProvisioned) -> Self {
Self {
id,
time_modified: None,
resource_type: resource_type.to_string(),
virtual_disk_bytes_provisioned: ByteCount(
external::ByteCount::from(0),
),
cpus_provisioned: 0,
ram_provisioned: ByteCount(external::ByteCount::from(0)),
}
}
}
12 changes: 8 additions & 4 deletions nexus/src/app/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,17 @@ impl super::Nexus {

pub async fn project_delete_disk(
self: &Arc<Self>,
opctx: &OpContext,
disk_lookup: &lookup::Disk<'_>,
) -> DeleteResult {
let (.., authz_disk) =
let (.., project, authz_disk) =
disk_lookup.lookup_for(authz::Action::Delete).await?;

let saga_params =
sagas::disk_delete::Params { disk_id: authz_disk.id() };
let saga_params = sagas::disk_delete::Params {
serialized_authn: authn::saga::Serialized::for_opctx(opctx),
project_id: project.id(),
disk_id: authz_disk.id(),
};
self.execute_saga::<sagas::disk_delete::SagaDiskDelete>(saga_params)
.await?;
Ok(())
Expand Down Expand Up @@ -542,7 +546,7 @@ impl super::Nexus {
.fetch()
.await?;

self.volume_remove_read_only_parent(db_disk.volume_id).await?;
self.volume_remove_read_only_parent(&opctx, db_disk.volume_id).await?;

Ok(())
}
Expand Down
Loading