-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add BE configuration update tool #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| use super::be_http_client; | ||
| use crate::config::Config; | ||
| use crate::error::{CliError, Result}; | ||
| use crate::tools::ExecutionResult; | ||
| use crate::tools::Tool; | ||
| use crate::ui; | ||
| use dialoguer::{Confirm, Input, theme::ColorfulTheme}; | ||
| use serde::Deserialize; | ||
| use std::path::PathBuf; | ||
|
|
||
| #[derive(Deserialize)] | ||
| struct ConfigUpdateResult { | ||
| config_name: String, | ||
| status: String, | ||
| msg: String, | ||
| } | ||
|
|
||
| pub struct BeUpdateConfigTool; | ||
|
|
||
| impl Tool for BeUpdateConfigTool { | ||
| fn name(&self) -> &str { | ||
| "set-be-config" | ||
| } | ||
|
|
||
| fn description(&self) -> &str { | ||
| "Update BE configuration variables" | ||
| } | ||
|
|
||
| fn execute(&self, _config: &Config, _pid: u32) -> Result<ExecutionResult> { | ||
| let key = prompt_input("Enter BE config key to update")?; | ||
| let value = prompt_input(&format!("Enter value for '{key}'"))?; | ||
| let persist = Confirm::with_theme(&ColorfulTheme::default()) | ||
| .with_prompt("Persist this configuration?") | ||
| .default(false) | ||
| .interact() | ||
| .map_err(|e| CliError::InvalidInput(format!("Input failed: {e}")))?; | ||
|
|
||
| ui::print_info(&format!( | ||
| "Updating BE config: {key}={value} (persist: {persist})" | ||
| )); | ||
|
|
||
| let endpoint = format!("/api/update_config?{key}={value}&persist={persist}"); | ||
| handle_update_result(be_http_client::post_be_endpoint(&endpoint), &key) | ||
| } | ||
|
|
||
| fn requires_pid(&self) -> bool { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| fn prompt_input(prompt: &str) -> Result<String> { | ||
| let input: String = Input::with_theme(&ColorfulTheme::default()) | ||
| .with_prompt(prompt) | ||
| .interact_text() | ||
| .map_err(|e| CliError::InvalidInput(format!("Input failed: {e}")))?; | ||
|
|
||
| let trimmed = input.trim(); | ||
| if trimmed.is_empty() { | ||
| ui::print_warning("Input cannot be empty!"); | ||
| Err(CliError::GracefulExit) | ||
| } else { | ||
| Ok(trimmed.to_string()) | ||
| } | ||
| } | ||
|
|
||
| fn get_current_value(key: &str) -> Option<String> { | ||
| be_http_client::request_be_webserver_port("/varz", Some(key)) | ||
| .ok()? | ||
| .lines() | ||
| .next()? | ||
| .split('=') | ||
| .nth(1) | ||
| .map(|v| v.trim().to_string()) | ||
| } | ||
|
|
||
| fn handle_update_result(result: Result<String>, key: &str) -> Result<ExecutionResult> { | ||
| let json_response = result.map_err(|e| { | ||
| ui::print_error(&format!("Failed to update BE config: {e}.")); | ||
| ui::print_info("Tips: Ensure the BE service is running and accessible."); | ||
| e | ||
| })?; | ||
|
|
||
| let results: Vec<ConfigUpdateResult> = serde_json::from_str(&json_response) | ||
| .map_err(|e| CliError::ToolExecutionFailed(format!("Failed to parse response: {e}")))?; | ||
|
|
||
| println!(); | ||
| ui::print_info("Results:"); | ||
|
|
||
| let all_ok = results.iter().all(|item| { | ||
| if item.status == "OK" { | ||
| match get_current_value(&item.config_name) { | ||
| Some(value) => println!(" ✓ {} = {}", item.config_name, value), | ||
| None => println!(" ✓ {}: OK", item.config_name), | ||
| } | ||
| true | ||
| } else { | ||
| println!(" ✗ {}: FAILED - {}", item.config_name, item.msg); | ||
| false | ||
| } | ||
| }); | ||
|
|
||
| if all_ok { | ||
| Ok(ExecutionResult { | ||
| output_path: PathBuf::from("console_output"), | ||
| message: format!("Config '{key}' updated successfully"), | ||
| }) | ||
| } else { | ||
| Err(CliError::ToolExecutionFailed( | ||
| "Some configurations failed to update".to_string(), | ||
| )) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The request URL is constructed as
/api/update_config?{key}={value}&persist={persist}which uses the BE configuration key as the parameter name. The Doris API expects fixedkeyandvaluequery parameters, so a call likedisable_storage_page_cache=trueomits the requiredkeyargument altogether and the endpoint will reject the request. As implemented, every update attempt will fail even though the user is prompted for valid input. The query string should usekey=<config>&value=<value>(with proper URL encoding) before issuing the POST.Useful? React with 👍 / 👎.