feat: add full hostname option to hostname plugin and remove full_hostname plugin

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-26 18:45:14 -03:00
parent c8afbb3984
commit 221d8b3b27
2 changed files with 31 additions and 156 deletions

View File

@@ -121,7 +121,6 @@ pub enum MetaPluginType {
ReadTime,
ReadRate,
Hostname,
FullHostname,
}
/// Central function to handle metadata output with name mapping
@@ -284,6 +283,5 @@ pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin>
MetaPluginType::ReadTime => Box::new(ReadTimeMetaPlugin::new_simple()),
MetaPluginType::ReadRate => Box::new(ReadRateMetaPlugin::new_simple()),
MetaPluginType::Hostname => Box::new(HostnameMetaPlugin::new_simple()),
MetaPluginType::FullHostname => Box::new(FullHostnameMetaPlugin::new_simple()),
}
}

View File

@@ -693,12 +693,14 @@ pub struct HostnameMetaPlugin {
impl HostnameMetaPlugin {
pub fn new(
_options: Option<std::collections::HashMap<String, serde_yaml::Value>>,
options: Option<std::collections::HashMap<String, serde_yaml::Value>>,
outputs: Option<std::collections::HashMap<String, serde_yaml::Value>>,
) -> HostnameMetaPlugin {
// Start with default options
let mut final_options = std::collections::HashMap::new();
if let Some(opts) = _options {
// Add default value for "full" option
final_options.insert("full".to_string(), serde_yaml::Value::Bool(true));
if let Some(opts) = options {
for (key, value) in opts {
final_options.insert(key, value);
}
@@ -727,6 +729,13 @@ impl HostnameMetaPlugin {
pub fn new_simple() -> HostnameMetaPlugin {
Self::new(None, None)
}
fn get_hostname(&self) -> String {
match gethostname().into_string() {
Ok(hostname) => hostname,
Err(_) => "unknown".to_string(),
}
}
}
impl MetaPlugin for HostnameMetaPlugin {
@@ -785,9 +794,18 @@ impl MetaPlugin for HostnameMetaPlugin {
}
let mut metadata = Vec::new();
let hostname = match gethostname().into_string() {
Ok(hostname) => hostname,
Err(_) => "unknown".to_string(),
// Check if we should use full hostname or short hostname
let use_full = self.options.get("full")
.and_then(|v| v.as_bool())
.unwrap_or(true); // Default to true
let hostname = if use_full {
self.get_hostname()
} else {
// Get short hostname (first part before the first dot)
let full_hostname = self.get_hostname();
full_hostname.split('.').next().unwrap_or(&full_hostname).to_string()
};
// Use process_metadata_outputs to handle output mapping
@@ -821,7 +839,9 @@ impl MetaPlugin for HostnameMetaPlugin {
}
fn default_options(&self) -> std::collections::HashMap<String, serde_yaml::Value> {
std::collections::HashMap::new()
let mut options = std::collections::HashMap::new();
options.insert("full".to_string(), serde_yaml::Value::Bool(true));
options
}
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
@@ -831,155 +851,12 @@ impl MetaPlugin for HostnameMetaPlugin {
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.options
}
}
#[derive(Debug, Clone, Default)]
pub struct FullHostnameMetaPlugin {
meta_name: String,
is_finalized: bool,
outputs: std::collections::HashMap<String, serde_yaml::Value>,
options: std::collections::HashMap<String, serde_yaml::Value>,
}
impl FullHostnameMetaPlugin {
pub fn new(
_options: Option<std::collections::HashMap<String, serde_yaml::Value>>,
outputs: Option<std::collections::HashMap<String, serde_yaml::Value>>,
) -> FullHostnameMetaPlugin {
// Start with default options
let mut final_options = std::collections::HashMap::new();
if let Some(opts) = _options {
for (key, value) in opts {
final_options.insert(key, value);
}
fn configure_options(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> anyhow::Result<()> {
for (key, value) in options {
self.options.insert(key.clone(), value.clone());
}
// Start with default outputs
let mut final_outputs = std::collections::HashMap::new();
let default_outputs = Self::default().default_outputs();
for output_name in default_outputs {
final_outputs.insert(output_name.clone(), serde_yaml::Value::String(output_name));
}
if let Some(outs) = outputs {
for (key, value) in outs {
final_outputs.insert(key, value);
}
}
FullHostnameMetaPlugin {
meta_name: "full_hostname".to_string(),
is_finalized: false,
outputs: final_outputs,
options: final_options,
}
}
pub fn new_simple() -> FullHostnameMetaPlugin {
Self::new(None, None)
Ok(())
}
}
impl MetaPlugin for FullHostnameMetaPlugin {
fn is_finalized(&self) -> bool {
self.is_finalized
}
fn set_finalized(&mut self, finalized: bool) {
self.is_finalized = finalized;
}
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
// If already finalized, don't process again
if self.is_finalized {
return crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: true,
};
}
// Mark as finalized
self.is_finalized = true;
crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: true,
}
}
fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
// If already finalized, don't process more data
if self.is_finalized {
return crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: true,
};
}
crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: false,
}
}
fn meta_name(&self) -> String {
self.meta_name.clone()
}
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
// If already finalized, don't process again
if self.is_finalized {
return crate::meta_plugin::MetaPluginResponse {
metadata: Vec::new(),
is_finalized: true,
};
}
let mut metadata = Vec::new();
// For now, use regular hostname since local_ip and lookup_addr aren't available
let hostname = match gethostname().into_string() {
Ok(hostname) => hostname,
Err(_) => "unknown".to_string(),
};
// Use process_metadata_outputs to handle output mapping
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
"full_hostname",
hostname,
&self.outputs
) {
metadata.push(meta_data);
}
// Mark as finalized since this plugin only needs to run once
self.is_finalized = true;
crate::meta_plugin::MetaPluginResponse {
metadata,
is_finalized: true,
}
}
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
fn default_outputs(&self) -> Vec<String> {
vec!["full_hostname".to_string()]
}
fn default_options(&self) -> std::collections::HashMap<String, serde_yaml::Value> {
std::collections::HashMap::new()
}
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.options
}
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.options
}
}