mirror of
https://github.com/zaphar/Heracles.git
synced 2025-07-23 04:29:48 -04:00
dev: do query filter modifications
This commit is contained in:
parent
cef7b42fac
commit
a620cd2b1b
@ -48,7 +48,6 @@ impl<'conn> PromQueryConn<'conn> {
|
|||||||
meta,
|
meta,
|
||||||
span: None,
|
span: None,
|
||||||
filters: None,
|
filters: None,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +70,33 @@ impl<'conn> PromQueryConn<'conn> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_query(&self) -> String {
|
||||||
|
let first = true;
|
||||||
|
let mut filter_string = String::new();
|
||||||
|
if let Some(filters) = self.filters {
|
||||||
|
for (k, v) in filters.iter() {
|
||||||
|
if !first {
|
||||||
|
filter_string.push_str(",");
|
||||||
|
}
|
||||||
|
filter_string.push_str(*k);
|
||||||
|
filter_string.push_str("=~");
|
||||||
|
filter_string.push('"');
|
||||||
|
filter_string.push_str(*v);
|
||||||
|
filter_string.push('"');
|
||||||
|
}
|
||||||
|
filter_string.push(',');
|
||||||
|
}
|
||||||
|
if self.query.contains("FILTERS") {
|
||||||
|
// TODO(jwall): replace the FILTERS placeholder with our filters
|
||||||
|
self.query.replace("FILTERS", &filter_string)
|
||||||
|
} else {
|
||||||
|
let mut filter_string_curly = String::from("{");
|
||||||
|
filter_string_curly.push_str(&filter_string);
|
||||||
|
// TODO(jwall): Place them after the first `{`
|
||||||
|
self.query.replace("{", &filter_string_curly)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_results(&self) -> anyhow::Result<PromqlResult> {
|
pub async fn get_results(&self) -> anyhow::Result<PromqlResult> {
|
||||||
debug!("Getting results for query");
|
debug!("Getting results for query");
|
||||||
let client = Client::try_from(self.source)?;
|
let client = Client::try_from(self.source)?;
|
||||||
@ -100,16 +126,18 @@ impl<'conn> PromQueryConn<'conn> {
|
|||||||
(start.timestamp(), end.timestamp(), 30 as f64)
|
(start.timestamp(), end.timestamp(), 30 as f64)
|
||||||
};
|
};
|
||||||
//debug!(start, end, step_resolution, "Running Query with range values");
|
//debug!(start, end, step_resolution, "Running Query with range values");
|
||||||
|
let query = self.get_query();
|
||||||
|
debug!(?query, "Using promql query");
|
||||||
match self.query_type {
|
match self.query_type {
|
||||||
QueryType::Range => {
|
QueryType::Range => {
|
||||||
let results = client
|
let results = client
|
||||||
.query_range(self.query, start, end, step_resolution)
|
.query_range(&query, start, end, step_resolution)
|
||||||
.get()
|
.get()
|
||||||
.await?;
|
.await?;
|
||||||
//debug!(?results, "range results");
|
//debug!(?results, "range results");
|
||||||
Ok(results)
|
Ok(results)
|
||||||
}
|
}
|
||||||
QueryType::Scalar => Ok(client.query(self.query).get().await?),
|
QueryType::Scalar => Ok(client.query(&query).get().await?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user