-
Notifications
You must be signed in to change notification settings - Fork 6
fix otlp json format and add upload subcommand #84
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,15 +1,44 @@ | ||||||
use clap::{Parser, ValueEnum}; | ||||||
use std::process::exit; | ||||||
use clap::{Parser, Subcommand, ValueEnum}; | ||||||
use std::fs::File; | ||||||
use std::time::Instant; | ||||||
use std::{path::Path, process::exit}; | ||||||
use tracing::{info_span, Instrument}; | ||||||
|
||||||
use opentelemetry_proto::tonic::{ | ||||||
collector::trace::v1::{trace_service_client::TraceServiceClient, ExportTraceServiceRequest}, | ||||||
trace::v1::TracesData, | ||||||
}; | ||||||
use tonic::transport::Channel; | ||||||
|
||||||
use s3_benchrunner_rust::{ | ||||||
bytes_to_gigabits, prepare_run, telemetry, BenchmarkConfig, Result, RunBenchmark, | ||||||
SkipBenchmarkError, TransferManagerRunner, | ||||||
}; | ||||||
|
||||||
#[derive(Parser, Debug)] | ||||||
struct SimpleCli { | ||||||
#[command(flatten)] | ||||||
run_args: RunArgs, | ||||||
} | ||||||
|
||||||
#[derive(Parser, Debug)] | ||||||
#[command()] | ||||||
struct Args { | ||||||
struct ExtendedCli { | ||||||
#[command(subcommand)] | ||||||
command: Command, | ||||||
#[command(flatten)] | ||||||
run_args: Option<RunArgs>, | ||||||
} | ||||||
|
||||||
#[derive(Subcommand, Debug)] | ||||||
enum Command { | ||||||
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, in the scripts that run all the benchmarks across the different language runners, it's assumed all runners take the same exact command line arguments (that's why the essential args are passed by position, so that it's easier to parse, regardless of language). See: https://github.com/awslabs/aws-crt-s3-benchmarks/?tab=readme-ov-file#run-a-benchmark
Fortunately Edit this line: aws-crt-s3-benchmarks/scripts/utils/build.py Lines 233 to 234 in 508f630
to be like |
||||||
RunBenchmark(RunArgs), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trivial/debatable: if we stick with this, I'd prefer a shorter name, since this is what we're doing 99% of the time
Suggested change
|
||||||
UploadOtlp(UploadOtlpArgs), | ||||||
} | ||||||
|
||||||
#[derive(Debug, clap::Args)] | ||||||
#[command(args_conflicts_with_subcommands = true)] | ||||||
#[command(flatten_help = true)] | ||||||
struct RunArgs { | ||||||
#[arg(value_enum, help = "ID of S3 library to use")] | ||||||
s3_client: S3ClientId, | ||||||
#[arg(help = "Path to workload file (e.g. download-1GiB.run.json)")] | ||||||
|
@@ -29,6 +58,17 @@ struct Args { | |||||
disable_directory: bool, | ||||||
} | ||||||
|
||||||
#[derive(Debug, clap::Args)] | ||||||
#[command(flatten_help = true)] | ||||||
struct UploadOtlpArgs { | ||||||
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't seem like this It seems simpler to just build this as a separate utility, rather than complicate the benchmark runner, unless you foresee a lot of shared functionality in the future? |
||||||
/// OLTP endpoint to export data to | ||||||
#[arg(long, default_value = "http://localhost:4317")] | ||||||
oltp_endpoint: String, | ||||||
|
||||||
/// Path to the trace file (in opentelemetry-proto JSON format) to upload | ||||||
json_file: String, | ||||||
} | ||||||
|
||||||
#[derive(ValueEnum, Clone, Debug)] | ||||||
enum S3ClientId { | ||||||
#[clap(name = "sdk-rust-tm", help = "use aws-s3-transfer-manager crate")] | ||||||
|
@@ -39,24 +79,33 @@ enum S3ClientId { | |||||
} | ||||||
|
||||||
#[tokio::main] | ||||||
async fn main() { | ||||||
let args = Args::parse(); | ||||||
|
||||||
let result = execute(&args).await; | ||||||
if let Err(e) = result { | ||||||
match e.downcast_ref::<SkipBenchmarkError>() { | ||||||
None => { | ||||||
panic!("{e:?}"); | ||||||
} | ||||||
Some(msg) => { | ||||||
eprintln!("Skipping benchmark - {msg}"); | ||||||
exit(123); | ||||||
async fn main() -> Result<()> { | ||||||
let command = SimpleCli::try_parse() | ||||||
.map(|cli| Command::RunBenchmark(cli.run_args)) | ||||||
.unwrap_or_else(|_| ExtendedCli::parse().command); | ||||||
|
||||||
match command { | ||||||
Command::RunBenchmark(args) => { | ||||||
let result = execute(&args).await; | ||||||
if let Err(e) = result { | ||||||
match e.downcast_ref::<SkipBenchmarkError>() { | ||||||
None => { | ||||||
panic!("{e:?}"); | ||||||
} | ||||||
Some(msg) => { | ||||||
eprintln!("Skipping benchmark - {msg}"); | ||||||
exit(123); | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
Command::UploadOtlp(args) => upload_otlp(args).await?, | ||||||
} | ||||||
|
||||||
Ok(()) | ||||||
} | ||||||
|
||||||
async fn execute(args: &Args) -> Result<()> { | ||||||
async fn execute(args: &RunArgs) -> Result<()> { | ||||||
let mut telemetry = if args.telemetry { | ||||||
// If emitting telemetry, set that up as tracing_subscriber. | ||||||
Some(telemetry::init_tracing_subscriber().unwrap()) | ||||||
|
@@ -119,7 +168,7 @@ async fn execute(args: &Args) -> Result<()> { | |||||
Ok(()) | ||||||
} | ||||||
|
||||||
async fn new_runner(args: &Args) -> Result<Box<dyn RunBenchmark>> { | ||||||
async fn new_runner(args: &RunArgs) -> Result<Box<dyn RunBenchmark>> { | ||||||
let config = BenchmarkConfig::new( | ||||||
&args.workload, | ||||||
&args.bucket, | ||||||
|
@@ -150,3 +199,36 @@ fn trace_file_name( | |||||
let run_start = run_start.format("%Y%m%dT%H%M%SZ").to_string(); | ||||||
format!("trace_{run_start}_{workload}_run{run_num:02}.json") | ||||||
} | ||||||
|
||||||
async fn upload_otlp(args: UploadOtlpArgs) -> Result<()> { | ||||||
let path = Path::new(&args.json_file); | ||||||
let f = File::open(path)?; | ||||||
let trace_data = read_spans_from_json(f)?; | ||||||
println!("loaded {} spans", trace_data.resource_spans.len()); | ||||||
|
||||||
let endpoint = Channel::from_shared(args.oltp_endpoint)?; | ||||||
let channel = endpoint.connect_lazy(); | ||||||
let mut client = TraceServiceClient::new(channel); | ||||||
|
||||||
let requests: Vec<_> = trace_data | ||||||
.resource_spans | ||||||
.chunks(4_096) | ||||||
.map(|batch| ExportTraceServiceRequest { | ||||||
resource_spans: batch.to_vec(), | ||||||
}) | ||||||
.collect(); | ||||||
|
||||||
for request in requests { | ||||||
let resp = client.export(request).await?; | ||||||
println!("export response: {:?}", resp); | ||||||
} | ||||||
|
||||||
Ok(()) | ||||||
} | ||||||
|
||||||
// read a file contains ResourceSpans in json format | ||||||
pub fn read_spans_from_json(file: File) -> Result<TracesData> { | ||||||
let reader = std::io::BufReader::new(file); | ||||||
let trace_data: TracesData = serde_json::from_reader(reader)?; | ||||||
Ok(trace_data) | ||||||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't use this. My bad for leaving it in