Remove ChannelExecFunction
This commit is contained in:
@@ -1,414 +0,0 @@
|
||||
pub mod binnedfrompbv;
|
||||
pub mod dim1;
|
||||
pub mod pbv;
|
||||
pub mod prebinned;
|
||||
pub mod query;
|
||||
|
||||
use crate::agg::binnedt::TBinnerStream;
|
||||
use crate::binned::binnedfrompbv::BinnedFromPreBinned;
|
||||
use crate::binnedstream::BoxedStream;
|
||||
use crate::channelexec::{channel_exec, ChannelExecFunction};
|
||||
use crate::decode::{Endianness, EventValueFromBytes, EventValueShape, NumFromBytes};
|
||||
use crate::merge::mergedfromremotes::MergedFromRemotes;
|
||||
use bytes::Bytes;
|
||||
use err::Error;
|
||||
use futures_core::Stream;
|
||||
use futures_util::StreamExt;
|
||||
use items::numops::NumOps;
|
||||
use items::streams::{collect_plain_events_json, Collectable, Collector};
|
||||
use items::{
|
||||
Clearable, EventsNodeProcessor, FilterFittingInside, Framable, FrameDecodable, FrameType, PushableIndex,
|
||||
RangeCompletableItem, Sitemty, StreamItem, TimeBinnableType, WithLen,
|
||||
};
|
||||
use netpod::log::*;
|
||||
use netpod::query::{BinnedQuery, RawEventsQuery};
|
||||
use netpod::x_bin_count;
|
||||
use netpod::{BinnedRange, NodeConfigCached, PerfOpts, PreBinnedPatchIterator, PreBinnedPatchRange, ScalarType, Shape};
|
||||
use std::fmt::Debug;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct BinnedStreamRes<I> {
|
||||
pub binned_stream: BoxedStream<Result<StreamItem<RangeCompletableItem<I>>, Error>>,
|
||||
pub range: BinnedRange,
|
||||
}
|
||||
|
||||
pub struct BinnedBinaryChannelExec {
|
||||
query: BinnedQuery,
|
||||
node_config: NodeConfigCached,
|
||||
}
|
||||
|
||||
impl BinnedBinaryChannelExec {
|
||||
pub fn new(query: BinnedQuery, node_config: NodeConfigCached) -> Self {
|
||||
Self { query, node_config }
|
||||
}
|
||||
}
|
||||
|
||||
impl ChannelExecFunction for BinnedBinaryChannelExec {
|
||||
type Output = Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>;
|
||||
|
||||
fn exec<NTY, END, EVS, ENP>(
|
||||
self,
|
||||
_byte_order: END,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
event_value_shape: EVS,
|
||||
_events_node_proc: ENP,
|
||||
) -> Result<Self::Output, Error>
|
||||
where
|
||||
NTY: NumOps + NumFromBytes<NTY, END> + 'static,
|
||||
END: Endianness + 'static,
|
||||
EVS: EventValueShape<NTY, END> + EventValueFromBytes<NTY, END> + 'static,
|
||||
ENP: EventsNodeProcessor<Input = <EVS as EventValueFromBytes<NTY, END>>::Batch> + 'static,
|
||||
// TODO require these things in general?
|
||||
<ENP as EventsNodeProcessor>::Output: Collectable + PushableIndex + Clearable,
|
||||
<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output: Debug
|
||||
+ TimeBinnableType<Output = <<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>
|
||||
+ Collectable
|
||||
+ Unpin,
|
||||
Sitemty<<ENP as EventsNodeProcessor>::Output>: FrameType + Framable + 'static,
|
||||
Sitemty<<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>:
|
||||
FrameType + Framable + FrameDecodable,
|
||||
{
|
||||
let _ = event_value_shape;
|
||||
let range = BinnedRange::covering_range(self.query.range().clone(), self.query.bin_count())?;
|
||||
let perf_opts = PerfOpts { inmem_bufcap: 512 };
|
||||
let souter = match PreBinnedPatchRange::covering_range(self.query.range().clone(), self.query.bin_count()) {
|
||||
Ok(Some(pre_range)) => {
|
||||
debug!("BinnedBinaryChannelExec found pre_range: {pre_range:?}");
|
||||
if range.grid_spec().bin_t_len() < pre_range.grid_spec.bin_t_len() {
|
||||
let msg = format!(
|
||||
"BinnedBinaryChannelExec incompatible ranges:\npre_range: {pre_range:?}\nrange: {range:?}"
|
||||
);
|
||||
return Err(Error::with_msg(msg));
|
||||
}
|
||||
let s = BinnedFromPreBinned::<<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>::new(
|
||||
PreBinnedPatchIterator::from_range(pre_range),
|
||||
self.query.channel().clone(),
|
||||
range.clone(),
|
||||
scalar_type,
|
||||
shape,
|
||||
self.query.agg_kind().clone(),
|
||||
self.query.cache_usage().clone(),
|
||||
self.query.disk_io_buffer_size(),
|
||||
&self.node_config,
|
||||
self.query.disk_stats_every().clone(),
|
||||
self.query.report_error(),
|
||||
)?
|
||||
.map(|item| match item.make_frame() {
|
||||
Ok(item) => Ok(item.freeze()),
|
||||
Err(e) => Err(e),
|
||||
});
|
||||
Ok(Box::pin(s) as Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>)
|
||||
}
|
||||
Ok(None) => {
|
||||
debug!(
|
||||
"BinnedBinaryChannelExec no covering range for prebinned, merge from remotes instead {range:?}"
|
||||
);
|
||||
// TODO let BinnedQuery provide the DiskIoTune and pass to RawEventsQuery:
|
||||
let evq = RawEventsQuery::new(
|
||||
self.query.channel().clone(),
|
||||
self.query.range().clone(),
|
||||
self.query.agg_kind().clone(),
|
||||
);
|
||||
let x_bin_count = x_bin_count(&shape, self.query.agg_kind());
|
||||
let s = MergedFromRemotes::<ENP>::new(evq, perf_opts, self.node_config.node_config.cluster.clone());
|
||||
let s = TBinnerStream::<_, <ENP as EventsNodeProcessor>::Output>::new(
|
||||
s,
|
||||
range,
|
||||
x_bin_count,
|
||||
self.query.agg_kind().do_time_weighted(),
|
||||
);
|
||||
let s = s.map(|item| match item.make_frame() {
|
||||
Ok(item) => Ok(item.freeze()),
|
||||
Err(e) => Err(e),
|
||||
});
|
||||
Ok(Box::pin(s) as Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}?;
|
||||
Ok(souter)
|
||||
}
|
||||
|
||||
fn empty() -> Self::Output {
|
||||
Box::pin(futures_util::stream::empty())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn binned_bytes_for_http(
|
||||
query: &BinnedQuery,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
node_config: &NodeConfigCached,
|
||||
) -> Result<Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>, Error> {
|
||||
let ret = channel_exec(
|
||||
BinnedBinaryChannelExec::new(query.clone(), node_config.clone()),
|
||||
query.channel(),
|
||||
query.range(),
|
||||
scalar_type,
|
||||
shape,
|
||||
query.agg_kind().clone(),
|
||||
node_config,
|
||||
)
|
||||
.await?;
|
||||
Ok(Box::pin(ret))
|
||||
}
|
||||
|
||||
pub struct BinnedBytesForHttpStream<S> {
|
||||
inp: S,
|
||||
errored: bool,
|
||||
completed: bool,
|
||||
}
|
||||
|
||||
impl<S> BinnedBytesForHttpStream<S> {
|
||||
pub fn new(inp: S) -> Self {
|
||||
Self {
|
||||
inp,
|
||||
errored: false,
|
||||
completed: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MakeBytesFrame {
|
||||
fn make_bytes_frame(&self) -> Result<Bytes, Error> {
|
||||
// TODO only implemented for one type, remove
|
||||
err::todoval()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, I> Stream for BinnedBytesForHttpStream<S>
|
||||
where
|
||||
S: Stream<Item = I> + Unpin,
|
||||
I: MakeBytesFrame,
|
||||
{
|
||||
type Item = Result<Bytes, Error>;
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
||||
use Poll::*;
|
||||
if self.completed {
|
||||
panic!("BinnedBytesForHttpStream poll_next on completed");
|
||||
}
|
||||
if self.errored {
|
||||
self.completed = true;
|
||||
return Ready(None);
|
||||
}
|
||||
match self.inp.poll_next_unpin(cx) {
|
||||
Ready(Some(item)) => match item.make_bytes_frame() {
|
||||
Ok(buf) => Ready(Some(Ok(buf))),
|
||||
Err(e) => {
|
||||
self.errored = true;
|
||||
Ready(Some(Err(e.into())))
|
||||
}
|
||||
},
|
||||
Ready(None) => {
|
||||
self.completed = true;
|
||||
Ready(None)
|
||||
}
|
||||
Pending => Pending,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Bool {}
|
||||
|
||||
impl Bool {
|
||||
pub fn is_false(x: &bool) -> bool {
|
||||
*x == false
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn collect_all<T, S>(
|
||||
stream: S,
|
||||
bin_count_exp: u32,
|
||||
timeout: Duration,
|
||||
abort_after_bin_count: u32,
|
||||
) -> Result<serde_json::Value, Error>
|
||||
where
|
||||
S: Stream<Item = Sitemty<T>> + Unpin,
|
||||
T: Collectable,
|
||||
{
|
||||
info!("\n\nConstruct deadline with timeout {timeout:?}\n\n");
|
||||
let deadline = tokio::time::Instant::now() + timeout;
|
||||
let mut collector = <T as Collectable>::new_collector(bin_count_exp);
|
||||
let mut i1 = 0;
|
||||
let mut stream = stream;
|
||||
loop {
|
||||
let item = if i1 == 0 {
|
||||
stream.next().await
|
||||
} else {
|
||||
if abort_after_bin_count > 0 && collector.len() >= abort_after_bin_count as usize {
|
||||
None
|
||||
} else {
|
||||
match tokio::time::timeout_at(deadline, stream.next()).await {
|
||||
Ok(k) => k,
|
||||
Err(_) => {
|
||||
collector.set_timed_out();
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
match item {
|
||||
Some(item) => {
|
||||
match item {
|
||||
Ok(item) => match item {
|
||||
StreamItem::Log(_) => {}
|
||||
StreamItem::Stats(_) => {}
|
||||
StreamItem::DataItem(item) => match item {
|
||||
RangeCompletableItem::RangeComplete => {
|
||||
collector.set_range_complete();
|
||||
}
|
||||
RangeCompletableItem::Data(item) => {
|
||||
collector.ingest(&item);
|
||||
i1 += 1;
|
||||
}
|
||||
},
|
||||
},
|
||||
Err(e) => {
|
||||
// TODO Need to use some flags to get good enough error message for remote user.
|
||||
Err(e)?;
|
||||
}
|
||||
};
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
let ret = serde_json::to_value(collector.result()?)?;
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
pub struct BinnedJsonChannelExec {
|
||||
query: BinnedQuery,
|
||||
node_config: NodeConfigCached,
|
||||
timeout: Duration,
|
||||
}
|
||||
|
||||
impl BinnedJsonChannelExec {
|
||||
pub fn new(query: BinnedQuery, timeout: Duration, node_config: NodeConfigCached) -> Self {
|
||||
Self {
|
||||
query,
|
||||
node_config,
|
||||
timeout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ChannelExecFunction for BinnedJsonChannelExec {
|
||||
type Output = Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>;
|
||||
|
||||
fn exec<NTY, END, EVS, ENP>(
|
||||
self,
|
||||
_byte_order: END,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
event_value_shape: EVS,
|
||||
_events_node_proc: ENP,
|
||||
) -> Result<Self::Output, Error>
|
||||
where
|
||||
NTY: NumOps + NumFromBytes<NTY, END> + 'static,
|
||||
END: Endianness + 'static,
|
||||
EVS: EventValueShape<NTY, END> + EventValueFromBytes<NTY, END> + 'static,
|
||||
ENP: EventsNodeProcessor<Input = <EVS as EventValueFromBytes<NTY, END>>::Batch> + 'static,
|
||||
// TODO require these things in general?
|
||||
<ENP as EventsNodeProcessor>::Output: Collectable + PushableIndex + Clearable,
|
||||
<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output: Debug
|
||||
+ TimeBinnableType<Output = <<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>
|
||||
+ Collectable
|
||||
+ Unpin,
|
||||
Sitemty<<ENP as EventsNodeProcessor>::Output>: FrameType + Framable + 'static,
|
||||
Sitemty<<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>:
|
||||
FrameType + Framable + FrameDecodable,
|
||||
{
|
||||
let _ = event_value_shape;
|
||||
let range = BinnedRange::covering_range(self.query.range().clone(), self.query.bin_count())?;
|
||||
let t_bin_count = range.bin_count() as u32;
|
||||
let perf_opts = PerfOpts { inmem_bufcap: 512 };
|
||||
let souter = match PreBinnedPatchRange::covering_range(self.query.range().clone(), self.query.bin_count()) {
|
||||
Ok(Some(pre_range)) => {
|
||||
info!("BinnedJsonChannelExec found pre_range: {pre_range:?}");
|
||||
if range.grid_spec().bin_t_len() < pre_range.grid_spec.bin_t_len() {
|
||||
let msg = format!(
|
||||
"BinnedJsonChannelExec incompatible ranges:\npre_range: {pre_range:?}\nrange: {range:?}"
|
||||
);
|
||||
return Err(Error::with_msg(msg));
|
||||
}
|
||||
let s = BinnedFromPreBinned::<<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>::new(
|
||||
PreBinnedPatchIterator::from_range(pre_range),
|
||||
self.query.channel().clone(),
|
||||
range.clone(),
|
||||
scalar_type,
|
||||
shape,
|
||||
self.query.agg_kind().clone(),
|
||||
self.query.cache_usage().clone(),
|
||||
self.query.disk_io_buffer_size(),
|
||||
&self.node_config,
|
||||
self.query.disk_stats_every().clone(),
|
||||
self.query.report_error(),
|
||||
)?;
|
||||
let f = collect_plain_events_json(s, self.timeout, t_bin_count, u64::MAX, self.query.do_log());
|
||||
let s = futures_util::stream::once(f).map(|item| match item {
|
||||
Ok(item) => Ok(Bytes::from(serde_json::to_vec(&item)?)),
|
||||
Err(e) => Err(e.into()),
|
||||
});
|
||||
Ok(Box::pin(s) as Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>)
|
||||
}
|
||||
Ok(None) => {
|
||||
info!("BinnedJsonChannelExec no covering range for prebinned, merge from remotes instead {range:?}");
|
||||
// TODO let BinnedQuery provide the DiskIoTune and pass to RawEventsQuery:
|
||||
let evq = RawEventsQuery::new(
|
||||
self.query.channel().clone(),
|
||||
self.query.range().clone(),
|
||||
self.query.agg_kind().clone(),
|
||||
);
|
||||
let x_bin_count = x_bin_count(&shape, self.query.agg_kind());
|
||||
let s = MergedFromRemotes::<ENP>::new(evq, perf_opts, self.node_config.node_config.cluster.clone());
|
||||
let s = TBinnerStream::<_, <ENP as EventsNodeProcessor>::Output>::new(
|
||||
s,
|
||||
range,
|
||||
x_bin_count,
|
||||
self.query.agg_kind().do_time_weighted(),
|
||||
);
|
||||
let f = collect_plain_events_json(s, self.timeout, t_bin_count, u64::MAX, self.query.do_log());
|
||||
let s = futures_util::stream::once(f).map(|item| match item {
|
||||
Ok(item) => Ok(Bytes::from(serde_json::to_vec(&item)?)),
|
||||
Err(e) => Err(e.into()),
|
||||
});
|
||||
Ok(Box::pin(s) as Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>)
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
}?;
|
||||
Ok(souter)
|
||||
}
|
||||
|
||||
fn empty() -> Self::Output {
|
||||
info!("BinnedJsonChannelExec fn empty");
|
||||
Box::pin(futures_util::stream::empty())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn binned_json(
|
||||
query: &BinnedQuery,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
node_config: &NodeConfigCached,
|
||||
) -> Result<Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>, Error> {
|
||||
let ret = channel_exec(
|
||||
BinnedJsonChannelExec::new(query.clone(), query.timeout(), node_config.clone()),
|
||||
query.channel(),
|
||||
query.range(),
|
||||
scalar_type,
|
||||
shape,
|
||||
query.agg_kind().clone(),
|
||||
node_config,
|
||||
)
|
||||
.await?;
|
||||
Ok(Box::pin(ret))
|
||||
}
|
||||
|
||||
pub trait EventsDecoder {
|
||||
type Output;
|
||||
fn ingest(&mut self, event: &[u8]);
|
||||
fn result(&mut self) -> Self::Output;
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
use err::Error;
|
||||
use http::request::Parts;
|
||||
use netpod::query::{agg_kind_from_binning_scheme, binning_scheme_append_to_url, CacheUsage};
|
||||
use netpod::timeunits::SEC;
|
||||
use netpod::{AggKind, AppendToUrl, ByteSize, Channel, FromUrl, PreBinnedPatchCoord, ScalarType, Shape};
|
||||
use std::collections::BTreeMap;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PreBinnedQuery {
|
||||
patch: PreBinnedPatchCoord,
|
||||
agg_kind: AggKind,
|
||||
channel: Channel,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
cache_usage: CacheUsage,
|
||||
disk_io_buffer_size: usize,
|
||||
disk_stats_every: ByteSize,
|
||||
report_error: bool,
|
||||
}
|
||||
|
||||
impl PreBinnedQuery {
|
||||
pub fn new(
|
||||
patch: PreBinnedPatchCoord,
|
||||
channel: Channel,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
agg_kind: AggKind,
|
||||
cache_usage: CacheUsage,
|
||||
disk_io_buffer_size: usize,
|
||||
disk_stats_every: ByteSize,
|
||||
report_error: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
patch,
|
||||
channel,
|
||||
scalar_type,
|
||||
shape,
|
||||
agg_kind,
|
||||
cache_usage,
|
||||
disk_io_buffer_size,
|
||||
disk_stats_every,
|
||||
report_error,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_url(url: &Url) -> Result<Self, Error> {
|
||||
let mut pairs = BTreeMap::new();
|
||||
for (j, k) in url.query_pairs() {
|
||||
pairs.insert(j.to_string(), k.to_string());
|
||||
}
|
||||
let pairs = pairs;
|
||||
let bin_t_len: u64 = pairs
|
||||
.get("binTlen")
|
||||
.ok_or_else(|| Error::with_msg("missing binTlen"))?
|
||||
.parse()?;
|
||||
let patch_t_len: u64 = pairs
|
||||
.get("patchTlen")
|
||||
.ok_or_else(|| Error::with_msg("missing patchTlen"))?
|
||||
.parse()?;
|
||||
let patch_ix = pairs
|
||||
.get("patchIx")
|
||||
.ok_or_else(|| Error::with_msg("missing patchIx"))?
|
||||
.parse()?;
|
||||
let disk_stats_every = pairs
|
||||
.get("diskStatsEveryKb")
|
||||
.ok_or_else(|| Error::with_msg("missing diskStatsEveryKb"))?;
|
||||
let disk_stats_every = disk_stats_every
|
||||
.parse()
|
||||
.map_err(|e| Error::with_msg(format!("can not parse diskStatsEveryKb {:?}", e)))?;
|
||||
let scalar_type = pairs
|
||||
.get("scalarType")
|
||||
.ok_or_else(|| Error::with_msg("missing scalarType"))
|
||||
.map(|x| ScalarType::from_url_str(&x))??;
|
||||
let shape = pairs
|
||||
.get("shape")
|
||||
.ok_or_else(|| Error::with_msg("missing shape"))
|
||||
.map(|x| Shape::from_url_str(&x))??;
|
||||
let ret = Self {
|
||||
patch: PreBinnedPatchCoord::new(bin_t_len * SEC, patch_t_len * SEC, patch_ix),
|
||||
channel: Channel::from_pairs(&pairs)?,
|
||||
scalar_type,
|
||||
shape,
|
||||
agg_kind: agg_kind_from_binning_scheme(&pairs).unwrap_or(AggKind::DimXBins1),
|
||||
cache_usage: CacheUsage::from_pairs(&pairs)?,
|
||||
disk_io_buffer_size: pairs
|
||||
.get("diskIoBufferSize")
|
||||
.map_or("4096", |k| k)
|
||||
.parse()
|
||||
.map_err(|e| Error::with_msg(format!("can not parse diskIoBufferSize {:?}", e)))?,
|
||||
disk_stats_every: ByteSize::kb(disk_stats_every),
|
||||
report_error: pairs
|
||||
.get("reportError")
|
||||
.map_or("false", |k| k)
|
||||
.parse()
|
||||
.map_err(|e| Error::with_msg(format!("can not parse reportError {:?}", e)))?,
|
||||
};
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
pub fn from_request(head: &Parts) -> Result<Self, Error> {
|
||||
let s1 = format!("dummy:{}", head.uri);
|
||||
let url = Url::parse(&s1)?;
|
||||
Self::from_url(&url)
|
||||
}
|
||||
|
||||
pub fn patch(&self) -> &PreBinnedPatchCoord {
|
||||
&self.patch
|
||||
}
|
||||
|
||||
pub fn report_error(&self) -> bool {
|
||||
self.report_error
|
||||
}
|
||||
|
||||
pub fn channel(&self) -> &Channel {
|
||||
&self.channel
|
||||
}
|
||||
|
||||
pub fn scalar_type(&self) -> &ScalarType {
|
||||
&self.scalar_type
|
||||
}
|
||||
|
||||
pub fn shape(&self) -> &Shape {
|
||||
&self.shape
|
||||
}
|
||||
|
||||
pub fn agg_kind(&self) -> &AggKind {
|
||||
&self.agg_kind
|
||||
}
|
||||
|
||||
pub fn disk_stats_every(&self) -> ByteSize {
|
||||
self.disk_stats_every.clone()
|
||||
}
|
||||
|
||||
pub fn cache_usage(&self) -> CacheUsage {
|
||||
self.cache_usage.clone()
|
||||
}
|
||||
|
||||
pub fn disk_io_buffer_size(&self) -> usize {
|
||||
self.disk_io_buffer_size
|
||||
}
|
||||
}
|
||||
|
||||
impl AppendToUrl for PreBinnedQuery {
|
||||
fn append_to_url(&self, url: &mut Url) {
|
||||
self.patch.append_to_url(url);
|
||||
binning_scheme_append_to_url(&self.agg_kind, url);
|
||||
self.channel.append_to_url(url);
|
||||
self.shape.append_to_url(url);
|
||||
self.scalar_type.append_to_url(url);
|
||||
let mut g = url.query_pairs_mut();
|
||||
// TODO add also impl AppendToUrl for these if applicable:
|
||||
g.append_pair("cacheUsage", &format!("{}", self.cache_usage.query_param_value()));
|
||||
g.append_pair("diskIoBufferSize", &format!("{}", self.disk_io_buffer_size));
|
||||
g.append_pair("diskStatsEveryKb", &format!("{}", self.disk_stats_every.bytes() / 1024));
|
||||
g.append_pair("reportError", &format!("{}", self.report_error()));
|
||||
}
|
||||
}
|
||||
@@ -1,363 +0,0 @@
|
||||
use crate::agg::enp::Identity;
|
||||
use crate::decode::{BigEndian, Endianness, EventValueFromBytes, EventValueShape, LittleEndian, NumFromBytes};
|
||||
use crate::decode::{EventValuesDim0Case, EventValuesDim1Case};
|
||||
use crate::merge::mergedfromremotes::MergedFromRemotes;
|
||||
use bytes::Bytes;
|
||||
use err::Error;
|
||||
use futures_core::Stream;
|
||||
use futures_util::future::FutureExt;
|
||||
use futures_util::StreamExt;
|
||||
use items::numops::{BoolNum, NumOps, StringNum};
|
||||
use items::scalarevents::ScalarEvents;
|
||||
use items::streams::{collect_plain_events_json, Collectable};
|
||||
use items::{Clearable, EventsNodeProcessor, Framable, FrameType, FrameTypeStatic};
|
||||
use items::{PushableIndex, Sitemty, TimeBinnableType};
|
||||
use netpod::query::{PlainEventsQuery, RawEventsQuery};
|
||||
use netpod::{AggKind, ByteOrder, Channel, NanoRange, NodeConfigCached, PerfOpts, ScalarType, Shape};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::fmt::Debug;
|
||||
use std::pin::Pin;
|
||||
use std::time::Duration;
|
||||
|
||||
pub trait ChannelExecFunction {
|
||||
type Output;
|
||||
|
||||
fn exec<NTY, END, EVS, ENP>(
|
||||
self,
|
||||
byte_order: END,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
event_value_shape: EVS,
|
||||
events_node_proc: ENP,
|
||||
) -> Result<Self::Output, Error>
|
||||
where
|
||||
NTY: NumOps + NumFromBytes<NTY, END> + 'static,
|
||||
END: Endianness + 'static,
|
||||
EVS: EventValueShape<NTY, END> + EventValueFromBytes<NTY, END> + 'static,
|
||||
ENP: EventsNodeProcessor<Input = <EVS as EventValueFromBytes<NTY, END>>::Batch> + 'static,
|
||||
// TODO require these things in general?
|
||||
<ENP as EventsNodeProcessor>::Output: Debug + Collectable + PushableIndex + Clearable,
|
||||
<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output: Debug
|
||||
+ TimeBinnableType<Output = <<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>
|
||||
+ Collectable
|
||||
+ Unpin,
|
||||
Sitemty<<ENP as EventsNodeProcessor>::Output>: FrameType + Framable + 'static,
|
||||
Sitemty<<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>:
|
||||
FrameType + Framable + DeserializeOwned;
|
||||
|
||||
fn empty() -> Self::Output;
|
||||
}
|
||||
|
||||
fn channel_exec_nty_end_evs_enp<F, NTY, END, EVS, ENP>(
|
||||
f: F,
|
||||
byte_order: END,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
event_value_shape: EVS,
|
||||
events_node_proc: ENP,
|
||||
) -> Result<F::Output, Error>
|
||||
where
|
||||
F: ChannelExecFunction,
|
||||
NTY: NumOps + NumFromBytes<NTY, END> + 'static,
|
||||
END: Endianness + 'static,
|
||||
EVS: EventValueShape<NTY, END> + EventValueFromBytes<NTY, END> + 'static,
|
||||
ENP: EventsNodeProcessor<Input = <EVS as EventValueFromBytes<NTY, END>>::Batch> + 'static,
|
||||
// TODO require these things in general?
|
||||
<ENP as EventsNodeProcessor>::Output: Debug + Collectable + PushableIndex + Clearable,
|
||||
<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output: Debug
|
||||
+ TimeBinnableType<Output = <<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>
|
||||
+ Collectable
|
||||
+ Unpin,
|
||||
// TODO shouldn't one of FrameType or FrameTypeStatic be enough?
|
||||
Sitemty<<ENP as EventsNodeProcessor>::Output>: FrameType + FrameTypeStatic + Framable + 'static,
|
||||
Sitemty<<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>:
|
||||
FrameType + FrameTypeStatic + Framable + DeserializeOwned,
|
||||
{
|
||||
Ok(f.exec(byte_order, scalar_type, shape, event_value_shape, events_node_proc)?)
|
||||
}
|
||||
|
||||
fn channel_exec_nty_end<F, NTY, END>(
|
||||
f: F,
|
||||
byte_order: END,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
agg_kind: AggKind,
|
||||
) -> Result<F::Output, Error>
|
||||
where
|
||||
F: ChannelExecFunction,
|
||||
NTY: NumOps + NumFromBytes<NTY, END> + 'static,
|
||||
END: Endianness + 'static,
|
||||
ScalarEvents<NTY>: Collectable,
|
||||
{
|
||||
match shape {
|
||||
Shape::Scalar => {
|
||||
let evs = EventValuesDim0Case::new();
|
||||
match agg_kind {
|
||||
AggKind::EventBlobs => panic!(),
|
||||
AggKind::Plain => {
|
||||
let events_node_proc = <<EventValuesDim0Case<NTY> as EventValueShape<NTY, END>>::NumXAggPlain as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
AggKind::TimeWeightedScalar => {
|
||||
let events_node_proc = <<EventValuesDim0Case<NTY> as EventValueShape<NTY, END>>::NumXAggToSingleBin as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
AggKind::DimXBins1 => {
|
||||
let events_node_proc = <<EventValuesDim0Case<NTY> as EventValueShape<NTY, END>>::NumXAggToSingleBin as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
AggKind::DimXBinsN(_) => {
|
||||
let events_node_proc = <<EventValuesDim0Case<NTY> as EventValueShape<NTY, END>>::NumXAggToNBins as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
AggKind::Stats1 => {
|
||||
let events_node_proc = <<EventValuesDim0Case<NTY> as EventValueShape<NTY, END>>::NumXAggToStats1 as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
}
|
||||
}
|
||||
Shape::Wave(n) => {
|
||||
let evs = EventValuesDim1Case::new(n);
|
||||
match agg_kind {
|
||||
AggKind::EventBlobs => panic!(),
|
||||
AggKind::Plain => {
|
||||
let events_node_proc = <<EventValuesDim1Case<NTY> as EventValueShape<NTY, END>>::NumXAggPlain as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
AggKind::TimeWeightedScalar => {
|
||||
let events_node_proc = <<EventValuesDim1Case<NTY> as EventValueShape<NTY, END>>::NumXAggToSingleBin as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
AggKind::DimXBins1 => {
|
||||
let events_node_proc = <<EventValuesDim1Case<NTY> as EventValueShape<NTY, END>>::NumXAggToSingleBin as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
AggKind::DimXBinsN(_) => {
|
||||
let events_node_proc = <<EventValuesDim1Case<NTY> as EventValueShape<NTY, END>>::NumXAggToNBins as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
AggKind::Stats1 => {
|
||||
let events_node_proc = <<EventValuesDim1Case<NTY> as EventValueShape<NTY, END>>::NumXAggToStats1 as EventsNodeProcessor>::create(shape.clone(), agg_kind.clone());
|
||||
channel_exec_nty_end_evs_enp(f, byte_order, scalar_type, shape, evs, events_node_proc)
|
||||
}
|
||||
}
|
||||
}
|
||||
Shape::Image(..) => {
|
||||
// TODO needed for binning or json event retrieval
|
||||
err::todoval()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! match_end {
|
||||
($f:expr, $nty:ident, $end:expr, $scalar_type:expr, $shape:expr, $agg_kind:expr, $node_config:expr) => {
|
||||
match $end {
|
||||
ByteOrder::Little => {
|
||||
channel_exec_nty_end::<_, $nty, _>($f, LittleEndian {}, $scalar_type, $shape, $agg_kind)
|
||||
}
|
||||
ByteOrder::Big => channel_exec_nty_end::<_, $nty, _>($f, BigEndian {}, $scalar_type, $shape, $agg_kind),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn channel_exec_config<F>(
|
||||
f: F,
|
||||
scalar_type: ScalarType,
|
||||
byte_order: ByteOrder,
|
||||
shape: Shape,
|
||||
agg_kind: AggKind,
|
||||
_node_config: &NodeConfigCached,
|
||||
) -> Result<F::Output, Error>
|
||||
where
|
||||
F: ChannelExecFunction,
|
||||
{
|
||||
match scalar_type {
|
||||
ScalarType::U8 => match_end!(f, u8, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::U16 => match_end!(f, u16, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::U32 => match_end!(f, u32, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::U64 => match_end!(f, u64, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::I8 => match_end!(f, i8, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::I16 => match_end!(f, i16, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::I32 => match_end!(f, i32, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::I64 => match_end!(f, i64, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::F32 => match_end!(f, f32, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::F64 => match_end!(f, f64, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::BOOL => match_end!(f, BoolNum, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
ScalarType::STRING => match_end!(f, StringNum, byte_order, scalar_type, shape, agg_kind, node_config),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn channel_exec<F>(
|
||||
f: F,
|
||||
_channel: &Channel,
|
||||
_range: &NanoRange,
|
||||
scalar_type: ScalarType,
|
||||
shape: Shape,
|
||||
agg_kind: AggKind,
|
||||
node_config: &NodeConfigCached,
|
||||
) -> Result<F::Output, Error>
|
||||
where
|
||||
F: ChannelExecFunction,
|
||||
{
|
||||
let ret = channel_exec_config(
|
||||
f,
|
||||
scalar_type,
|
||||
// TODO TODO TODO is the byte order ever important here?
|
||||
ByteOrder::Little,
|
||||
shape,
|
||||
agg_kind,
|
||||
node_config,
|
||||
)?;
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
pub struct PlainEvents {
|
||||
channel: Channel,
|
||||
range: NanoRange,
|
||||
agg_kind: AggKind,
|
||||
node_config: NodeConfigCached,
|
||||
}
|
||||
|
||||
impl PlainEvents {
|
||||
pub fn new(channel: Channel, range: NanoRange, node_config: NodeConfigCached) -> Self {
|
||||
Self {
|
||||
channel,
|
||||
range,
|
||||
agg_kind: AggKind::Plain,
|
||||
node_config,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channel(&self) -> &Channel {
|
||||
&self.channel
|
||||
}
|
||||
|
||||
pub fn range(&self) -> &NanoRange {
|
||||
&self.range
|
||||
}
|
||||
}
|
||||
|
||||
impl ChannelExecFunction for PlainEvents {
|
||||
type Output = Pin<Box<dyn Stream<Item = Box<dyn Framable + Send>> + Send>>;
|
||||
|
||||
fn exec<NTY, END, EVS, ENP>(
|
||||
self,
|
||||
byte_order: END,
|
||||
_scalar_type: ScalarType,
|
||||
_shape: Shape,
|
||||
event_value_shape: EVS,
|
||||
_events_node_proc: ENP,
|
||||
) -> Result<Self::Output, Error>
|
||||
where
|
||||
NTY: NumOps + NumFromBytes<NTY, END> + 'static,
|
||||
END: Endianness + 'static,
|
||||
EVS: EventValueShape<NTY, END> + EventValueFromBytes<NTY, END> + 'static,
|
||||
ENP: EventsNodeProcessor<Input = <EVS as EventValueFromBytes<NTY, END>>::Batch> + 'static,
|
||||
{
|
||||
let _ = byte_order;
|
||||
let _ = event_value_shape;
|
||||
let perf_opts = PerfOpts { inmem_bufcap: 4096 };
|
||||
// TODO let upstream provide DiskIoTune and pass in RawEventsQuery:
|
||||
let evq = RawEventsQuery::new(self.channel, self.range, self.agg_kind);
|
||||
let s = MergedFromRemotes::<Identity<NTY>>::new(evq, perf_opts, self.node_config.node_config.cluster);
|
||||
let s = s.map(|item| Box::new(item) as Box<dyn Framable + Send>);
|
||||
Ok(Box::pin(s))
|
||||
}
|
||||
|
||||
fn empty() -> Self::Output {
|
||||
Box::pin(futures_util::stream::empty())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlainEventsJson {
|
||||
query: PlainEventsQuery,
|
||||
channel: Channel,
|
||||
range: NanoRange,
|
||||
agg_kind: AggKind,
|
||||
timeout: Duration,
|
||||
node_config: NodeConfigCached,
|
||||
events_max: u64,
|
||||
do_log: bool,
|
||||
}
|
||||
|
||||
impl PlainEventsJson {
|
||||
pub fn new(
|
||||
query: PlainEventsQuery,
|
||||
channel: Channel,
|
||||
range: NanoRange,
|
||||
timeout: Duration,
|
||||
node_config: NodeConfigCached,
|
||||
events_max: u64,
|
||||
do_log: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
query,
|
||||
channel,
|
||||
range,
|
||||
agg_kind: AggKind::Plain,
|
||||
timeout,
|
||||
node_config,
|
||||
events_max,
|
||||
do_log,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channel(&self) -> &Channel {
|
||||
&self.channel
|
||||
}
|
||||
|
||||
pub fn range(&self) -> &NanoRange {
|
||||
&self.range
|
||||
}
|
||||
}
|
||||
|
||||
impl ChannelExecFunction for PlainEventsJson {
|
||||
type Output = Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>;
|
||||
|
||||
fn exec<NTY, END, EVS, ENP>(
|
||||
self,
|
||||
_byte_order: END,
|
||||
_scalar_type: ScalarType,
|
||||
_shape: Shape,
|
||||
_event_value_shape: EVS,
|
||||
_events_node_proc: ENP,
|
||||
) -> Result<Self::Output, Error>
|
||||
where
|
||||
NTY: NumOps + NumFromBytes<NTY, END> + 'static,
|
||||
END: Endianness + 'static,
|
||||
EVS: EventValueShape<NTY, END> + EventValueFromBytes<NTY, END> + 'static,
|
||||
ENP: EventsNodeProcessor<Input = <EVS as EventValueFromBytes<NTY, END>>::Batch> + 'static,
|
||||
// TODO require these things in general?
|
||||
<ENP as EventsNodeProcessor>::Output: Debug + Collectable + PushableIndex + Clearable,
|
||||
<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output: Debug
|
||||
+ TimeBinnableType<Output = <<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>
|
||||
+ Collectable
|
||||
+ Unpin,
|
||||
Sitemty<<ENP as EventsNodeProcessor>::Output>: FrameType + Framable + 'static,
|
||||
Sitemty<<<ENP as EventsNodeProcessor>::Output as TimeBinnableType>::Output>:
|
||||
FrameType + Framable + DeserializeOwned,
|
||||
{
|
||||
let perf_opts = PerfOpts { inmem_bufcap: 4096 };
|
||||
// TODO let upstream provide DiskIoTune and set in RawEventsQuery.
|
||||
let mut evq = RawEventsQuery::new(self.channel, self.range, self.agg_kind);
|
||||
evq.do_test_main_error = self.query.do_test_main_error();
|
||||
evq.do_test_stream_error = self.query.do_test_stream_error();
|
||||
let s = MergedFromRemotes::<ENP>::new(evq, perf_opts, self.node_config.node_config.cluster);
|
||||
let f = collect_plain_events_json(s, self.timeout, 0, self.events_max, self.do_log);
|
||||
let f = FutureExt::map(f, |item| match item {
|
||||
Ok(item) => {
|
||||
// TODO add channel entry info here?
|
||||
//let obj = item.as_object_mut().unwrap();
|
||||
//obj.insert("channelName", JsonValue::String(en));
|
||||
Ok(Bytes::from(serde_json::to_vec(&item)?))
|
||||
}
|
||||
Err(e) => Err(e.into()),
|
||||
});
|
||||
let s = futures_util::stream::once(f);
|
||||
Ok(Box::pin(s))
|
||||
}
|
||||
|
||||
fn empty() -> Self::Output {
|
||||
Box::pin(futures_util::stream::empty())
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
pub mod agg;
|
||||
#[cfg(test)]
|
||||
pub mod aggtest;
|
||||
pub mod binned;
|
||||
pub mod binnedstream;
|
||||
pub mod cache;
|
||||
pub mod channelexec;
|
||||
pub mod dataopen;
|
||||
pub mod decode;
|
||||
pub mod eventblobs;
|
||||
|
||||
Reference in New Issue
Block a user