-
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.
Adds functionality to run oximeter standalone
- Adds a "standalone" mode for the `oximeter-collector` crate, including the binary and main inner types. This runs in a slightly different mode, in which the ClickHouse database itself isn't strictly required. In this case, a task to simply print the results will be spawned in place of the normal results-sink task which inserts records into the database. - Creates a tiny fake Nexus server, which includes only the API needed to register collectors and producers. This is started automatically when running `oximeter standalone`, and used to assign producers / collectors as the real Nexus does, but without a database. The assignments are only in memory. - Adds internal `oximeter` API for listing / deleting a producer for each oximeter collector, and an `omdb` subcommand which exercises the listing.
- Loading branch information
Showing
16 changed files
with
1,185 additions
and
117 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// 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/. | ||
|
||
//! omdb commands that query oximeter | ||
use anyhow::Context; | ||
use clap::Args; | ||
use clap::Subcommand; | ||
use futures::TryStreamExt; | ||
use oximeter_client::types::ProducerEndpoint; | ||
use oximeter_client::Client; | ||
use slog::Logger; | ||
use std::net::SocketAddr; | ||
use std::time::Duration; | ||
use tabled::Table; | ||
use tabled::Tabled; | ||
use uuid::Uuid; | ||
|
||
#[derive(Debug, Args)] | ||
pub struct OximeterArgs { | ||
/// URL of the oximeter collector to query | ||
oximeter_url: String, | ||
|
||
#[command(subcommand)] | ||
command: OximeterCommands, | ||
} | ||
|
||
/// Subcommands that query oximeter collector state | ||
#[derive(Debug, Subcommand)] | ||
enum OximeterCommands { | ||
/// List the producers the collector is assigned to poll | ||
ListProducers, | ||
} | ||
|
||
impl OximeterArgs { | ||
fn client(&self, log: &Logger) -> Client { | ||
Client::new( | ||
&self.oximeter_url, | ||
log.new(slog::o!("component" => "oximeter-client")), | ||
) | ||
} | ||
|
||
pub async fn run_cmd(&self, log: &Logger) -> anyhow::Result<()> { | ||
let client = self.client(log); | ||
match self.command { | ||
OximeterCommands::ListProducers => { | ||
self.list_producers(client).await | ||
} | ||
} | ||
} | ||
|
||
async fn list_producers(&self, client: Client) -> anyhow::Result<()> { | ||
let info = client | ||
.collector_info() | ||
.await | ||
.context("failed to fetch collector info")?; | ||
let producers: Vec<Producer> = client | ||
.producers_list_stream(None) | ||
.map_ok(Producer::from) | ||
.try_collect() | ||
.await | ||
.context("failed to list producers")?; | ||
let table = Table::new(producers) | ||
.with(tabled::settings::Style::empty()) | ||
.with(tabled::settings::Padding::new(0, 1, 0, 0)) | ||
.to_string(); | ||
println!("Collector ID: {}\n", info.id); | ||
println!("{table}"); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Tabled)] | ||
struct Producer { | ||
id: Uuid, | ||
address: SocketAddr, | ||
base_route: String, | ||
interval: String, | ||
} | ||
|
||
impl From<ProducerEndpoint> for Producer { | ||
fn from(p: ProducerEndpoint) -> Self { | ||
let interval = Duration::new(p.interval.secs, p.interval.nanos); | ||
Self { | ||
id: p.id, | ||
address: p.address.parse().unwrap(), | ||
base_route: p.base_route, | ||
interval: humantime::format_duration(interval).to_string(), | ||
} | ||
} | ||
} |
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
Oops, something went wrong.