WIP testing cbor output

This commit is contained in:
Dominik Werder
2023-12-19 16:30:06 +01:00
parent a8479b2c8d
commit b5ce2dd743
17 changed files with 495 additions and 116 deletions

View File

@@ -19,4 +19,5 @@ taskrun = { path = "../taskrun" }
netpod = { path = "../netpod" }
disk = { path = "../disk" }
httpclient = { path = "../httpclient" }
streams = { path = "../streams" }
daqbufp2 = { path = "../daqbufp2" }

View File

@@ -11,7 +11,9 @@ use netpod::query::CacheUsage;
use netpod::NodeConfig;
use netpod::NodeConfigCached;
use netpod::ProxyConfig;
use netpod::ScalarType;
use netpod::ServiceVersion;
use netpod::Shape;
use taskrun::tokio;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
@@ -123,6 +125,16 @@ async fn go() -> Result<(), Error> {
)
.await?;
}
ClientType::CborEvents(opts) => {
daqbuffer::fetch::fetch_cbor(
&opts.url,
ScalarType::from_variant_str(&opts.scalar_type).unwrap(),
Shape::from_dims_str(&opts.shape).unwrap(),
)
.await
.map_err(|_| Error::with_msg_no_trace("error"))
.unwrap();
}
},
SubCmd::GenerateTestData => {
disk::gen::gen_test_data().await?;

View File

@@ -42,6 +42,7 @@ pub struct Client {
pub enum ClientType {
Binned(BinnedClient),
Status(StatusClient),
CborEvents(CborEvents),
}
#[derive(Debug, Parser)]
@@ -73,3 +74,13 @@ pub struct BinnedClient {
#[arg(long, default_value = "1048576")]
pub disk_stats_every_kb: u32,
}
#[derive(Debug, Parser)]
pub struct CborEvents {
#[arg(long)]
pub url: String,
#[arg(long)]
pub scalar_type: String,
#[arg(long)]
pub shape: String,
}

View File

@@ -0,0 +1,47 @@
use futures_util::future;
use futures_util::StreamExt;
use http::header;
use http::Method;
use http::StatusCode;
use httpclient::body_empty;
use httpclient::connect_client;
use httpclient::http;
use httpclient::hyper::Request;
use httpclient::IncomingStream;
use netpod::log::*;
use netpod::ScalarType;
use netpod::Shape;
use std::fmt;
use streams::cbor::FramedBytesToSitemtyDynEventsStream;
use url::Url;
pub struct Error {}
impl<T> From<T> for Error
where
T: fmt::Debug,
{
fn from(_value: T) -> Self {
Self {}
}
}
pub async fn fetch_cbor(url: &str, scalar_type: ScalarType, shape: Shape) -> Result<(), Error> {
let url: Url = url.parse().unwrap();
let accept = "application/cbor";
let req = Request::builder()
.method(Method::GET)
.uri(url.to_string())
.header(header::HOST, url.host_str().ok_or_else(|| "NoHostname")?)
.header(header::ACCEPT, accept)
.body(body_empty())?;
let mut send_req = connect_client(req.uri()).await?;
let res = send_req.send_request(req).await?;
let (head, body) = res.into_parts();
debug!("http_get head {head:?}");
let stream = IncomingStream::new(body);
let stream = FramedBytesToSitemtyDynEventsStream::new(stream, scalar_type, shape);
let stream = stream.map(|item| info!("{item:?}"));
stream.for_each(|_| future::ready(())).await;
Ok(())
}

View File

@@ -1,2 +1,3 @@
pub mod cli;
pub mod err;
pub mod fetch;