feat: add node version (#6224)

Add node version to node list via heartbeat.
This commit is contained in:
Hengfei Yang
2025-03-10 16:46:38 +08:00
committed by GitHub
parent 72aaa8d67a
commit 19d654eb7d
17 changed files with 36 additions and 26 deletions
-3
View File
@@ -180,9 +180,6 @@ pprof = { version = "0.14", features = [
"prost-codec",
], optional = true }
[build-dependencies]
chrono = { version = "0.4", default-features = false, features = ["clock"] }
[dev-dependencies]
async-walkdir.workspace = true
expect-test.workspace = true
+1 -1
View File
@@ -28,7 +28,7 @@ use crate::{
pub async fn cli() -> Result<bool, anyhow::Error> {
let app = clap::Command::new("openobserve")
.version(env!("GIT_VERSION"))
.version(config::VERSION)
.about(clap::crate_description!())
.subcommands(&[
clap::Command::new("reset")
+6 -2
View File
@@ -126,7 +126,8 @@ pub async fn node_list() -> Result<(), anyhow::Error> {
Cell::new("ID"),
Cell::new("UUID"),
Cell::new("Name"),
Cell::new("HTTP Address"),
Cell::new("Endpoint"),
Cell::new("Version"),
Cell::new("Status"),
Cell::new("Scheduled"),
Cell::new("CPU"),
@@ -139,6 +140,7 @@ pub async fn node_list() -> Result<(), anyhow::Error> {
Cell::new(&node.uuid),
Cell::new(&node.name),
Cell::new(&node.http_addr),
Cell::new(&node.version),
Cell::new(&format!("{:?}", node.status)),
Cell::new(&node.scheduled.to_string()),
Cell::new(&node.metrics.cpu_total.to_string()),
@@ -167,7 +169,8 @@ pub async fn node_list_with_metrics() -> Result<(), anyhow::Error> {
Cell::new("ID"),
Cell::new("UUID"),
Cell::new("Name"),
Cell::new("HTTP Address"),
Cell::new("Endpoint"),
Cell::new("Version"),
Cell::new("Status"),
Cell::new("Scheduled"),
Cell::new("CPU"),
@@ -186,6 +189,7 @@ pub async fn node_list_with_metrics() -> Result<(), anyhow::Error> {
Cell::new(&node.uuid),
Cell::new(&node.name),
Cell::new(&node.http_addr),
Cell::new(&node.version),
Cell::new(&format!("{:?}", node.status)),
Cell::new(&node.scheduled.to_string()),
Cell::new(&node.metrics.cpu_total.to_string()),
+2
View File
@@ -153,6 +153,7 @@ async fn register() -> Result<()> {
scheduled: true,
broadcasted: false,
metrics: Default::default(),
version: config::VERSION.to_string(),
};
let val = json::to_string(&node).unwrap();
@@ -244,6 +245,7 @@ pub(crate) async fn set_status(status: NodeStatus, new_lease_id: bool) -> Result
scheduled: true,
broadcasted: false,
metrics: Default::default(),
version: config::VERSION.to_string(),
},
};
+2
View File
@@ -154,6 +154,7 @@ async fn register() -> Result<()> {
scheduled: true,
broadcasted: false,
metrics: Default::default(),
version: config::VERSION.to_string(),
};
let val = json::to_vec(&node).unwrap();
@@ -232,6 +233,7 @@ pub(crate) async fn set_status(status: NodeStatus) -> Result<()> {
scheduled: true,
broadcasted: false,
metrics: Default::default(),
version: config::VERSION.to_string(),
},
};
+1
View File
@@ -107,6 +107,7 @@ mod tests {
tcp_conns_close_wait: 3,
tcp_conns_time_wait: 5,
},
version: config::VERSION.to_string(),
}
}
-5
View File
@@ -44,11 +44,6 @@ use crate::{
},
};
// global version variables
pub static VERSION: &str = env!("GIT_VERSION");
pub static COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
pub static BUILD_DATE: &str = env!("GIT_BUILD_DATE");
// global cache variables
pub static KVS: Lazy<RwHashMap<String, bytes::Bytes>> = Lazy::new(Default::default);
pub static QUERY_FUNCTIONS: Lazy<RwHashMap<String, Transform>> = Lazy::new(DashMap::default);
+1 -1
View File
@@ -112,7 +112,7 @@ pub fn get_base_info(data: &mut HashMap<String, json::Value>) -> HashMap<String,
get_config().common.instance_name.clone().into(),
);
data.insert("zo_version".to_string(), VERSION.to_owned().into());
data.insert("zo_version".to_string(), config::VERSION.to_owned().into());
data.clone()
}
+2 -5
View File
@@ -41,10 +41,7 @@ use o2_openfga::authorizer::authz::get_ownership_tuple;
use o2_openfga::config::get_config as get_openfga_config;
use crate::{
common::{
infra::config::VERSION,
utils::auth::{into_ofga_supported_format, is_ofga_unsupported},
},
common::utils::auth::{into_ofga_supported_format, is_ofga_unsupported},
service::db,
};
@@ -290,7 +287,7 @@ pub async fn migrate_resource_names() -> Result<(), anyhow::Error> {
if let Err(e) = db
.put(
META_MIGRATION_VERSION_KEY,
VERSION.to_string().into(),
config::VERSION.to_string().into(),
NO_NEED_WATCH,
None,
)
+3
View File
@@ -76,3 +76,6 @@ vrl.workspace = true
[dev-dependencies]
expect-test.workspace = true
[build-dependencies]
chrono.workspace = true
View File
+1
View File
@@ -55,6 +55,7 @@ pub fn load_local_node() -> Node {
broadcasted: false,
status: NodeStatus::Online,
metrics: Default::default(),
version: crate::VERSION.to_string(),
}
}
+5
View File
@@ -45,6 +45,11 @@ pub type RwAHashMap<K, V> = tokio::sync::RwLock<HashMap<K, V>>;
pub type RwAHashSet<K> = tokio::sync::RwLock<HashSet<K>>;
pub type RwBTreeMap<K, V> = tokio::sync::RwLock<BTreeMap<K, V>>;
// global version variables
pub static VERSION: &str = env!("GIT_VERSION");
pub static COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
pub static BUILD_DATE: &str = env!("GIT_BUILD_DATE");
pub const META_ORG_ID: &str = "_meta";
pub const MMDB_CITY_FILE_NAME: &str = "GeoLite2-City.mmdb";
+3
View File
@@ -50,6 +50,8 @@ pub struct Node {
pub status: NodeStatus,
#[serde(default)]
pub metrics: NodeMetrics,
#[serde(default)]
pub version: String,
}
impl Node {
@@ -67,6 +69,7 @@ impl Node {
broadcasted: false,
status: NodeStatus::Prepare,
metrics: Default::default(),
version: crate::VERSION.to_string(),
}
}
+3 -3
View File
@@ -256,10 +256,10 @@ pub async fn zo_config() -> Result<HttpResponse, Error> {
let build_type = "opensource";
let cfg = get_config();
Ok(HttpResponse::Ok().json(ConfigResponse {
version: VERSION.to_string(),
version: config::VERSION.to_string(),
instance: get_instance_id(),
commit_hash: COMMIT_HASH.to_string(),
build_date: BUILD_DATE.to_string(),
commit_hash: config::COMMIT_HASH.to_string(),
build_date: config::BUILD_DATE.to_string(),
build_type: build_type.to_string(),
telemetry_enabled: cfg.common.telemetry_enabled,
default_fts_keys: SQL_FULL_TEXT_SEARCH_FIELDS
+5 -5
View File
@@ -38,7 +38,7 @@ use openobserve::handler::http::{
use openobserve::{
cli::basic::cli,
common::{
infra::{self as common_infra, cluster, config::VERSION},
infra::{self as common_infra, cluster},
meta, migration,
utils::zo_logger,
},
@@ -147,7 +147,7 @@ async fn main() -> Result<(), anyhow::Error> {
[
("role", cfg.common.node_role.as_str()),
("instance", cfg.common.instance_name.as_str()),
("version", VERSION),
("version", config::VERSION),
]
.to_vec(),
)
@@ -187,7 +187,7 @@ async fn main() -> Result<(), anyhow::Error> {
Some(setup_logs())
};
log::info!("Starting OpenObserve {}", VERSION);
log::info!("Starting OpenObserve {}", config::VERSION);
log::info!(
"System info: CPU cores {}, MEM total {}, Disk total {}, free {}",
cfg.limit.real_cpu_num,
@@ -257,7 +257,7 @@ async fn main() -> Result<(), anyhow::Error> {
// check version upgrade
let old_version = db::version::get().await.unwrap_or("v0.0.0".to_string());
if let Err(e) = migration::check_upgrade(&old_version, VERSION).await {
if let Err(e) = migration::check_upgrade(&old_version, config::VERSION).await {
job_init_tx.send(false).ok();
panic!("check upgrade failed: {}", e);
}
@@ -982,7 +982,7 @@ fn enable_tracing() -> Result<(), anyhow::Error> {
Resource::new(vec![
KeyValue::new("service.name", cfg.common.node_role.to_string()),
KeyValue::new("service.instance", cfg.common.instance_name.to_string()),
KeyValue::new("service.version", VERSION),
KeyValue::new("service.version", config::VERSION),
]),
))
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
+1 -1
View File
@@ -13,7 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::{common::infra::config, service::db};
use crate::service::db;
pub async fn get() -> Result<String, anyhow::Error> {
let ret = db::get("/meta/kv/version").await?;