feat(nacos): add Nacos management console (#1456)
This commit is contained in:
62 files changed
+7314
-55
No files matched your search
@@ -80,6 +80,8 @@ pub enum PoolKind {
|
||||
/// Message queue admin connection (not a data query pool; serves as a
|
||||
/// marker that this connection_id is a valid MQ admin connection).
|
||||
MessageQueue,
|
||||
/// Nacos admin connection marker.
|
||||
Nacos,
|
||||
}
|
||||
|
||||
macro_rules! agent_connection_pool_database_type {
|
||||
@@ -131,6 +133,7 @@ pub struct AppState {
|
||||
pub storage: Storage,
|
||||
pub plugins: PluginRegistry,
|
||||
pub agent_manager: crate::agent_manager::AgentManager,
|
||||
pub nacos_registry: crate::nacos::NacosAdminRegistry,
|
||||
#[cfg(feature = "mq-admin")]
|
||||
pub mq_registry: crate::mq::MqAdminRegistry,
|
||||
}
|
||||
@@ -358,6 +361,7 @@ impl AppState {
|
||||
agent_dir,
|
||||
app_version,
|
||||
),
|
||||
nacos_registry: crate::nacos::NacosAdminRegistry::new(),
|
||||
#[cfg(feature = "mq-admin")]
|
||||
mq_registry: crate::mq::MqAdminRegistry::new(),
|
||||
}
|
||||
@@ -781,6 +785,12 @@ impl AppState {
|
||||
db::influxdb_driver::test_connection(&client, connect_timeout).await?;
|
||||
PoolKind::InfluxDb(client)
|
||||
}
|
||||
DatabaseType::Nacos => {
|
||||
let admin_config = self.nacos_admin_config_for_connection(connection_id, &config).await?;
|
||||
let adapter = self.nacos_registry.build_transient_config(admin_config).await?;
|
||||
adapter.test_connection().await?;
|
||||
PoolKind::Nacos
|
||||
}
|
||||
agent_connection_pool_database_type!() => {
|
||||
let connect_params =
|
||||
agent_connect_params(&db_config, &host, port, db_config.effective_database().unwrap_or(""));
|
||||
@@ -1014,6 +1024,20 @@ impl AppState {
|
||||
Ok(mqc.with_connect_override(&host, port))
|
||||
}
|
||||
|
||||
pub async fn nacos_admin_config_for_connection(
|
||||
&self,
|
||||
connection_id: &str,
|
||||
config: &ConnectionConfig,
|
||||
) -> Result<crate::nacos::config::NacosAdminConfig, String> {
|
||||
let nacos_config = crate::nacos::config::NacosAdminConfig::from_connection(config)?;
|
||||
if !config.has_effective_transport_layers() {
|
||||
return Ok(nacos_config);
|
||||
}
|
||||
|
||||
let (host, port) = self.connection_host_port(connection_id, config).await?;
|
||||
Ok(nacos_config.with_connect_override(&host, port))
|
||||
}
|
||||
|
||||
async fn remove_stale_connection_pool(&self, pool_key: &str) -> bool {
|
||||
if self.running_queries.is_pool_active(pool_key) {
|
||||
return false;
|
||||
@@ -1191,7 +1215,8 @@ impl AppState {
|
||||
| PoolKind::DuckDb(_)
|
||||
| PoolKind::ExternalTabular(_)
|
||||
| PoolKind::ExternalDriver { .. }
|
||||
| PoolKind::MessageQueue => false,
|
||||
| PoolKind::MessageQueue
|
||||
| PoolKind::Nacos => false,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1570,7 +1595,8 @@ impl AppState {
|
||||
| PoolKind::DuckDb(_)
|
||||
| PoolKind::ExternalTabular(_)
|
||||
| PoolKind::ExternalDriver { .. }
|
||||
| PoolKind::MessageQueue => true,
|
||||
| PoolKind::MessageQueue
|
||||
| PoolKind::Nacos => true,
|
||||
PoolKind::Redis(_) => unreachable!("Redis handled separately"),
|
||||
};
|
||||
if !healthy {
|
||||
@@ -1795,6 +1821,8 @@ fn connection_remote_endpoint(config: &ConnectionConfig) -> (String, u16) {
|
||||
.unwrap_or_else(|| (config.host.clone(), config.port))
|
||||
} else if config.db_type == DatabaseType::MessageQueue {
|
||||
parse_mq_admin_host_port(config).unwrap_or_else(|| (config.host.clone(), config.port))
|
||||
} else if config.db_type == DatabaseType::Nacos {
|
||||
parse_nacos_server_host_port(config).unwrap_or_else(|| (config.host.clone(), config.port))
|
||||
} else {
|
||||
(config.host.clone(), config.port)
|
||||
}
|
||||
@@ -1817,6 +1845,23 @@ fn parse_mq_admin_host_port(config: &ConnectionConfig) -> Option<(String, u16)>
|
||||
Some((host, port))
|
||||
}
|
||||
|
||||
fn parse_nacos_server_host_port(config: &ConnectionConfig) -> Option<(String, u16)> {
|
||||
let value = config
|
||||
.external_config
|
||||
.as_ref()?
|
||||
.get("serverAddr")
|
||||
.or_else(|| config.external_config.as_ref()?.get("server_addr"))?
|
||||
.as_str()?
|
||||
.trim();
|
||||
if value.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let url = reqwest::Url::parse(value).ok()?;
|
||||
let host = url.host_str()?.to_string();
|
||||
let port = url.port_or_known_default()?;
|
||||
Some((host, port))
|
||||
}
|
||||
|
||||
fn normalize_client_session_id(client_session_id: Option<&str>) -> Option<String> {
|
||||
client_session_id.map(str::trim).filter(|session| !session.is_empty()).map(|session| session.replace(':', "_"))
|
||||
}
|
||||
@@ -1891,6 +1936,7 @@ fn clone_pool_kind(pool: &PoolKind) -> PoolKind {
|
||||
PoolKind::ExternalDriver { driver_id: driver_id.clone(), config: config.clone(), session: session.clone() }
|
||||
}
|
||||
PoolKind::MessageQueue => PoolKind::MessageQueue,
|
||||
PoolKind::Nacos => PoolKind::Nacos,
|
||||
PoolKind::Redis(_) => panic!("clone_pool_kind not supported for Redis — handled separately"),
|
||||
}
|
||||
}
|
||||
@@ -1940,6 +1986,7 @@ pub async fn close_pool_kind(pool: PoolKind) {
|
||||
session.shutdown().await;
|
||||
}
|
||||
PoolKind::MessageQueue => {}
|
||||
PoolKind::Nacos => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3242,6 +3289,28 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn nacos_admin_config_allows_domain_server_addr_without_transport_override() {
|
||||
let (state, dir) = test_app_state().await;
|
||||
let mut config = mysql_config(None);
|
||||
config.id = "aliyun-nacos".to_string();
|
||||
config.db_type = DatabaseType::Nacos;
|
||||
config.host = "example.com".to_string();
|
||||
config.port = 8848;
|
||||
config.external_config = Some(serde_json::json!({
|
||||
"serverAddr": "https://nacos.aliyuncs.com:8848",
|
||||
"namespace": "public",
|
||||
"contextPath": "/nacos",
|
||||
"auth": { "kind": "none" }
|
||||
}));
|
||||
|
||||
let nacos_config = state.nacos_admin_config_for_connection("aliyun-nacos", &config).await.unwrap();
|
||||
|
||||
assert_eq!(nacos_config.server_addr, "https://nacos.aliyuncs.com:8848");
|
||||
assert!(nacos_config.connect_override.is_none());
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore = "requires a reachable GaussDB instance via environment variables"]
|
||||
async fn live_gaussdb_native_connection_succeeds() {
|
||||
|
||||
Reference in new issue
Block a user