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

Define virtual resource provisioning timeseries in TOML #6007

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 9 additions & 32 deletions nexus/db-queries/src/provisioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,14 @@
//! Types to export metrics about provisioning information.

use crate::db::model::VirtualProvisioningCollection;
use oximeter::{types::Sample, Metric, MetricsError, Target};
use oximeter::{types::Sample, MetricsError};
use std::sync::{Arc, Mutex};
use uuid::Uuid;

/// Describes a collection that holds other resources.
///
/// Example targets might include projects, silos or fleets.
#[derive(Debug, Clone, Target)]
struct CollectionTarget {
id: Uuid,
}

#[derive(Debug, Clone, Metric)]
struct VirtualDiskSpaceProvisioned {
#[datum]
bytes_used: i64,
}

#[derive(Debug, Clone, Metric)]
struct CpusProvisioned {
#[datum]
cpus: i64,
}

#[derive(Debug, Clone, Metric)]
struct RamProvisioned {
#[datum]
bytes: i64,
}
oximeter::use_timeseries!("collection-target.toml");
use collection_target::CollectionTarget;
use collection_target::CpusProvisioned;
use collection_target::RamProvisioned;
use collection_target::VirtualDiskSpaceProvisioned;

/// An oximeter producer for reporting [`VirtualProvisioningCollection`] information to Clickhouse.
///
Expand Down Expand Up @@ -72,9 +51,7 @@ impl Producer {
.expect("Should always have default value"),
&CollectionTarget { id: provision.id },
&VirtualDiskSpaceProvisioned {
bytes_used: provision
.virtual_disk_bytes_provisioned
.into(),
datum: provision.virtual_disk_bytes_provisioned.into(),
},
)
})
Expand All @@ -96,7 +73,7 @@ impl Producer {
.time_modified
.expect("Should always have default value"),
&CollectionTarget { id: provision.id },
&CpusProvisioned { cpus: provision.cpus_provisioned },
&CpusProvisioned { datum: provision.cpus_provisioned },
)
})
.chain(provisions.iter().map(|provision| {
Expand All @@ -105,7 +82,7 @@ impl Producer {
.time_modified
.expect("Should always have default value"),
&CollectionTarget { id: provision.id },
&RamProvisioned { bytes: provision.ram_provisioned.into() },
&RamProvisioned { datum: provision.ram_provisioned.into() },
)
}))
.collect::<Result<Vec<_>, _>>()?;
Expand Down
40 changes: 40 additions & 0 deletions oximeter/oximeter/schema/collection-target.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
format_version = 1

[target]
name = "collection_target"
description = "A collection such as project or silo, whose provisioned virtual resources are tracked"
authz_scope = "fleet"
versions = [
{ version = 1, fields = [ "id" ] },
]

[fields.id]
type = "uuid"
description = "UUID of the tracked collection"

[[metrics]]
name = "virtual_disk_space_provisioned"
description = "Total virtual disk space provisioned in the collection"
units = "bytes"
datum_type = "i64"
versions = [
{ added_in = 1, fields = [] }
]

[[metrics]]
name = "ram_provisioned"
description = "Total memory provisioned in the collection"
units = "bytes"
datum_type = "i64"
versions = [
{ added_in = 1, fields = [] }
]

[[metrics]]
name = "cpus_provisioned"
description = "Total number of vCPUs provisioned in the collection"
units = "count"
datum_type = "i64"
versions = [
{ added_in = 1, fields = [] }
]
Loading