Move /api/1/ related proxy functionality

This commit is contained in:
Dominik Werder
2021-06-17 18:32:05 +02:00
parent 7077d6b09a
commit 0d73251db8
16 changed files with 848 additions and 142 deletions

View File

@@ -655,6 +655,7 @@ where
S: Stream<Item = Sitemty<T>> + Unpin,
T: Collectable,
{
info!("\n\nConstruct deadline with timeout {:?}\n\n", timeout);
let deadline = tokio::time::Instant::now() + timeout;
let mut collector = <T as Collectable>::new_collector(bin_count_exp);
let mut i1 = 0;
@@ -711,15 +712,11 @@ pub struct BinnedJsonChannelExec {
}
impl BinnedJsonChannelExec {
pub fn new(query: BinnedQuery, node_config: NodeConfigCached) -> Self {
info!(
"BinnedJsonChannelExec AggKind: {:?}\n--------------------------------------------------------------",
query.agg_kind()
);
pub fn new(query: BinnedQuery, timeout: Duration, node_config: NodeConfigCached) -> Self {
Self {
query,
node_config,
timeout: Duration::from_millis(3000),
timeout,
}
}
}
@@ -819,7 +816,7 @@ pub async fn binned_json(
node_config: &NodeConfigCached,
) -> Result<Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send>>, Error> {
let ret = channel_exec(
BinnedJsonChannelExec::new(query.clone(), node_config.clone()),
BinnedJsonChannelExec::new(query.clone(), query.timeout(), node_config.clone()),
query.channel(),
query.range(),
query.agg_kind().clone(),

View File

@@ -148,7 +148,6 @@ fn make_num_pipeline(
}
}
// TODO after the refactor, return direct value instead of boxed.
pub async fn pre_binned_bytes_for_http(
node_config: &NodeConfigCached,
query: &PreBinnedQuery,

View File

@@ -76,7 +76,7 @@ impl PreBinnedQuery {
self.patch.to_url_params_strings(),
self.channel.backend,
self.channel.name,
binning_scheme_string(&self.agg_kind),
binning_scheme_query_string(&self.agg_kind),
self.cache_usage,
self.disk_stats_every.bytes() / 1024,
self.report_error(),
@@ -293,7 +293,7 @@ impl BinnedQuery {
self.bin_count,
Utc.timestamp_nanos(self.range.beg as i64).format(date_fmt),
Utc.timestamp_nanos(self.range.end as i64).format(date_fmt),
binning_scheme_string(&self.agg_kind),
binning_scheme_query_string(&self.agg_kind),
self.disk_stats_every.bytes() / 1024,
self.timeout.as_millis(),
self.abort_after_bin_count,
@@ -301,17 +301,16 @@ impl BinnedQuery {
}
}
fn binning_scheme_string(agg_kind: &AggKind) -> String {
fn binning_scheme_query_string(agg_kind: &AggKind) -> String {
match agg_kind {
AggKind::Plain => "fullValue".into(),
AggKind::DimXBins1 => "toScalarX".into(),
AggKind::DimXBinsN(n) => format!("binnedXcount{}", n),
AggKind::DimXBinsN(n) => format!("binnedX&binnedXcount={}", n),
}
}
fn agg_kind_from_binning_scheme(params: &BTreeMap<String, String>) -> Result<AggKind, Error> {
let key = "binningScheme";
let tok1 = "binnedXcount";
let s = params
.get(key)
.map_or(Err(Error::with_msg(format!("can not find {}", key))), |k| Ok(k))?;
@@ -319,8 +318,9 @@ fn agg_kind_from_binning_scheme(params: &BTreeMap<String, String>) -> Result<Agg
AggKind::Plain
} else if s == "toScalarX" {
AggKind::DimXBins1
} else if s.starts_with(tok1) {
AggKind::DimXBinsN(s[tok1.len()..].parse()?)
} else if s == "binnedX" {
let u = params.get("binnedXcount").map_or("1", |k| k).parse()?;
AggKind::DimXBinsN(u)
} else {
return Err(Error::with_msg("can not extract binningScheme"));
};

View File

@@ -301,6 +301,7 @@ where
S: Stream<Item = Sitemty<T>> + Unpin,
T: Collectable + Debug,
{
info!("\n\nConstruct deadline with timeout {:?}\n\n", timeout);
let deadline = tokio::time::Instant::now() + timeout;
// TODO in general a Collector does not need to know about the expected number of bins.
// It would make more sense for some specific Collector kind to know.
@@ -335,7 +336,6 @@ where
collector.set_range_complete();
}
RangeCompletableItem::Data(item) => {
info!("collect_plain_events_json GOT ITEM {:?}", item);
collector.ingest(&item);
i1 += 1;
}

View File

@@ -19,7 +19,7 @@ impl PlainEventsQuery {
channel,
range,
report_error: false,
timeout: Duration::from_millis(2000),
timeout: Duration::from_millis(10000),
}
}
@@ -40,7 +40,7 @@ impl PlainEventsQuery {
.map_err(|e| Error::with_msg(format!("can not parse reportError {:?}", e)))?,
timeout: params
.get("timeout")
.map_or("2000", |k| k)
.map_or("10000", |k| k)
.parse::<u64>()
.map(|k| Duration::from_millis(k))
.map_err(|e| Error::with_msg(format!("can not parse timeout {:?}", e)))?,
@@ -98,7 +98,7 @@ impl PlainEventsJsonQuery {
channel,
range,
report_error: false,
timeout: Duration::from_millis(2000),
timeout: Duration::from_millis(10000),
}
}
@@ -119,7 +119,7 @@ impl PlainEventsJsonQuery {
.map_err(|e| Error::with_msg(format!("can not parse reportError {:?}", e)))?,
timeout: params
.get("timeout")
.map_or("2000", |k| k)
.map_or("10000", |k| k)
.parse::<u64>()
.map(|k| Duration::from_millis(k))
.map_err(|e| Error::with_msg(format!("can not parse timeout {:?}", e)))?,