fix: broadcast event use file id (#6891)

- [x] fix: broadcast event use file id
- [x] feat: add metrics for consistent hashing
This commit is contained in:
Hengfei Yang
2025-05-23 16:56:06 +08:00
committed by GitHub
parent 9c585d73a4
commit b058106166
26 changed files with 517 additions and 454 deletions
+16
View File
@@ -231,6 +231,14 @@ pub async fn cli() -> Result<bool, anyhow::Error> {
.required(true)
.help("snowflake id"),
]),
clap::Command::new("consistent-hash").about("consistent hash").args([
clap::Arg::new("file")
.short('f')
.long("file")
.required(true)
.num_args(1..)
.help("file"),
]),
clap::Command::new("upgrade-db")
.about("upgrade db table schemas").args(dataArgs()),
])
@@ -495,6 +503,14 @@ pub async fn cli() -> Result<bool, anyhow::Error> {
let td = t.format("%Y-%m-%dT%H:%M:%SZ").to_string();
println!("datetimes: {}", td);
}
"consistent-hash" => {
let files = command
.get_many::<String>("file")
.unwrap()
.collect::<Vec<_>>();
let files = files.iter().map(|f| f.to_string()).collect::<Vec<_>>();
super::http::consistent_hash(files).await?;
}
"upgrade-db" => {
crate::migration::init_db().await?;
}
+34 -3
View File
@@ -96,6 +96,7 @@ pub async fn node_offline() -> Result<(), anyhow::Error> {
}
Ok(())
}
pub async fn node_online() -> Result<(), anyhow::Error> {
let url = "/node/enable?value=true";
let response = request(url, None, reqwest::Method::PUT).await?;
@@ -262,6 +263,35 @@ pub async fn local_node_metrics() -> Result<(), anyhow::Error> {
Ok(())
}
pub async fn consistent_hash(files: Vec<String>) -> Result<(), anyhow::Error> {
let url = "/node/consistent_hash";
let req = config::meta::search::HashFileRequest { files };
let body = serde_json::to_vec(&req)?;
let response = request(url, Some(body), reqwest::Method::POST).await?;
let Some(body) = response else {
return Err(anyhow::anyhow!("consistent hash failed"));
};
let response: config::meta::search::HashFileResponse = serde_json::from_str(&body)?;
// Create header row with all column names
let mut table = Table::new();
table.add_row(Row::new(vec![
Cell::new("File"),
Cell::new("Querier"),
Cell::new("Alert Querier"),
]));
for (file, nodes) in response.files.iter() {
table.add_row(Row::new(vec![
Cell::new(file),
Cell::new(nodes.get("querier_interactive").unwrap_or(&"".to_string())),
Cell::new(nodes.get("querier_background").unwrap_or(&"".to_string())),
]));
}
table.printstd();
Ok(())
}
async fn request(
url: &str,
body: Option<Vec<u8>>,
@@ -273,11 +303,12 @@ async fn request(
let url = format!("{}{}", local.http_addr, url);
let user = cfg.auth.root_user_email.clone();
let password = cfg.auth.root_user_password.clone();
let mut response = client.request(method, url).basic_auth(user, Some(password));
let mut req = client.request(method, url).basic_auth(user, Some(password));
if let Some(body) = body {
response = response.body(body);
req = req.header("Content-Type", "application/json");
req = req.body(body);
}
let response = response.send().await?;
let response = req.send().await?;
let status = response.status();
let body = response.text().await?;
if status.is_success() {