Skip to content

Commit bf83e7f

Browse files
authored
feat: /ping API contains versioning headers (#26433)
* feat: `/ping` API contains versioning headers Further, the product version can be modified by updating the metadata in the `influxdb3_process` `Cargo.toml`. * chore: PR feedback * chore: placate linter
1 parent b615e5c commit bf83e7f

File tree

8 files changed

+105
-5
lines changed

8 files changed

+105
-5
lines changed

Cargo.lock

Lines changed: 40 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ bimap = "0.6.3"
6868
bitcode = { version = "0.6.3", features = ["serde"] }
6969
byteorder = "1.3.4"
7070
bytes = "1.9"
71+
cargo_metadata = "0.19.2"
7172
chrono = "0.4"
7273
cron = "0.15"
7374
clap = { version = "4", features = ["derive", "env", "string"] }

influxdb3/tests/server/ping.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use hyper::Method;
2+
use influxdb3_process::{INFLUXDB3_BUILD, INFLUXDB3_VERSION};
23
use serde_json::Value;
34

45
use crate::server::TestServer;
@@ -32,6 +33,27 @@ async fn test_ping() {
3233
.send()
3334
.await
3435
.unwrap();
36+
// Verify we have a request id
37+
assert!(resp.headers().contains_key("Request-Id"));
38+
assert!(resp.headers().contains_key("X-Request-Id"));
39+
40+
assert_eq!(
41+
resp.headers()
42+
.get("X-Influxdb-Version")
43+
.unwrap()
44+
.to_str()
45+
.unwrap(),
46+
&INFLUXDB3_VERSION[..]
47+
);
48+
assert_eq!(
49+
resp.headers()
50+
.get("X-Influxdb-Build")
51+
.unwrap()
52+
.to_str()
53+
.unwrap(),
54+
&INFLUXDB3_BUILD[..]
55+
);
56+
3557
let json = resp.json::<Value>().await.unwrap();
3658
println!("Method: {}, URL: {}", t.method, t.url);
3759
println!("{json:#}");

influxdb3_process/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ authors.workspace = true
55
edition.workspace = true
66
license.workspace = true
77

8+
[package.metadata.influxdb3]
9+
build = "Core"
10+
811
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
912

1013
[dependencies]
@@ -17,6 +20,9 @@ tokio_metrics_bridge.workspace = true
1720
tokio.workspace = true
1821
uuid.workspace = true
1922

23+
[build-dependencies]
24+
cargo_metadata.workspace = true
25+
2026
# Optional Dependencies
2127
[target.'cfg(not(target_env = "msvc"))'.dependencies]
2228
tikv-jemalloc-ctl = { version = "0.5.4", optional = true }

influxdb3_process/build.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// time, panic'ing if it can not be found
33
//
44
// https://stackoverflow.com/questions/43753491/include-git-commit-hash-as-string-into-rust-program
5+
use cargo_metadata::MetadataCommand;
56
use std::process::Command;
67

78
fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -11,6 +12,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1112
// Populate env!(GIT_HASH_SHORT) with the current git commit
1213
println!("cargo:rustc-env=GIT_HASH_SHORT={}", get_git_hash_short());
1314

15+
let path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
16+
let meta = MetadataCommand::new()
17+
.manifest_path("./Cargo.toml")
18+
.current_dir(&path)
19+
.exec()
20+
.unwrap();
21+
22+
let root = meta.root_package().unwrap();
23+
let build = root.metadata["influxdb3"]["build"]
24+
.as_str()
25+
.unwrap_or("Core");
26+
println!("cargo:rerun-if-env-changed=INFLUXDB3_BUILD_VERSION");
27+
println!("cargo:rustc-env=INFLUXDB3_BUILD_VERSION={}", build);
28+
1429
Ok(())
1530
}
1631

influxdb3_process/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ pub fn build_malloc_conf() -> String {
3434
pub static INFLUXDB3_VERSION: LazyLock<&'static str> =
3535
LazyLock::new(|| option_env!("CARGO_PKG_VERSION").unwrap_or("UNKNOWN"));
3636

37+
/// Build information.
38+
pub static INFLUXDB3_BUILD: LazyLock<&'static str> =
39+
LazyLock::new(|| env!("INFLUXDB3_BUILD_VERSION"));
40+
3741
/// Build-time GIT revision hash.
3842
pub static INFLUXDB3_GIT_HASH: &str = env!(
3943
"GIT_HASH",

influxdb3_server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ tonic.workspace = true
9393
tower.workspace = true
9494
unicode-segmentation.workspace = true
9595
url.workspace = true
96+
uuid.workspace = true
9697

9798
[dev-dependencies]
9899
# Core Crates

influxdb3_server/src/http.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use influxdb3_cache::last_cache;
2929
use influxdb3_catalog::CatalogError;
3030
use influxdb3_catalog::log::FieldDataType;
3131
use influxdb3_internal_api::query_executor::{QueryExecutor, QueryExecutorError};
32-
use influxdb3_process::{INFLUXDB3_GIT_HASH_SHORT, INFLUXDB3_VERSION, PROCESS_UUID};
32+
use influxdb3_process::{
33+
INFLUXDB3_BUILD, INFLUXDB3_GIT_HASH_SHORT, INFLUXDB3_VERSION, PROCESS_UUID,
34+
};
3335
use influxdb3_processing_engine::ProcessingEngineManagerImpl;
3436
use influxdb3_processing_engine::manager::ProcessingEngineError;
3537
use influxdb3_types::http::*;
@@ -59,6 +61,7 @@ use std::task::Poll;
5961
use thiserror::Error;
6062
use trace::ctx::SpanContext;
6163
use unicode_segmentation::UnicodeSegmentation;
64+
use uuid::Uuid;
6265

6366
mod v1;
6467

@@ -690,7 +693,18 @@ impl HttpApi {
690693
process_id: *PROCESS_UUID,
691694
})?;
692695

693-
Ok(Response::new(Body::from(body)))
696+
// InfluxDB 1.x used time-based UUIDs.
697+
let request_id = Uuid::now_v7().as_hyphenated().to_string();
698+
699+
Response::builder()
700+
.status(StatusCode::OK)
701+
.header(CONTENT_TYPE, "application/json")
702+
.header("Request-Id", request_id.clone())
703+
.header("X-Influxdb-Build", INFLUXDB3_BUILD.to_string())
704+
.header("X-Influxdb-Version", INFLUXDB3_VERSION.to_string())
705+
.header("X-Request-Id", request_id)
706+
.body(Body::from(body))
707+
.map_err(Into::into)
694708
}
695709

696710
fn handle_metrics(&self) -> Result<Response<Body>> {

0 commit comments

Comments
 (0)