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

Add (perf_data) upload to CLI report subcommand #146

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion lib/bencher_json/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pub mod auth;
pub mod backup;
pub mod config;
pub mod restart;
pub mod version;
pub mod version;
4 changes: 4 additions & 0 deletions services/cli/src/bencher/sub/project/report/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ use crate::{bencher::sub::SubCmd, cli::project::report::CliReport, CliError};

mod list;
mod view;
mod upload;

#[derive(Debug)]
pub enum Report {
List(list::List),
Create(Box<Create>),
View(view::View),
Upload(upload::Upload)
}

impl TryFrom<CliReport> for Report {
Expand All @@ -21,6 +23,7 @@ impl TryFrom<CliReport> for Report {
CliReport::List(list) => Self::List(list.try_into()?),
CliReport::Create(create) => Self::Create(Box::new((*create).try_into()?)),
CliReport::View(view) => Self::View(view.try_into()?),
CliReport::Upload(upload) => Self::Upload(upload.try_into()?),
})
}
}
Expand All @@ -32,6 +35,7 @@ impl SubCmd for Report {
Self::List(list) => list.exec().await,
Self::Create(create) => create.exec().await,
Self::View(create) => create.exec().await,
Self::Upload(upload) => upload.exec().await
}
}
}
53 changes: 53 additions & 0 deletions services/cli/src/bencher/sub/project/report/upload.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::{convert::TryFrom, path::PathBuf};

use async_trait::async_trait;
use bencher_json::{ResourceId};
use serde_json::json;
use uuid::Uuid;

use crate::{
bencher::{backend::Backend, sub::SubCmd},
cli::project::report::CliReportUpload,
CliError,
};

#[derive(Debug)]
pub struct Upload{
pub project: ResourceId,
pub report: Uuid,
pub backend: Backend,
pub perf_data_path: PathBuf
}

impl TryFrom<CliReportUpload> for Upload {
type Error = CliError;

fn try_from(upload: CliReportUpload) -> Result<Self, Self::Error> {
let CliReportUpload{
project,
report,
backend,
perf_data_path
} = upload;
Ok(Self {
project,
report,
backend: backend.try_into()?,
perf_data_path
})
}
}

#[async_trait]
impl SubCmd for Upload {
async fn exec(&self) -> Result<(), CliError> {
let perf_data_json = json!(self.perf_data_path);
self.backend
.post(&format!(
"/v0/projects/{}/reports/{}",
self.project, self.report
), &perf_data_json)
.await?;
Ok(())
}
}
20 changes: 20 additions & 0 deletions services/cli/src/cli/project/report.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use bencher_json::ResourceId;
use clap::{Parser, Subcommand};
use uuid::Uuid;
Expand All @@ -15,6 +17,8 @@ pub enum CliReport {
Create(Box<CliRun>),
/// View a report
View(CliReportView),
/// Upload report
Upload(CliReportUpload)
}

#[derive(Parser, Debug)]
Expand All @@ -39,3 +43,19 @@ pub struct CliReportView {
#[clap(flatten)]
pub backend: CliBackend,
}

#[derive(Parser, Debug)]
pub struct CliReportUpload {
/// Project slug or UUID
#[clap(long)]
pub project: ResourceId,

/// Report UUID
pub report: Uuid,

#[clap(flatten)]
pub backend: CliBackend,

/// Perf data file path
pub perf_data_path: PathBuf
}