for some reason values output is always zero
This commit is contained in:
parent
8c8c183e65
commit
9417961d78
@ -230,3 +230,37 @@ pub fn get_query_window_seconds_from_params(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_stats_column_from_params(
|
||||||
|
params: &HashMap<String, String>
|
||||||
|
) -> Result<&str, FrontendErrorResponse> {
|
||||||
|
params.get("query_stats_column").map_or_else(
|
||||||
|
|| {
|
||||||
|
Ok("frontend_requests")
|
||||||
|
},
|
||||||
|
|query_stats_column: &String| {
|
||||||
|
// Must be one of: Otherwise respond with an error ...
|
||||||
|
match query_stats_column.as_str() {
|
||||||
|
"frontend_requests" |
|
||||||
|
"backend_requests" |
|
||||||
|
"cache_hits" |
|
||||||
|
"cache_misses" |
|
||||||
|
"no_servers" |
|
||||||
|
"sum_request_bytes" |
|
||||||
|
"sum_response_bytes" |
|
||||||
|
"sum_response_millis" => Ok(query_stats_column),
|
||||||
|
_ => Err(FrontendErrorResponse::BadRequest(
|
||||||
|
"Unable to parse query_stats_column. It must be one of: \
|
||||||
|
frontend_requests, \
|
||||||
|
backend_requests, \
|
||||||
|
cache_hits, \
|
||||||
|
cache_misses, \
|
||||||
|
no_servers, \
|
||||||
|
sum_request_bytes, \
|
||||||
|
sum_response_bytes, \
|
||||||
|
sum_response_millis".to_string()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
@ -22,6 +22,7 @@ use itertools::Itertools;
|
|||||||
use log::info;
|
use log::info;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::{json};
|
use serde_json::{json};
|
||||||
|
use crate::http_params::get_stats_column_from_params;
|
||||||
|
|
||||||
// TODO: include chain_id, method, and some other things in this struct
|
// TODO: include chain_id, method, and some other things in this struct
|
||||||
#[derive(Debug, Default, FromDataPoint, Serialize)]
|
#[derive(Debug, Default, FromDataPoint, Serialize)]
|
||||||
@ -66,6 +67,7 @@ pub async fn query_user_stats<'a>(
|
|||||||
let query_start = get_query_start_from_params(params)?.timestamp();
|
let query_start = get_query_start_from_params(params)?.timestamp();
|
||||||
let query_stop = get_query_stop_from_params(params)?.timestamp();
|
let query_stop = get_query_stop_from_params(params)?.timestamp();
|
||||||
let chain_id = get_chain_id_from_params(app, params)?;
|
let chain_id = get_chain_id_from_params(app, params)?;
|
||||||
|
let stats_column = get_stats_column_from_params(params)?;
|
||||||
|
|
||||||
// query_window_seconds must be provided, and should be not 1s (?) by default ..
|
// query_window_seconds must be provided, and should be not 1s (?) by default ..
|
||||||
|
|
||||||
@ -119,11 +121,15 @@ pub async fn query_user_stats<'a>(
|
|||||||
// StatType::Aggregated => f!(r#"|> filter(fn: (r) => r["_field"] == "frontend_requests")"#),
|
// StatType::Aggregated => f!(r#"|> filter(fn: (r) => r["_field"] == "frontend_requests")"#),
|
||||||
// Let's show all endpoints in a detailed stats
|
// Let's show all endpoints in a detailed stats
|
||||||
// StatType::Aggregated => "".to_string(), // f!(r#"|> filter(fn: (r) => r["_field"] == "frontend_requests")"#),
|
// StatType::Aggregated => "".to_string(), // f!(r#"|> filter(fn: (r) => r["_field"] == "frontend_requests")"#),
|
||||||
StatType::Aggregated => f!(r#"|> filter(fn: (r) => r["_field"] == "frontend_requests" or r["_field"] == "backend_requests" or r["_field"] == "cache_hits" or r["_field"] == "cache_misses" or r["_field"] == "no_servers" or r["_field"] == "sum_request_bytes" or r["_field"] == "sum_response_bytes" or r["_field"] == "sum_response_millis")"#),
|
StatType::Aggregated => {
|
||||||
|
f!(r#"|> filter(fn: (r) => r["_field"] == "{stats_column}")"#)
|
||||||
|
},
|
||||||
|
// TODO: Detailed should still filter it, but just "group-by" method (call it once per each method ...
|
||||||
StatType::Detailed => "".to_string(),
|
StatType::Detailed => "".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("Query start and stop are: {:?} {:?}", query_start, query_stop);
|
info!("Query start and stop are: {:?} {:?}", query_start, query_stop);
|
||||||
|
info!("Query column parameters are: {:?}", stats_column);
|
||||||
info!("Query measurement is: {:?}", measurement);
|
info!("Query measurement is: {:?}", measurement);
|
||||||
info!("Filters are: {:?} {:?}", filter_field, filter_chain_id);
|
info!("Filters are: {:?} {:?}", filter_field, filter_chain_id);
|
||||||
info!("Group is: {:?}", group);
|
info!("Group is: {:?}", group);
|
||||||
|
Loading…
Reference in New Issue
Block a user