Skip to content
Open
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
6 changes: 6 additions & 0 deletions dev-tools/omdb/src/bin/omdb/oximeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl OximeterArgs {
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
struct Producer {
id: Uuid,
kind: String,
address: SocketAddr,
interval: String,
}
Expand All @@ -148,6 +149,7 @@ impl From<ProducerEndpoint> for Producer {
fn from(p: ProducerEndpoint) -> Self {
Self {
id: p.id,
kind: p.kind.to_string(),
address: p.address.parse().unwrap(),
interval: duration_to_humantime(&p.interval),
}
Expand All @@ -164,6 +166,7 @@ const WIDTH: usize = 12;
fn print_producer_details(details: ProducerDetails) {
println!();
println!("{:>WIDTH$}: {}", "ID", details.id);
println!("{:>WIDTH$}: {:?}", "Kind", details.kind);
println!("{:>WIDTH$}: {}", "Address", details.address);
println!(
"{:>WIDTH$}: {}",
Expand Down Expand Up @@ -258,6 +261,7 @@ mod tests {
use chrono::Utc;
use oximeter_client::types::FailedCollection;
use oximeter_client::types::ProducerDetails;
use oximeter_client::types::ProducerKind;
use oximeter_client::types::SuccessfulCollection;
use std::time::Duration;
use uuid::Uuid;
Expand All @@ -267,6 +271,7 @@ mod tests {
let now = Utc::now();
let details = ProducerDetails {
id: Uuid::new_v4(),
kind: ProducerKind::SledAgent,
address: "[::1]:12345".parse().unwrap(),
interval: Duration::from_secs(10).into(),
last_success: Some(SuccessfulCollection {
Expand All @@ -289,6 +294,7 @@ mod tests {
let now = Utc::now();
let details = ProducerDetails {
id: Uuid::new_v4(),
kind: ProducerKind::SledAgent,
interval: Duration::from_secs(10).into(),
address: "[::1]:12345".parse().unwrap(),
last_success: Some(SuccessfulCollection {
Expand Down
1 change: 1 addition & 0 deletions openapi/oximeter/oximeter-1.0.0-8e3b9c.json.gitstub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a582b520e5926304437d844dd68dcb03dd1d04cf:openapi/oximeter/oximeter-1.0.0-8e3b9c.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://oxide.computer",
"email": "api@oxide.computer"
},
"version": "1.0.0"
"version": "2.0.0"
},
"paths": {
"/info": {
Expand Down Expand Up @@ -261,6 +261,14 @@
}
]
},
"kind": {
"description": "The kind of producer.",
"allOf": [
{
"$ref": "#/components/schemas/ProducerKind"
}
]
},
"last_failure": {
"nullable": true,
"description": "Details about the last failed collection.\n\nThis is None if we've never failed to collect from the producer.",
Expand Down Expand Up @@ -306,6 +314,7 @@
"address",
"id",
"interval",
"kind",
"n_collections",
"n_failures",
"registered",
Expand Down
2 changes: 1 addition & 1 deletion openapi/oximeter/oximeter-latest.json
20 changes: 19 additions & 1 deletion oximeter/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dropshot::{
};
use dropshot_api_manager_types::api_versions;
use omicron_common::api::internal::nexus::ProducerEndpoint;
use oximeter_types_versions::latest;
use oximeter_types_versions::{latest, v1};

api_versions!([
// WHEN CHANGING THE API (part 1 of 2):
Expand All @@ -22,6 +22,7 @@ api_versions!([
// | example for the next person.
// v
// (next_int, IDENT),
(2, ADD_PRODUCER_KIND),
(1, INITIAL),
]);

Expand Down Expand Up @@ -57,12 +58,29 @@ pub trait OximeterApi {
#[endpoint {
method = GET,
path = "/producers/{producer_id}",
versions = VERSION_ADD_PRODUCER_KIND..,
}]
async fn producer_details(
request_context: RequestContext<Self::Context>,
path: dropshot::Path<latest::producer::ProducerIdPathParams>,
) -> Result<HttpResponseOk<latest::producer::ProducerDetails>, HttpError>;

/// Get details about a producer by ID.
#[endpoint {
operation_id = "producer_details",
method = GET,
path = "/producers/{producer_id}",
versions = ..VERSION_ADD_PRODUCER_KIND,
}]
async fn producer_details_v1(
request_context: RequestContext<Self::Context>,
path: dropshot::Path<v1::producer::ProducerIdPathParams>,
) -> Result<HttpResponseOk<v1::producer::ProducerDetails>, HttpError> {
Ok(Self::producer_details(request_context, path)
.await?
.map(v1::producer::ProducerDetails::from))
}

/// Delete a producer by ID.
#[endpoint {
method = DELETE,
Expand Down
9 changes: 9 additions & 0 deletions oximeter/types/versions/src/add_producer_kind/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 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/.

//! Version `ADD_PRODUCER_KIND` of the Oximeter API.
//!
//! Adds the producer's `kind` to `ProducerDetails`.

pub mod producer;
67 changes: 67 additions & 0 deletions oximeter/types/versions/src/add_producer_kind/producer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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/.

//! Producer-related types for the Oximeter collector.

use crate::v1;
use chrono::{DateTime, Utc};
use omicron_common::api::internal::nexus::ProducerKind;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use std::time::Duration;
use uuid::Uuid;

#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
pub struct ProducerDetails {
/// The producer's ID.
pub id: Uuid,

/// The kind of producer.
pub kind: ProducerKind,

/// The current collection interval.
pub interval: Duration,

/// The current collection address.
pub address: SocketAddr,

/// The time the producer was first registered with us.
pub registered: DateTime<Utc>,

/// The last time the producer's information was updated.
pub updated: DateTime<Utc>,

/// Details about the last successful collection.
///
/// This is None if we've never successfully collected from the producer.
pub last_success: Option<v1::producer::SuccessfulCollection>,

/// Details about the last failed collection.
///
/// This is None if we've never failed to collect from the producer.
pub last_failure: Option<v1::producer::FailedCollection>,

/// The total number of successful collections we've made.
pub n_collections: u64,

/// The total number of failed collections.
pub n_failures: u64,
}

impl From<ProducerDetails> for v1::producer::ProducerDetails {
fn from(new: ProducerDetails) -> Self {
Self {
id: new.id,
interval: new.interval,
address: new.address,
registered: new.registered,
updated: new.updated,
last_success: new.last_success,
last_failure: new.last_failure,
n_collections: new.n_collections,
n_failures: new.n_failures,
}
}
}
1 change: 1 addition & 0 deletions oximeter/types/versions/src/impls/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ impl ProducerDetails {
let now = Utc::now();
Self {
id: info.id,
kind: info.kind,
interval: info.interval,
address: info.address,
registered: now,
Expand Down
3 changes: 2 additions & 1 deletion oximeter/types/versions/src/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ pub mod histogram {

pub mod producer {
pub use crate::v1::producer::FailedCollection;
pub use crate::v1::producer::ProducerDetails;
pub use crate::v1::producer::ProducerIdPathParams;
pub use crate::v1::producer::ProducerPage;
pub use crate::v1::producer::SuccessfulCollection;

pub use crate::v3::producer::ProducerDetails;
}

pub mod quantile {
Expand Down
2 changes: 2 additions & 0 deletions oximeter/types/versions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ pub mod latest;
pub mod v1;
#[path = "add_joules/mod.rs"]
pub mod v2;
#[path = "add_producer_kind/mod.rs"]
pub mod v3;
Loading