Skip to content

feat: additional logging in the write path to capture db and ip - #26616

Merged
praveen-influx merged 2 commits into
mainfrom
pk/additional-logging-write-path
Jul 18, 2025
Merged

praveen-influx merged 2 commits into
mainfrom
pk/additional-logging-write-path

Conversation

@praveen-influx

@praveen-influx praveen-influx commented Jul 17, 2025 •

Copy link
Copy Markdown
Contributor

closes: https://github.com/influxdata/influxdb_pro/issues/519

After this commit the log message on failed write looks like below,

2025-07-17T17:16:11.089558Z ERROR influxdb3_server::http: Error while handling request error=partial write of line protocol occurred method=POST path="/api/v3/write_lp" content_length=Some("47") database=foo client_ip=127.0.0.1

The IP address is fetched from,

  • x-forwarded-for header if available,
  • x-real-ip if that is available,
  • remote address as reported by TlsStream (when running over TLS) or AddrStream (on non-TLS)

This PR extends TestServer to capture logs conditionally that can be used for assertions in the logs

@praveen-influx
praveen-influx force-pushed the pk/additional-logging-write-path branch 5 times, most recently from f20027c to 83c88d7 Compare July 18, 2025 09:34
@praveen-influx
praveen-influx force-pushed the pk/additional-logging-write-path branch from 83c88d7 to 8c194db Compare July 18, 2025 10:00
@praveen-influx
praveen-influx requested a review from a team July 18, 2025 10:00
@praveen-influx
praveen-influx marked this pull request as ready for review July 18, 2025 10:00
Err(error) => {
error!(%error, %method, path = uri.path(), ?content_length, "Error while handling request");
let ip = client_ip.as_deref().unwrap_or(UNKNOWN_VAL);
match db.as_ref() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did start with a single error log line with database=unknown when db cannot be extracted from the query param, but realized that probably is going to be confusing for other requests that aren't db specific or db is in the body. So, ended up with 2 separate log lines (with / without database)

@hiltontj hiltontj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had one non-blocking comment.

Comment thread influxdb3_server/src/http.rs Outdated
Comment on lines +2443 to +2460
// Extract client IP - should get socket address since no headers
let client_ip = req
.headers()
.get("x-forwarded-for")
.and_then(|h| h.to_str().ok())
.and_then(|s| s.split(',').next())
.map(|s| s.trim().to_string())
.or_else(|| {
req.headers()
.get("x-real-ip")
.and_then(|h| h.to_str().ok())
.map(|s| s.to_string())
})
.or_else(|| {
req.extensions()
.get::<std::net::SocketAddr>()
.map(|addr| addr.ip().to_string())
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use the extract_client_ip function above? The code looks very similar.

Comment thread influxdb3_server/src/http.rs Outdated
Comment on lines +2480 to +2497
// Extract client IP - should prefer header over socket
let client_ip = req
.headers()
.get("x-forwarded-for")
.and_then(|h| h.to_str().ok())
.and_then(|s| s.split(',').next())
.map(|s| s.trim().to_string())
.or_else(|| {
req.headers()
.get("x-real-ip")
.and_then(|h| h.to_str().ok())
.map(|s| s.to_string())
})
.or_else(|| {
req.extensions()
.get::<std::net::SocketAddr>()
.map(|addr| addr.ip().to_string())
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment.

@praveen-influx
praveen-influx merged commit 2392878 into main Jul 18, 2025
mgattozzi pushed a commit that referenced this pull request Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants