From 76d7e3b4f325f3a642118594668a4be5e10f7e71 Mon Sep 17 00:00:00 2001 From: Dominik Werder Date: Fri, 2 Feb 2024 16:28:19 +0100 Subject: [PATCH] Reduce log --- crates/httpret/src/proxy.rs | 22 +++++------------ crates/httpret/src/proxy/api4/events.rs | 32 +++++++++---------------- crates/query/src/api4/binned.rs | 2 -- 3 files changed, 17 insertions(+), 39 deletions(-) diff --git a/crates/httpret/src/proxy.rs b/crates/httpret/src/proxy.rs index b39fe45..716930d 100644 --- a/crates/httpret/src/proxy.rs +++ b/crates/httpret/src/proxy.rs @@ -204,7 +204,7 @@ async fn proxy_http_service_inner( Ok(proxy_backend_query::(req, ctx, proxy_config).await?) } else if path == "/api/4/binned" { Ok(proxy_backend_query::(req, ctx, proxy_config).await?) - } else if let Some(h) = crate::api4::accounting::AccountingIngestedBytes::handler(&req) { + } else if let Some(_) = crate::api4::accounting::AccountingIngestedBytes::handler(&req) { Ok(proxy_backend_query::(req, ctx, proxy_config).await?) } else if path == "/api/4/channel/config" { Ok(proxy_backend_query::(req, ctx, proxy_config).await?) @@ -510,7 +510,7 @@ where return Ok(response_err_msg(StatusCode::BAD_REQUEST, msg)?); } }; - info!("proxy_backend_query {query:?} {head:?}"); + debug!("proxy_backend_query {query:?} {head:?}"); let query_host = get_query_host_for_backend(&query.backend(), proxy_config)?; // TODO remove this special case // SPECIAL CASE: @@ -522,7 +522,7 @@ where let uri_path: String = if url.as_str().contains("/map/pulse/") { match MapPulseQuery::from_url(&url) { Ok(qu) => { - info!("qu {qu:?}"); + debug!("qu {qu:?}"); format!("/api/4/map/pulse/{}/{}", qu.backend, qu.pulse) } Err(e) => { @@ -533,7 +533,7 @@ where } else { head.uri.path().into() }; - info!("uri_path {uri_path}"); + debug!("uri_path {uri_path}"); let mut url = Url::parse(&format!("{}{}", query_host, uri_path))?; query.append_to_url(&mut url); @@ -558,9 +558,11 @@ where } } } + debug!("send request {req:?}"); let req = req.body(body_empty())?; let fut = async move { + debug!("requesting {:?} {:?} {:?}", req.method(), req.uri(), req.headers()); let mut send_req = httpclient::httpclient::connect_client(req.uri()).await?; let res = send_req.send_request(req).await?; Ok::<_, Error>(res) @@ -596,15 +598,3 @@ fn get_query_host_for_backend(backend: &str, proxy_config: &ProxyConfig) -> Resu } return Err(Error::with_msg(format!("host not found for backend {:?}", backend))); } - -fn get_random_query_host_for_backend(backend: &str, proxy_config: &ProxyConfig) -> Result { - let url = get_query_host_for_backend(backend, proxy_config)?; - // TODO remove special code, make it part of configuration - if url.contains("sf-daqbuf-23.psi.ch") { - let id = 21 + rand::random::() % 13; - let url = url.replace("-23.", &format!("-{id}.")); - Ok(url) - } else { - Ok(url) - } -} diff --git a/crates/httpret/src/proxy/api4/events.rs b/crates/httpret/src/proxy/api4/events.rs index 0f5bc0f..fbe8680 100644 --- a/crates/httpret/src/proxy/api4/events.rs +++ b/crates/httpret/src/proxy/api4/events.rs @@ -1,32 +1,27 @@ use crate::bodystream::response; use crate::err::Error; use crate::proxy::get_query_host_for_backend; +use crate::requests::accepts_cbor_frames; +use crate::requests::accepts_json_or_all; use crate::ReqCtx; use http::header; -use http::HeaderValue; use http::Method; use http::Request; use http::StatusCode; use http::Uri; -use httpclient::body_bytes; use httpclient::body_empty; use httpclient::body_stream; use httpclient::connect_client; -use httpclient::read_body_bytes; use httpclient::Requ; use httpclient::StreamIncoming; use httpclient::StreamResponse; use netpod::get_url_query_pairs; use netpod::log::*; -use netpod::query::api1::Api1Query; use netpod::req_uri_to_url; use netpod::FromUrl; use netpod::HasBackend; use netpod::ProxyConfig; -use netpod::ACCEPT_ALL; use netpod::APP_CBOR; -use netpod::APP_JSON; -use netpod::X_DAQBUF_REQID; use query::api4::events::PlainEventsQuery; pub struct EventsHandler {} @@ -46,21 +41,16 @@ impl EventsHandler { pub async fn handle(&self, req: Requ, ctx: &ReqCtx, proxy_config: &ProxyConfig) -> Result { if req.method() != Method::GET { - return Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(body_empty())?); - } - - let def = HeaderValue::from_static("*/*"); - let accept = req.headers().get(header::ACCEPT).unwrap_or(&def); - let accept = accept.to_str()?; - - if accept.contains(APP_CBOR) { - self.handle_cbor(req, ctx, proxy_config).await - } else if accept.contains(APP_JSON) { - return Ok(crate::proxy::proxy_backend_query::(req, ctx, proxy_config).await?); - } else if accept.contains(ACCEPT_ALL) { - todo!() + Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(body_empty())?) } else { - return Err(Error::with_msg_no_trace(format!("bad accept {:?}", req.headers()))); + if accepts_cbor_frames(req.headers()) { + // self.handle_cbor(req, ctx, proxy_config).await + Ok(crate::proxy::proxy_backend_query::(req, ctx, proxy_config).await?) + } else if accepts_json_or_all(req.headers()) { + Ok(crate::proxy::proxy_backend_query::(req, ctx, proxy_config).await?) + } else { + Err(Error::with_msg_no_trace(format!("bad accept {:?}", req.headers()))) + } } } diff --git a/crates/query/src/api4/binned.rs b/crates/query/src/api4/binned.rs index 9224e9a..a8f1f05 100644 --- a/crates/query/src/api4/binned.rs +++ b/crates/query/src/api4/binned.rs @@ -3,8 +3,6 @@ use err::Error; use netpod::get_url_query_pairs; use netpod::log::*; use netpod::query::CacheUsage; -use netpod::query::PulseRangeQuery; -use netpod::query::TimeRangeQuery; use netpod::range::evrange::SeriesRange; use netpod::AppendToUrl; use netpod::ByteSize;