-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created using spr 1.3.6-beta.1
- Loading branch information
Showing
15 changed files
with
285 additions
and
263 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "oximeter-api" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
chrono.workspace = true | ||
dropshot.workspace = true | ||
omicron-common.workspace = true | ||
omicron-workspace-hack.workspace = true | ||
schemars.workspace = true | ||
serde.workspace = true | ||
uuid.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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 chrono::{DateTime, Utc}; | ||
use dropshot::{ | ||
EmptyScanParams, HttpError, HttpResponseDeleted, HttpResponseOk, | ||
HttpResponseUpdatedNoContent, PaginationParams, Query, RequestContext, | ||
ResultsPage, TypedBody, | ||
}; | ||
use omicron_common::api::internal::nexus::ProducerEndpoint; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
use uuid::Uuid; | ||
|
||
#[dropshot::api_description { | ||
module = "oximeter_api_mod", | ||
}] | ||
pub trait OximeterApi { | ||
type Context; | ||
|
||
/// Handle a request from Nexus to register a new producer with this collector. | ||
#[endpoint { | ||
method = POST, | ||
path = "/producers", | ||
}] | ||
async fn producers_post( | ||
request_context: RequestContext<Self::Context>, | ||
body: TypedBody<ProducerEndpoint>, | ||
) -> Result<HttpResponseUpdatedNoContent, HttpError>; | ||
|
||
/// List all producers. | ||
#[endpoint { | ||
method = GET, | ||
path = "/producers", | ||
}] | ||
async fn producers_list( | ||
request_context: RequestContext<Self::Context>, | ||
query: Query<PaginationParams<EmptyScanParams, ProducerPage>>, | ||
) -> Result<HttpResponseOk<ResultsPage<ProducerEndpoint>>, HttpError>; | ||
|
||
/// Delete a producer by ID. | ||
#[endpoint { | ||
method = DELETE, | ||
path = "/producers/{producer_id}", | ||
}] | ||
async fn producer_delete( | ||
request_context: RequestContext<Self::Context>, | ||
path: dropshot::Path<ProducerIdPathParams>, | ||
) -> Result<HttpResponseDeleted, HttpError>; | ||
|
||
/// Return identifying information about this collector. | ||
#[endpoint { | ||
method = GET, | ||
path = "/info", | ||
}] | ||
async fn collector_info( | ||
request_context: RequestContext<Self::Context>, | ||
) -> Result<HttpResponseOk<CollectorInfo>, HttpError>; | ||
} | ||
|
||
/// Parameters for paginating the list of producers. | ||
#[derive(Clone, Copy, Debug, Deserialize, JsonSchema, Serialize)] | ||
pub struct ProducerPage { | ||
pub id: Uuid, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Deserialize, JsonSchema, Serialize)] | ||
pub struct ProducerIdPathParams { | ||
pub producer_id: Uuid, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Deserialize, JsonSchema, Serialize)] | ||
pub struct CollectorInfo { | ||
/// The collector's UUID. | ||
pub id: Uuid, | ||
/// Last time we refreshed our producer list with Nexus. | ||
pub last_refresh: Option<DateTime<Utc>>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ use anyhow::{anyhow, Context}; | |
use clap::Parser; | ||
use omicron_common::cmd::fatal; | ||
use omicron_common::cmd::CmdError; | ||
use oximeter_collector::oximeter_api; | ||
use oximeter_collector::standalone_nexus_api; | ||
use oximeter_collector::Config; | ||
use oximeter_collector::Oximeter; | ||
|
@@ -23,16 +22,6 @@ use std::net::SocketAddrV6; | |
use std::path::PathBuf; | ||
use uuid::Uuid; | ||
|
||
pub fn run_openapi() -> Result<(), String> { | ||
oximeter_api() | ||
.openapi("Oxide Oximeter API", "0.0.1") | ||
.description("API for interacting with oximeter") | ||
.contact_url("https://oxide.computer") | ||
.contact_email("[email protected]") | ||
.write(&mut std::io::stdout()) | ||
.map_err(|e| e.to_string()) | ||
} | ||
|
||
pub fn run_standalone_openapi() -> Result<(), String> { | ||
standalone_nexus_api() | ||
.openapi("Oxide Nexus API", "0.0.1") | ||
|
@@ -47,9 +36,6 @@ pub fn run_standalone_openapi() -> Result<(), String> { | |
#[derive(Parser)] | ||
#[clap(name = "oximeter", about = "See README.adoc for more information")] | ||
enum Args { | ||
/// Print the external OpenAPI Spec document and exit | ||
Openapi, | ||
|
||
/// Start an Oximeter server | ||
Run { | ||
/// Path to TOML file with configuration for the server | ||
|
@@ -133,9 +119,6 @@ async fn main() { | |
async fn do_run() -> Result<(), CmdError> { | ||
let args = Args::parse(); | ||
match args { | ||
Args::Openapi => { | ||
run_openapi().map_err(|err| CmdError::Failure(anyhow!(err))) | ||
} | ||
Args::Run { config_file, id, address } => { | ||
let config = Config::from_file(config_file).unwrap(); | ||
let args = OximeterArguments { id, address }; | ||
|
Oops, something went wrong.