Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/user_guide/phase.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ Every error that reaches `fail_to_proxy()` will be automatically logged in the e

This callback returns a string which allows users to customize what info to dump in the error log to help track and debug the failures.

### `suppress_pre_request_error_log()`
This is also not a phase, but another callback.

This callback is similar to `suppress_error_log()`, but it is invoked for downstream request read and parse failures before the per-request `CTX` is created. Because the request may not have been parsed successfully yet, it receives the downstream HTTP session directly instead of `Session` and `CTX`.

Return `true` to suppress the error log.

### `suppress_error_log()`
This is also not a phase, but another callback.

Expand Down
9 changes: 7 additions & 2 deletions pingora-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ use pingora_core::protocols::http::subrequest::server::SubrequestHandle;
use pingora_core::protocols::http::v1::client::HttpSession as HttpSessionV1;
use pingora_core::protocols::http::v2::server::H2Options;
use pingora_core::protocols::http::HttpTask;
use pingora_core::protocols::http::ServerSession as HttpSession;
use pingora_core::protocols::http::SERVER_NAME;
use pingora_core::protocols::Stream;
use pingora_core::protocols::{Digest, UniqueID};
Expand All @@ -89,6 +88,7 @@ pub mod subrequest;

use subrequest::{BodyMode, Ctx as SubrequestCtx};

pub use pingora_core::protocols::http::ServerSession as HttpSession;
pub use proxy_cache::range_filter::{range_header_filter, MultiRangeInfo, RangeType};
pub use proxy_purge::PurgeStatus;
pub use proxy_trait::{FailToProxy, ProxyHttp};
Expand Down Expand Up @@ -234,7 +234,12 @@ where
}
Err(mut e) => {
e.as_down();
error!("Fail to proxy: {e}");
if !self
.inner
.suppress_pre_request_error_log(&downstream_session, &e)
{
error!("Fail to proxy: {e}");
}
if matches!(e.etype, InvalidHTTPHeader) {
downstream_session
.respond_error(400)
Expand Down
9 changes: 9 additions & 0 deletions pingora-proxy/src/proxy_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,15 @@ pub trait ProxyHttp {
) {
}

/// A value of true means that the log message will be suppressed. The default value is false.
///
/// This callback is invoked for downstream request read or parse failures, before
/// [`Self::early_request_filter`] and before [`Self::CTX`] is created, so
/// implementations should not assume `session.req_header()` is available.
fn suppress_pre_request_error_log(&self, _session: &HttpSession, _error: &Error) -> bool {
false
}

/// A value of true means that the log message will be suppressed. The default value is false.
fn suppress_error_log(&self, _session: &Session, _ctx: &Self::CTX, _error: &Error) -> bool {
false
Expand Down
Loading