Add json-framed encoding, docs, refactor
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
pub mod binned;
|
||||
pub mod events;
|
||||
|
||||
use chrono::DateTime;
|
||||
use chrono::TimeZone;
|
||||
use chrono::Utc;
|
||||
use err::Error;
|
||||
use netpod::get_url_query_pairs;
|
||||
use netpod::range::evrange::SeriesRange;
|
||||
@@ -8,6 +11,9 @@ use netpod::AppendToUrl;
|
||||
use netpod::FromUrl;
|
||||
use netpod::HasBackend;
|
||||
use netpod::HasTimeout;
|
||||
use netpod::ToNanos;
|
||||
use netpod::TsNano;
|
||||
use netpod::DATETIME_FMT_6MS;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::BTreeMap;
|
||||
@@ -34,7 +40,12 @@ impl HasBackend for AccountingIngestedBytesQuery {
|
||||
|
||||
impl HasTimeout for AccountingIngestedBytesQuery {
|
||||
fn timeout(&self) -> Duration {
|
||||
Duration::from_millis(5000)
|
||||
Duration::from_millis(10000)
|
||||
}
|
||||
|
||||
fn set_timeout(&mut self, timeout: Duration) {
|
||||
// TODO
|
||||
// self.timeout = Some(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,3 +76,77 @@ impl AppendToUrl for AccountingIngestedBytesQuery {
|
||||
self.range.append_to_url(url);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AccountingToplistQuery {
|
||||
backend: String,
|
||||
ts: TsNano,
|
||||
limit: u32,
|
||||
}
|
||||
|
||||
impl AccountingToplistQuery {
|
||||
pub fn ts(&self) -> TsNano {
|
||||
self.ts.clone()
|
||||
}
|
||||
|
||||
pub fn limit(&self) -> u32 {
|
||||
self.limit
|
||||
}
|
||||
}
|
||||
|
||||
impl HasBackend for AccountingToplistQuery {
|
||||
fn backend(&self) -> &str {
|
||||
&self.backend
|
||||
}
|
||||
}
|
||||
|
||||
impl HasTimeout for AccountingToplistQuery {
|
||||
fn timeout(&self) -> Duration {
|
||||
Duration::from_millis(10000)
|
||||
}
|
||||
|
||||
fn set_timeout(&mut self, timeout: Duration) {
|
||||
// TODO
|
||||
// self.timeout = Some(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
impl FromUrl for AccountingToplistQuery {
|
||||
fn from_url(url: &Url) -> Result<Self, err::Error> {
|
||||
let pairs = get_url_query_pairs(url);
|
||||
Self::from_pairs(&pairs)
|
||||
}
|
||||
|
||||
fn from_pairs(pairs: &BTreeMap<String, String>) -> Result<Self, Error> {
|
||||
let fn1 = |pairs: &BTreeMap<String, String>| {
|
||||
let v = pairs.get("tsDate").ok_or(Error::with_public_msg("missing tsDate"))?;
|
||||
let w = v.parse::<DateTime<Utc>>()?;
|
||||
Ok::<_, Error>(TsNano(w.to_nanos()))
|
||||
};
|
||||
let ret = Self {
|
||||
backend: pairs
|
||||
.get("backend")
|
||||
.ok_or_else(|| Error::with_msg_no_trace("missing backend"))?
|
||||
.to_string(),
|
||||
ts: fn1(pairs)?,
|
||||
limit: pairs.get("limit").map_or(None, |x| x.parse().ok()).unwrap_or(20),
|
||||
};
|
||||
Ok(ret)
|
||||
}
|
||||
}
|
||||
|
||||
impl AppendToUrl for AccountingToplistQuery {
|
||||
fn append_to_url(&self, url: &mut Url) {
|
||||
let mut g = url.query_pairs_mut();
|
||||
g.append_pair("backend", &self.backend);
|
||||
g.append_pair(
|
||||
"ts",
|
||||
&Utc.timestamp_nanos(self.ts.ns() as i64)
|
||||
.format(DATETIME_FMT_6MS)
|
||||
.to_string(),
|
||||
);
|
||||
g.append_pair("limit", &self.limit.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,6 +160,10 @@ impl HasTimeout for BinnedQuery {
|
||||
fn timeout(&self) -> Duration {
|
||||
self.timeout_value()
|
||||
}
|
||||
|
||||
fn set_timeout(&mut self, timeout: Duration) {
|
||||
self.timeout = Some(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
impl FromUrl for BinnedQuery {
|
||||
|
||||
@@ -208,6 +208,10 @@ impl HasTimeout for PlainEventsQuery {
|
||||
fn timeout(&self) -> Duration {
|
||||
self.timeout()
|
||||
}
|
||||
|
||||
fn set_timeout(&mut self, timeout: Duration) {
|
||||
self.timeout = Some(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
impl FromUrl for PlainEventsQuery {
|
||||
|
||||
Reference in New Issue
Block a user