Skip to content

Commit

Permalink
pr review
Browse files Browse the repository at this point in the history
  • Loading branch information
mellowagain committed Feb 24, 2025
1 parent 8f1f61d commit 8aa4296
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions otel-worker-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod client;
pub mod debug;
pub mod dev;
pub mod system;
mod util;

/// otel-worker - store and query traces
#[derive(Parser, Debug)]
Expand Down
18 changes: 5 additions & 13 deletions otel-worker-cli/src/commands/client/traces.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::{anyhow, Result};
use crate::commands::util::parse_rfc3339_from_str;
use anyhow::Result;
use clap::Subcommand;
use otel_worker_core::api::client::ApiClient;
use std::io::stdout;
use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;
use url::Url;

Expand Down Expand Up @@ -62,7 +62,8 @@ pub struct ListArgs {

/// Optional timestamp from which traces that occurred before it are returned.
/// Must be in RFC3339 format
pub time: Option<String>,
#[arg(value_parser = parse_rfc3339_from_str)]
pub time: Option<OffsetDateTime>,

#[arg(from_global)]
pub base_url: Url,
Expand All @@ -72,19 +73,10 @@ pub struct ListArgs {
}

async fn handle_list(args: ListArgs) -> Result<()> {
let time = if let Some(time) = args.time {
Some(
OffsetDateTime::parse(&time, &Rfc3339)
.map_err(|err| anyhow!("failed to parse time argument as rfc3339: {err}"))?,
)
} else {
None
};

let mut api_client = ApiClient::new(args.base_url.clone());
api_client.set_bearer_token(args.auth_token);

let result = api_client.trace_list(args.limit, time).await?;
let result = api_client.trace_list(args.limit, args.time).await?;

serde_json::to_writer_pretty(stdout(), &result)?;

Expand Down
7 changes: 7 additions & 0 deletions otel-worker-cli/src/commands/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use anyhow::{Context, Result};
use time::format_description::well_known::Rfc3339;
use time::OffsetDateTime;

pub fn parse_rfc3339_from_str(arg: &str) -> Result<OffsetDateTime> {
OffsetDateTime::parse(arg, &Rfc3339).context("failed to parse rfc3339 timestamp")
}

0 comments on commit 8aa4296

Please sign in to comment.