From 9417961d783d10690b055f3bb28276a926cc25c4 Mon Sep 17 00:00:00 2001 From: yenicelik Date: Sun, 12 Mar 2023 16:09:20 +0100 Subject: [PATCH] for some reason values output is always zero --- web3_proxy/src/http_params.rs | 34 ++++++++++++++++++++++++ web3_proxy/src/stats/influxdb_queries.rs | 8 +++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/web3_proxy/src/http_params.rs b/web3_proxy/src/http_params.rs index 9f871e3c..4c4d671a 100644 --- a/web3_proxy/src/http_params.rs +++ b/web3_proxy/src/http_params.rs @@ -230,3 +230,37 @@ pub fn get_query_window_seconds_from_params( }, ) } + +pub fn get_stats_column_from_params( + params: &HashMap +) -> 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() + )) + } + } + ) +} \ No newline at end of file diff --git a/web3_proxy/src/stats/influxdb_queries.rs b/web3_proxy/src/stats/influxdb_queries.rs index 1aafbaf9..949ef034 100644 --- a/web3_proxy/src/stats/influxdb_queries.rs +++ b/web3_proxy/src/stats/influxdb_queries.rs @@ -22,6 +22,7 @@ use itertools::Itertools; use log::info; use serde::Serialize; 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 #[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_stop = get_query_stop_from_params(params)?.timestamp(); 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 .. @@ -119,11 +121,15 @@ pub async fn query_user_stats<'a>( // StatType::Aggregated => f!(r#"|> filter(fn: (r) => r["_field"] == "frontend_requests")"#), // Let's show all endpoints in a detailed stats // 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(), }; info!("Query start and stop are: {:?} {:?}", query_start, query_stop); + info!("Query column parameters are: {:?}", stats_column); info!("Query measurement is: {:?}", measurement); info!("Filters are: {:?} {:?}", filter_field, filter_chain_id); info!("Group is: {:?}", group);