diff --git a/libs/metrics/src/lib.rs b/libs/metrics/src/lib.rs index b4026d93e1..0b3b24c18e 100644 --- a/libs/metrics/src/lib.rs +++ b/libs/metrics/src/lib.rs @@ -89,14 +89,14 @@ pub const DISK_WRITE_SECONDS_BUCKETS: &[f64] = &[ 0.000_050, 0.000_100, 0.000_500, 0.001, 0.003, 0.005, 0.01, 0.05, 0.1, 0.3, 0.5, ]; -pub fn set_build_info_metric(revision: &str) { +pub fn set_build_info_metric(revision: &str, build_tag: &str) { let metric = register_int_gauge_vec!( "libmetrics_build_info", "Build/version information", - &["revision"] + &["revision", "build_tag"] ) .expect("Failed to register build info metric"); - metric.with_label_values(&[revision]).set(1); + metric.with_label_values(&[revision, build_tag]).set(1); } // Records I/O stats in a "cross-platform" way. diff --git a/libs/utils/src/lib.rs b/libs/utils/src/lib.rs index b3e38cd9e1..88cefd516d 100644 --- a/libs/utils/src/lib.rs +++ b/libs/utils/src/lib.rs @@ -130,6 +130,21 @@ macro_rules! project_git_version { }; } +/// This is a shortcut to embed build tag into binaries and avoid copying the same build script to all packages +#[macro_export] +macro_rules! project_build_tag { + ($const_identifier:ident) => { + const $const_identifier: &::core::primitive::str = { + const __ARG: &[&::core::primitive::str; 2] = &match ::core::option_env!("BUILD_TAG") { + ::core::option::Option::Some(x) => ["build_tag-env:", x], + ::core::option::Option::None => ["build_tag:", ""], + }; + + $crate::__const_format::concatcp!(__ARG[0], __ARG[1]) + }; + }; +} + /// Re-export for `project_git_version` macro #[doc(hidden)] pub use const_format as __const_format; diff --git a/pageserver/src/bin/pageserver.rs b/pageserver/src/bin/pageserver.rs index 798b9f258b..df2db25ec6 100644 --- a/pageserver/src/bin/pageserver.rs +++ b/pageserver/src/bin/pageserver.rs @@ -34,11 +34,12 @@ use postgres_backend::AuthType; use utils::logging::TracingErrorLayerEnablement; use utils::signals::ShutdownSignals; use utils::{ - auth::JwtAuth, logging, project_git_version, sentry_init::init_sentry, signals::Signal, - tcp_listener, + auth::JwtAuth, logging, project_build_tag, project_git_version, sentry_init::init_sentry, + signals::Signal, tcp_listener, }; project_git_version!(GIT_VERSION); +project_build_tag!(BUILD_TAG); const PID_FILE_NAME: &str = "pageserver.pid"; @@ -258,11 +259,12 @@ fn start_pageserver( // A changed version string indicates changed software. // A changed launch timestamp indicates a pageserver restart. info!( - "version: {} launch_timestamp: {}", + "version: {} launch_timestamp: {} build_tag: {}", version(), - launch_ts.to_string() + launch_ts.to_string(), + BUILD_TAG, ); - set_build_info_metric(GIT_VERSION); + set_build_info_metric(GIT_VERSION, BUILD_TAG); set_launch_timestamp_metric(launch_ts); pageserver::preinitialize_metrics(); diff --git a/proxy/src/bin/proxy.rs b/proxy/src/bin/proxy.rs index a9ca308797..28d0d95c5b 100644 --- a/proxy/src/bin/proxy.rs +++ b/proxy/src/bin/proxy.rs @@ -16,9 +16,10 @@ use tokio::task::JoinSet; use tokio_util::sync::CancellationToken; use tracing::info; use tracing::warn; -use utils::{project_git_version, sentry_init::init_sentry}; +use utils::{project_build_tag, project_git_version, sentry_init::init_sentry}; project_git_version!(GIT_VERSION); +project_build_tag!(BUILD_TAG); use clap::{Parser, ValueEnum}; @@ -100,7 +101,8 @@ async fn main() -> anyhow::Result<()> { let _sentry_guard = init_sentry(Some(GIT_VERSION.into()), &[]); info!("Version: {GIT_VERSION}"); - ::metrics::set_build_info_metric(GIT_VERSION); + info!("Build_tag: {BUILD_TAG}"); + ::metrics::set_build_info_metric(GIT_VERSION, BUILD_TAG); let args = ProxyCliArgs::parse(); let config = build_config(&args)?; diff --git a/safekeeper/src/bin/safekeeper.rs b/safekeeper/src/bin/safekeeper.rs index 202343fca1..d476cf33ae 100644 --- a/safekeeper/src/bin/safekeeper.rs +++ b/safekeeper/src/bin/safekeeper.rs @@ -42,7 +42,7 @@ use utils::auth::{JwtAuth, Scope}; use utils::{ id::NodeId, logging::{self, LogFormat}, - project_git_version, + project_build_tag, project_git_version, sentry_init::init_sentry, tcp_listener, }; @@ -51,6 +51,7 @@ const PID_FILE_NAME: &str = "safekeeper.pid"; const ID_FILE_NAME: &str = "safekeeper.id"; project_git_version!(GIT_VERSION); +project_build_tag!(BUILD_TAG); const ABOUT: &str = r#" A fleet of safekeepers is responsible for reliably storing WAL received from @@ -204,6 +205,7 @@ async fn main() -> anyhow::Result<()> { )?; logging::replace_panic_hook_with_tracing_panic_hook().forget(); info!("version: {GIT_VERSION}"); + info!("buld_tag: {BUILD_TAG}"); let args_workdir = &args.datadir; let workdir = args_workdir.canonicalize_utf8().with_context(|| { @@ -423,7 +425,7 @@ async fn start_safekeeper(conf: SafeKeeperConf) -> Result<()> { .map(|res| ("WAL remover".to_owned(), res)); tasks_handles.push(Box::pin(wal_remover_handle)); - set_build_info_metric(GIT_VERSION); + set_build_info_metric(GIT_VERSION, BUILD_TAG); // TODO: update tokio-stream, convert to real async Stream with // SignalStream, map it to obtain missing signal name, combine streams into diff --git a/storage_broker/src/bin/storage_broker.rs b/storage_broker/src/bin/storage_broker.rs index 23d1bee354..5ce24a6a42 100644 --- a/storage_broker/src/bin/storage_broker.rs +++ b/storage_broker/src/bin/storage_broker.rs @@ -44,10 +44,11 @@ use storage_broker::{ }; use utils::id::TenantTimelineId; use utils::logging::{self, LogFormat}; -use utils::project_git_version; use utils::sentry_init::init_sentry; +use utils::{project_build_tag, project_git_version}; project_git_version!(GIT_VERSION); +project_build_tag!(BUILD_TAG); const DEFAULT_CHAN_SIZE: usize = 32; const DEFAULT_ALL_KEYS_CHAN_SIZE: usize = 16384; @@ -438,7 +439,8 @@ async fn main() -> Result<(), Box> { // initialize sentry if SENTRY_DSN is provided let _sentry_guard = init_sentry(Some(GIT_VERSION.into()), &[]); info!("version: {GIT_VERSION}"); - ::metrics::set_build_info_metric(GIT_VERSION); + info!("build_tag: {BUILD_TAG}"); + metrics::set_build_info_metric(GIT_VERSION, BUILD_TAG); // On any shutdown signal, log receival and exit. std::thread::spawn(move || { diff --git a/test_runner/regress/test_build_info_metric.py b/test_runner/regress/test_build_info_metric.py index 4e53928d14..8f714dae67 100644 --- a/test_runner/regress/test_build_info_metric.py +++ b/test_runner/regress/test_build_info_metric.py @@ -17,3 +17,6 @@ def test_build_info_metric(neon_env_builder: NeonEnvBuilder, link_proxy: NeonPro assert "revision" in sample.labels assert len(sample.labels["revision"]) > 0 + + assert "build_tag" in sample.labels + assert len(sample.labels["build_tag"]) > 0