feat: add common_version customization (#7869)

* feat: add product name customization

* chore: update tests
This commit is contained in:
Ning Sun
2026-03-26 18:18:06 +08:00
committed by GitHub
parent 1118fe243f
commit 08ded45c7a
15 changed files with 44 additions and 17 deletions

1
Cargo.lock generated
View File

@@ -2055,6 +2055,7 @@ dependencies = [
"common-time",
"common-version",
"common-wal",
"const_format",
"datafusion",
"datafusion-common",
"datafusion-physical-plan",

View File

@@ -54,6 +54,7 @@ common-telemetry = { workspace = true, features = [
common-time.workspace = true
common-version.workspace = true
common-wal.workspace = true
const_format.workspace = true
datafusion.workspace = true
datafusion-common.workspace = true
datafusion-physical-plan.workspace = true

View File

@@ -20,11 +20,11 @@ use cmd::error::{InitTlsProviderSnafu, Result};
use cmd::options::GlobalOptions;
use cmd::{App, cli, datanode, flownode, frontend, metasrv, standalone};
use common_base::Plugins;
use common_version::{verbose_version, version};
use common_version::{product_name, verbose_version, version};
use servers::install_ring_crypto_provider;
#[derive(Parser)]
#[command(name = "greptime", author, version, long_version = verbose_version(), about)]
#[command(name = product_name(), author, version, long_version = verbose_version(), about)]
#[command(propagate_version = true)]
pub(crate) struct Command {
#[clap(subcommand)]
@@ -52,11 +52,11 @@ enum SubCommand {
#[clap(name = "metasrv")]
Metasrv(metasrv::Command),
/// Run greptimedb as a standalone service.
/// Start service in standalone mode.
#[clap(name = "standalone")]
Standalone(standalone::Command),
/// Execute the cli tools for greptimedb.
/// Execute the cli tools.
#[clap(name = "cli")]
Cli(cli::Command),
}
@@ -148,7 +148,7 @@ async fn start(cli: Command) -> Result<()> {
fn setup_human_panic() {
human_panic::setup_panic!(
human_panic::Metadata::new("GreptimeDB", version())
human_panic::Metadata::new(product_name(), version())
.homepage("https://github.com/GreptimeTeam/greptimedb/discussions")
);

View File

@@ -21,7 +21,7 @@ use tracing_appender::non_blocking::WorkerGuard;
use crate::options::GlobalOptions;
use crate::{App, Result, error};
pub const APP_NAME: &str = "greptime-cli";
pub const APP_NAME: &str = const_format::concatcp!(common_version::product_name(), "-cli");
use async_trait::async_trait;
pub struct Instance {

View File

@@ -43,7 +43,7 @@ use crate::error::{
};
use crate::options::{GlobalOptions, GreptimeOptions};
pub const APP_NAME: &str = "greptime-datanode";
pub const APP_NAME: &str = const_format::concatcp!(common_version::product_name(), "-datanode");
type DatanodeOptions = GreptimeOptions<datanode::config::DatanodeOptions>;

View File

@@ -35,6 +35,7 @@ use common_stat::ResourceStatImpl;
use common_telemetry::info;
use common_telemetry::logging::{DEFAULT_LOGGING_DIR, TracingOptions};
use common_version::{short_version, verbose_version};
use const_format::concatcp;
use flow::{
FlownodeBuilder, FlownodeInstance, FlownodeServiceBuilder, FrontendClient, FrontendInvoker,
get_flow_auth_options,
@@ -52,7 +53,7 @@ use crate::error::{
use crate::options::{GlobalOptions, GreptimeOptions};
use crate::{App, create_resource_limit_metrics, log_versions, maybe_activate_heap_profile};
pub const APP_NAME: &str = "greptime-flownode";
pub const APP_NAME: &str = concatcp!(common_version::product_name(), "-flownode");
type FlownodeOptions = GreptimeOptions<flow::FlownodeOptions>;

View File

@@ -72,7 +72,7 @@ pub struct Instance {
_guard: Vec<WorkerGuard>,
}
pub const APP_NAME: &str = "greptime-frontend";
pub const APP_NAME: &str = const_format::concatcp!(common_version::product_name(), "-frontend");
impl Instance {
pub fn new(frontend: Frontend, _guard: Vec<WorkerGuard>) -> Self {

View File

@@ -24,6 +24,7 @@ use common_meta::distributed_time_constants::init_distributed_time_constants;
use common_telemetry::info;
use common_telemetry::logging::{DEFAULT_LOGGING_DIR, TracingOptions};
use common_version::{short_version, verbose_version};
use const_format::concatcp;
use meta_srv::bootstrap::{MetasrvInstance, metasrv_builder};
use meta_srv::metasrv::BackendImpl;
use snafu::ResultExt;
@@ -35,7 +36,7 @@ use crate::{App, create_resource_limit_metrics, log_versions, maybe_activate_hea
type MetasrvOptions = GreptimeOptions<meta_srv::metasrv::MetasrvOptions>;
pub const APP_NAME: &str = "greptime-metasrv";
pub const APP_NAME: &str = concatcp!(common_version::product_name(), "-metasrv");
pub struct Instance {
instance: MetasrvInstance,

View File

@@ -48,6 +48,7 @@ use common_telemetry::info;
use common_telemetry::logging::{DEFAULT_LOGGING_DIR, TracingOptions};
use common_time::timezone::set_default_timezone;
use common_version::{short_version, verbose_version};
use const_format::concatcp;
use datanode::config::DatanodeOptions;
use datanode::datanode::{Datanode, DatanodeBuilder};
use datanode::region_server::RegionServer;
@@ -75,7 +76,7 @@ use crate::error::{OtherSnafu, Result, StartFlownodeSnafu};
use crate::options::{GlobalOptions, GreptimeOptions};
use crate::{App, create_resource_limit_metrics, error, log_versions, maybe_activate_heap_profile};
pub const APP_NAME: &str = "greptime-standalone";
pub const APP_NAME: &str = concatcp!(common_version::product_name(), "-standalone");
#[derive(Parser)]
pub struct Command {

View File

@@ -43,14 +43,19 @@ impl Function for VersionFunction {
let version = match func_ctx.query_ctx.channel() {
Channel::Mysql => {
format!(
"{}-greptimedb-{}",
"{}-{}-{}",
std::env::var("GREPTIMEDB_MYSQL_SERVER_VERSION")
.unwrap_or_else(|_| "8.4.2".to_string()),
common_version::product_name(),
common_version::version()
)
}
Channel::Postgres => {
format!("PostgreSQL 16.3 GreptimeDB {}", common_version::version())
format!(
"PostgreSQL 16.3 {} {}",
common_version::product_name(),
common_version::version()
)
}
_ => common_version::version().to_string(),
};

View File

@@ -29,6 +29,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let refresh = profile == "release";
println!("cargo:rerun-if-env-changed=RUSTC");
println!("cargo:rerun-if-env-changed=GREPTIME_PRODUCT_NAME");
// The "CARGO_WORKSPACE_DIR" is set manually (not by Rust itself) in Cargo config file, to
// solve the problem where the "CARGO_MANIFEST_DIR" is not what we want when this repo is
@@ -44,6 +45,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let product_version = load_product_version(&workspace_root);
println!("cargo:rustc-env=GREPTIME_PRODUCT_VERSION={product_version}");
let product_name = load_product_name();
println!("cargo:rustc-env=GREPTIME_PRODUCT_NAME={product_name}");
let repository = open_repository(&workspace_root);
if refresh {
@@ -100,6 +104,10 @@ fn load_product_version(workspace_root: &Path) -> String {
.unwrap_or_else(|| env::var("CARGO_PKG_VERSION").unwrap())
}
fn load_product_name() -> String {
env::var("GREPTIME_PRODUCT_NAME").unwrap_or_else(|_| "GreptimeDB".to_string())
}
fn emit_workspace_watch_list(
workspace_root: &Path,
repository: Option<&Repository>,

View File

@@ -109,6 +109,10 @@ pub const fn version() -> &'static str {
BUILD_INFO.version
}
pub const fn product_name() -> &'static str {
env!("GREPTIME_PRODUCT_NAME")
}
pub const fn verbose_version() -> &'static str {
const_format::formatcp!(
"\nbranch: {}\ncommit: {}\nclean: {}\nversion: {}",

View File

@@ -21,6 +21,7 @@ use std::sync::Arc;
use common_query::Output;
use common_recordbatch::RecordBatches;
use common_time::timezone::system_timezone_name;
use common_version;
use datatypes::prelude::ConcreteDataType;
use datatypes::schema::{ColumnSchema, Schema};
use datatypes::vectors::StringVector;
@@ -119,7 +120,7 @@ static VAR_VALUES: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
("interactive_timeout", "31536000"),
("wait_timeout", "31536000"),
("net_write_timeout", "31536000"),
("version_comment", "Greptime"),
("version_comment", common_version::product_name()),
])
});
@@ -380,7 +381,7 @@ mod test {
+-------------------+
| @@version_comment |
+-------------------+
| Greptime |
| GreptimeDB |
+-------------------+";
test(query, expected);

View File

@@ -50,7 +50,11 @@ pub(crate) struct GreptimeDBStartupParameters {
impl GreptimeDBStartupParameters {
fn new() -> GreptimeDBStartupParameters {
GreptimeDBStartupParameters {
version: format!("16.3-greptimedb-{}", common_version::version()),
version: format!(
"16.3-{}-{}",
common_version::product_name(),
common_version::version()
),
}
}
}

View File

@@ -13,7 +13,7 @@ SELECT @@version_comment;
+-------------------+
| @@version_comment |
+-------------------+
| Greptime |
| GreptimeDB |
+-------------------+
-- SQLNESS PROTOCOL MYSQL