From 6f4f3691a55ac4e7599c8a7e44539a266b339be9 Mon Sep 17 00:00:00 2001 From: Alexander Sarantcev <99037063+ephemeralsad@users.noreply.github.com> Date: Wed, 21 May 2025 13:03:26 +0400 Subject: [PATCH] pageserver: Add tracing endpoint correctness check in config validation (#11970) ## Problem When using an incorrect endpoint string - `"localhost:4317"`, it's a runtime error, but it can be a config error - Closes: https://github.com/neondatabase/neon/issues/11394 ## Summary of changes Add config parse time check via `request::Url::parse` validation. --------- Co-authored-by: Aleksandr Sarantsev --- pageserver/src/config.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pageserver/src/config.rs b/pageserver/src/config.rs index 7e773f56b3..62f5b009f7 100644 --- a/pageserver/src/config.rs +++ b/pageserver/src/config.rs @@ -544,6 +544,23 @@ impl PageServerConf { ratio.numerator, ratio.denominator ) ); + + let url = Url::parse(&tracing_config.export_config.endpoint) + .map_err(anyhow::Error::msg) + .with_context(|| { + format!( + "tracing endpoint URL is invalid : {}", + tracing_config.export_config.endpoint + ) + })?; + + ensure!( + url.scheme() == "http" || url.scheme() == "https", + format!( + "tracing endpoint URL must start with http:// or https://: {}", + tracing_config.export_config.endpoint + ) + ); } IndexEntry::validate_checkpoint_distance(conf.default_tenant_conf.checkpoint_distance) @@ -660,4 +677,25 @@ mod tests { PageServerConf::parse_and_validate(NodeId(0), config_toml, &workdir) .expect("parse_and_validate"); } + + #[test] + fn test_config_tracing_endpoint_is_invalid() { + let input = r#" + control_plane_api = "http://localhost:6666" + + [tracing] + + sampling_ratio = { numerator = 1, denominator = 0 } + + [tracing.export_config] + endpoint = "localhost:4317" + protocol = "http-binary" + timeout = "1ms" + "#; + let config_toml = toml_edit::de::from_str::(input) + .expect("config has valid fields"); + let workdir = Utf8PathBuf::from("/nonexistent"); + PageServerConf::parse_and_validate(NodeId(0), config_toml, &workdir) + .expect_err("parse_and_validate should fail for endpoint without scheme"); + } }