From 5e01fc1b0ea1934c831edda501ab24f4cc2a30e7 Mon Sep 17 00:00:00 2001 From: Nipunn Koorapati Date: Mon, 27 Jan 2025 16:47:51 -0800 Subject: [PATCH] Add vergen revision to local_backend (#33677) Add vergen revision to local_backend Add commit timestamp GitOrigin-RevId: b1f80550c790acbd65d89b6b584cfce47876230d --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + crates/local_backend/Cargo.toml | 4 ++++ crates/local_backend/build.rs | 18 ++++++++++++++++++ crates/local_backend/src/beacon.rs | 9 +++++++-- 5 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 crates/local_backend/build.rs diff --git a/Cargo.lock b/Cargo.lock index 67666b71..dfc9cc8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4327,6 +4327,7 @@ dependencies = [ "usage_tracking", "value", "vector", + "vergen", ] [[package]] @@ -9218,6 +9219,17 @@ dependencies = [ "value", ] +[[package]] +name = "vergen" +version = "8.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f9f3c0ac17bba2cce5ba26fc17a26cb93e099626b6c3260882cecb08a1e2b4" +dependencies = [ + "anyhow", + "rustversion", + "time", +] + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 4cbe46a9..6a1e3a07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -162,6 +162,7 @@ tungstenite = { version = "0.21.0", features = [ "url", "native-tls-vendored" ] url = "2.5.4" urlencoding = "2.1.3" uuid = { version = "1.6", features = [ "serde", "v4" ] } +vergen = { version = "8.1.0" } walkdir = "2" xorf = { git = "https://github.com/sujayakar/xorf.git", rev = "62a32de47bb3ad8b34d6d4feac034a24be2c881a" } diff --git a/crates/local_backend/Cargo.toml b/crates/local_backend/Cargo.toml index 91e3663e..dd1c6335 100644 --- a/crates/local_backend/Cargo.toml +++ b/crates/local_backend/Cargo.toml @@ -98,5 +98,9 @@ usage_tracking = { path = "../../crates/usage_tracking", features = [ value = { path = "../../crates/value", features = ["testing"] } vector = { path = "../../crates/vector", features = ["testing"] } +[build-dependencies] +anyhow = { workspace = true } +vergen = { workspace = true, features = ["git", "gitcl"] } + [lints] workspace = true diff --git a/crates/local_backend/build.rs b/crates/local_backend/build.rs new file mode 100644 index 00000000..75691da1 --- /dev/null +++ b/crates/local_backend/build.rs @@ -0,0 +1,18 @@ +use std::env; + +use vergen::EmitBuilder; + +fn main() -> anyhow::Result<()> { + // recompile when there's a new git hash for /rev endpoint. + if cfg!(not(debug_assertions)) || env::var("FORCE_EMIT").is_ok() { + // Emit git sha + EmitBuilder::builder() + .git_sha(false) + .git_commit_timestamp() + .emit()?; + } else { + println!("cargo:rustc-env=VERGEN_GIT_SHA=dev"); + println!("cargo:rustc-env=VERGEN_GIT_COMMIT_TIMESTAMP=0000-00-00T00:00:00.000000000Z"); + } + Ok(()) +} diff --git a/crates/local_backend/src/beacon.rs b/crates/local_backend/src/beacon.rs index bc37570d..28e147ea 100644 --- a/crates/local_backend/src/beacon.rs +++ b/crates/local_backend/src/beacon.rs @@ -21,6 +21,8 @@ use database::Database; use model::database_globals::DatabaseGlobalsModel; use runtime::prod::ProdRuntime; +const COMPILED_REVISION: &str = env!("VERGEN_GIT_SHA"); +const COMMIT_TIMESTAMP: &str = env!("VERGEN_GIT_COMMIT_TIMESTAMP"); const INITIAL_BACKOFF: Duration = Duration::from_secs(1); const MAX_BACKOFF: Duration = Duration::from_secs(900); // 15 minutes @@ -36,9 +38,12 @@ pub async fn start_beacon(runtime: ProdRuntime, database: Database) // For now, just log the beacon info since endpoint is TBD tracing::info!( - "Beacon: document_id={:?}, database_version={}", + "Beacon: document_id={:?}, database_version={}, compiled_revision={}, \ + commit_timestamp={}", globals.id(), - globals.version + globals.version, + COMPILED_REVISION, + COMMIT_TIMESTAMP, ); Ok::<(), anyhow::Error>(()) }