feat(connection): show server versions for more datasources
This commit is contained in:
20 files changed
+408
-38
No files matched your search
@@ -173,9 +173,21 @@ impl PoolKind {
|
||||
|
||||
enum ConnectionDatabaseInfoSource {
|
||||
Agent(Arc<db::agent_driver::PooledAgentClient>),
|
||||
ExternalDriver { config: Arc<ConnectionConfig>, session: Arc<PluginDriverSession> },
|
||||
MongoAgent(Arc<db::agent_driver::PooledAgentClient>, Option<String>),
|
||||
ExternalDriver {
|
||||
config: Arc<ConnectionConfig>,
|
||||
session: Arc<PluginDriverSession>,
|
||||
},
|
||||
NativeMysql(db::mysql::MySqlPool),
|
||||
NativeHBase(db::hbase_driver::HBaseClient),
|
||||
NativeMongo(mongodb::Client, Option<String>),
|
||||
Meilisearch(db::meilisearch_driver::MeilisearchClient),
|
||||
VictoriaMetrics(db::victoriametrics_driver::VictoriaMetricsClient),
|
||||
Redis(String),
|
||||
Nacos,
|
||||
Consul(Box<crate::consul::ConsulClient>),
|
||||
#[cfg(feature = "mq-admin")]
|
||||
MessageQueue,
|
||||
}
|
||||
|
||||
/// Held connection for a manual transaction session
|
||||
@@ -4275,6 +4287,9 @@ impl AppState {
|
||||
let source = {
|
||||
let connections = self.connections.read().await;
|
||||
match connections.get(&pool_key) {
|
||||
Some(PoolKind::Agent(client)) if config.db_type == DatabaseType::MongoDb => {
|
||||
Some(ConnectionDatabaseInfoSource::MongoAgent(client.clone(), database.map(str::to_string)))
|
||||
}
|
||||
Some(PoolKind::Agent(client)) => Some(ConnectionDatabaseInfoSource::Agent(client.clone())),
|
||||
Some(PoolKind::ExternalDriver { config, session, .. }) => {
|
||||
Some(ConnectionDatabaseInfoSource::ExternalDriver {
|
||||
@@ -4284,6 +4299,18 @@ impl AppState {
|
||||
}
|
||||
Some(PoolKind::Mysql(pool, _)) => Some(ConnectionDatabaseInfoSource::NativeMysql(pool.clone())),
|
||||
Some(PoolKind::HBase(client)) => Some(ConnectionDatabaseInfoSource::NativeHBase(client.clone())),
|
||||
Some(PoolKind::MongoDb(client)) => {
|
||||
Some(ConnectionDatabaseInfoSource::NativeMongo(client.clone(), database.map(str::to_string)))
|
||||
}
|
||||
Some(PoolKind::Meilisearch(client)) => Some(ConnectionDatabaseInfoSource::Meilisearch(client.clone())),
|
||||
Some(PoolKind::VictoriaMetrics(client)) => {
|
||||
Some(ConnectionDatabaseInfoSource::VictoriaMetrics(client.clone()))
|
||||
}
|
||||
Some(PoolKind::Redis(_)) => Some(ConnectionDatabaseInfoSource::Redis(pool_key.clone())),
|
||||
Some(PoolKind::Nacos) => Some(ConnectionDatabaseInfoSource::Nacos),
|
||||
Some(PoolKind::Consul(client)) => Some(ConnectionDatabaseInfoSource::Consul(Box::new(client.clone()))),
|
||||
#[cfg(feature = "mq-admin")]
|
||||
Some(PoolKind::MessageQueue) => Some(ConnectionDatabaseInfoSource::MessageQueue),
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
@@ -4293,6 +4320,17 @@ impl AppState {
|
||||
let mut agent = client.lock().await;
|
||||
Ok(agent.connection_info(Some(db::connection_timeout())).await?.database_info)
|
||||
}
|
||||
Some(ConnectionDatabaseInfoSource::MongoAgent(client, database)) => {
|
||||
let mut agent = client.lock().await;
|
||||
let version = agent.mongo_server_version::<String>(database.as_deref().unwrap_or("admin")).await?;
|
||||
Ok(Some(DatabaseConnectionInfo {
|
||||
product_name: Some("MongoDB".to_string()),
|
||||
product_version: Some(version),
|
||||
current_database: database,
|
||||
driver_name: Some("MongoDB legacy Agent".to_string()),
|
||||
..Default::default()
|
||||
}))
|
||||
}
|
||||
Some(ConnectionDatabaseInfoSource::ExternalDriver { config, session }) => {
|
||||
let response = session
|
||||
.invoke_with_timeout::<serde_json::Value>(
|
||||
@@ -4309,6 +4347,41 @@ impl AppState {
|
||||
Some(ConnectionDatabaseInfoSource::NativeHBase(client)) => {
|
||||
db::hbase_driver::database_connection_info(&client).await
|
||||
}
|
||||
Some(ConnectionDatabaseInfoSource::NativeMongo(client, database)) => {
|
||||
db::mongo_driver::database_connection_info(&client, database.as_deref()).await.map(Some)
|
||||
}
|
||||
Some(ConnectionDatabaseInfoSource::Meilisearch(client)) => {
|
||||
db::meilisearch_driver::database_connection_info(&client).await.map(Some)
|
||||
}
|
||||
Some(ConnectionDatabaseInfoSource::VictoriaMetrics(client)) => {
|
||||
db::victoriametrics_driver::database_connection_info(&client, db::connection_timeout()).await.map(Some)
|
||||
}
|
||||
Some(ConnectionDatabaseInfoSource::Redis(pool_key)) => {
|
||||
let connections = self.connections.read().await;
|
||||
match connections.get(&pool_key) {
|
||||
Some(PoolKind::Redis(redis)) => db::redis_driver::database_connection_info(redis).await.map(Some),
|
||||
_ => Ok(None),
|
||||
}
|
||||
}
|
||||
Some(ConnectionDatabaseInfoSource::Nacos) => {
|
||||
let admin_config = self.nacos_admin_config_for_connection(connection_id, &config).await?;
|
||||
let admin = self.nacos_registry.get_or_build_config(connection_id, admin_config).await?;
|
||||
Ok(crate::nacos::service::database_info_from_connection(&admin.test_connection().await?))
|
||||
}
|
||||
Some(ConnectionDatabaseInfoSource::Consul(client)) => {
|
||||
let identity = client.agent_self().await?;
|
||||
Ok(Some(DatabaseConnectionInfo {
|
||||
product_name: Some("Consul".to_string()),
|
||||
product_version: identity.version,
|
||||
server_comment: Some(format!("Agent {}", identity.node)),
|
||||
driver_name: Some("Consul HTTP API".to_string()),
|
||||
..Default::default()
|
||||
}))
|
||||
}
|
||||
#[cfg(feature = "mq-admin")]
|
||||
Some(ConnectionDatabaseInfoSource::MessageQueue) => {
|
||||
Ok(crate::mq::service::mq_database_connection_info(self, connection_id).await?)
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use std::time::{Duration, Instant};
|
||||
|
||||
use super::{http_client_builder, ColumnInfo};
|
||||
use crate::db::document_result::DocumentQueryResult;
|
||||
use crate::models::connection::DatabaseConnectionInfo;
|
||||
use crate::types::QueryResult;
|
||||
|
||||
const PATH_SEGMENT_ENCODE_SET: &AsciiSet = &CONTROLS
|
||||
@@ -178,6 +179,22 @@ pub async fn test_connection(client: &MeilisearchClient, _timeout: Duration) ->
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn database_connection_info(client: &MeilisearchClient) -> Result<DatabaseConnectionInfo, String> {
|
||||
let response =
|
||||
client.get("/version").send().await.map_err(|error| format!("Meilisearch request failed: {error}"))?;
|
||||
let value = response_json(response, "version lookup").await?;
|
||||
Ok(DatabaseConnectionInfo {
|
||||
product_name: Some("Meilisearch".to_string()),
|
||||
product_version: value
|
||||
.get("pkgVersion")
|
||||
.or_else(|| value.get("version"))
|
||||
.and_then(Value::as_str)
|
||||
.map(str::to_string),
|
||||
driver_name: Some("Meilisearch HTTP API".to_string()),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct IndexInfoResponse {
|
||||
|
||||
@@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::with_connection_timeout;
|
||||
use crate::document_ops::{MongoGridFsBucketInfo, MongoGridFsFileInfo};
|
||||
use crate::models::connection::DatabaseConnectionInfo;
|
||||
use crate::types::IndexInfo;
|
||||
use futures::{io::AsyncReadExt, io::AsyncWriteExt, TryStreamExt};
|
||||
use percent_encoding::percent_decode_str;
|
||||
@@ -239,6 +240,20 @@ pub async fn server_version(client: &Client, database: &str) -> Result<String, S
|
||||
server_version_from_build_info(&result)
|
||||
}
|
||||
|
||||
pub async fn database_connection_info(
|
||||
client: &Client,
|
||||
database: Option<&str>,
|
||||
) -> Result<DatabaseConnectionInfo, String> {
|
||||
let version = server_version(client, database.unwrap_or("admin")).await?;
|
||||
Ok(DatabaseConnectionInfo {
|
||||
product_name: Some("MongoDB".to_string()),
|
||||
product_version: Some(version),
|
||||
current_database: database.map(str::to_string),
|
||||
driver_name: Some("MongoDB Rust driver".to_string()),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn run_command(client: &Client, database: &str, command_json: &str) -> Result<MongoDocumentResult, String> {
|
||||
let value: serde_json::Value =
|
||||
serde_json::from_str(command_json).map_err(|error| format!("Invalid MongoDB command JSON: {error}"))?;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::models::connection::ConnectionConfig;
|
||||
use crate::models::connection::{ConnectionConfig, DatabaseConnectionInfo};
|
||||
use base64::Engine;
|
||||
use redis::{
|
||||
aio::ConnectionLike,
|
||||
@@ -749,6 +749,41 @@ pub async fn test_connection(connection: &RedisConnection) -> Result<(), String>
|
||||
}
|
||||
}
|
||||
|
||||
/// Read the Redis server identity without making metadata unavailable when the
|
||||
/// INFO command is disabled by ACL or server policy.
|
||||
pub async fn database_connection_info(connection: &RedisConnection) -> Result<DatabaseConnectionInfo, String> {
|
||||
match connection {
|
||||
RedisConnection::Direct(con) => {
|
||||
let mut con = con.lock().await;
|
||||
redis_database_connection_info(&mut *con).await
|
||||
}
|
||||
RedisConnection::Cluster(pool) => {
|
||||
let mut con = cluster_any_connection(pool).await?;
|
||||
redis_database_connection_info(&mut con).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn redis_database_connection_info<C>(con: &mut C) -> Result<DatabaseConnectionInfo, String>
|
||||
where
|
||||
C: ConnectionLike + Send + Sync + Unpin,
|
||||
{
|
||||
let info =
|
||||
tokio::time::timeout(super::connection_timeout(), redis::cmd("INFO").arg("server").query_async::<String>(con))
|
||||
.await
|
||||
.map_err(|_| format!("Redis INFO command timed out ({}s)", super::CONNECTION_TIMEOUT_SECS))?
|
||||
.map_err(|error| format!("Redis INFO command failed: {error}"))?;
|
||||
let product_version = info.lines().find_map(|line| {
|
||||
let (key, value) = line.trim().split_once(':')?;
|
||||
(key.eq_ignore_ascii_case("redis_version") && !value.trim().is_empty()).then(|| value.trim().to_string())
|
||||
});
|
||||
Ok(DatabaseConnectionInfo {
|
||||
product_name: Some("Redis".to_string()),
|
||||
product_version,
|
||||
..DatabaseConnectionInfo::default()
|
||||
})
|
||||
}
|
||||
|
||||
async fn redis_ping<C>(con: &mut C, label: &str) -> Result<(), String>
|
||||
where
|
||||
C: ConnectionLike + Send + Sync + Unpin,
|
||||
|
||||
@@ -8,6 +8,7 @@ use std::time::{Duration, Instant};
|
||||
|
||||
use super::with_connection_timeout;
|
||||
use crate::models::connection::ConnectionConfig;
|
||||
use crate::models::connection::DatabaseConnectionInfo;
|
||||
use crate::types::{ColumnInfo, DatabaseInfo, ObjectStatistics, QueryResult, TableInfo};
|
||||
|
||||
const DEFAULT_API_PATH: &str = "/prometheus";
|
||||
@@ -182,6 +183,24 @@ pub async fn test_connection(client: &VictoriaMetricsClient, timeout: Duration)
|
||||
parse_api_response::<Value>(response).await.map(|_| ())
|
||||
}
|
||||
|
||||
pub async fn database_connection_info(
|
||||
client: &VictoriaMetricsClient,
|
||||
timeout: Duration,
|
||||
) -> Result<DatabaseConnectionInfo, String> {
|
||||
let request = client.request(client.http.get(client.endpoint("/api/v1/status/buildinfo")));
|
||||
let response = with_connection_timeout("VictoriaMetrics", timeout, async {
|
||||
request.send().await.map_err(|error| format!("VictoriaMetrics connection failed: {error}"))
|
||||
})
|
||||
.await?;
|
||||
let value = parse_api_response::<Value>(response).await?;
|
||||
Ok(DatabaseConnectionInfo {
|
||||
product_name: Some("VictoriaMetrics".to_string()),
|
||||
product_version: value.get("version").and_then(Value::as_str).map(str::to_string),
|
||||
driver_name: Some("VictoriaMetrics HTTP API".to_string()),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn list_databases(client: &VictoriaMetricsClient) -> Result<Vec<DatabaseInfo>, String> {
|
||||
Ok(vec![DatabaseInfo { name: client.database_label.clone(), ..Default::default() }])
|
||||
}
|
||||
|
||||
@@ -38,6 +38,27 @@ pub async fn mq_test_connection_core(state: &AppState, conn_id: &str) -> Result<
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the adapter's cluster probe into the common connection metadata
|
||||
/// shown by the desktop and web connection views.
|
||||
pub async fn mq_database_connection_info(
|
||||
state: &AppState,
|
||||
conn_id: &str,
|
||||
) -> Result<Option<crate::models::connection::DatabaseConnectionInfo>, String> {
|
||||
let info = mq_test_connection_core(state, conn_id).await?;
|
||||
let product_name = match info.system_kind {
|
||||
MqSystemKind::Pulsar => "Pulsar",
|
||||
MqSystemKind::Kafka => "Kafka",
|
||||
MqSystemKind::RocketMq => "RocketMQ",
|
||||
MqSystemKind::RabbitMq => "RabbitMQ",
|
||||
};
|
||||
Ok(Some(crate::models::connection::DatabaseConnectionInfo {
|
||||
product_name: Some(product_name.to_string()),
|
||||
product_version: info.server_version,
|
||||
driver_name: Some("Message Queue Admin API".to_string()),
|
||||
..Default::default()
|
||||
}))
|
||||
}
|
||||
|
||||
// ---- Tenants ----
|
||||
|
||||
pub async fn mq_list_tenants_core(state: &AppState, conn_id: &str) -> Result<Vec<TenantInfo>, String> {
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
use std::future::Future;
|
||||
|
||||
use crate::connection::AppState;
|
||||
use crate::models::connection::DatabaseType;
|
||||
use crate::models::connection::{DatabaseConnectionInfo, DatabaseType};
|
||||
use crate::nacos::types::*;
|
||||
|
||||
pub fn database_info_from_connection(info: &NacosConnectionInfo) -> Option<DatabaseConnectionInfo> {
|
||||
let product_version = info.server_version.clone().filter(|value| !value.trim().is_empty());
|
||||
Some(DatabaseConnectionInfo {
|
||||
product_name: Some("Nacos".to_string()),
|
||||
product_version,
|
||||
..DatabaseConnectionInfo::default()
|
||||
})
|
||||
}
|
||||
|
||||
async fn refresh_access_control_after_mutation(admin: &std::sync::Arc<dyn crate::nacos::port::NacosAdmin>) {
|
||||
admin.invalidate_access_control_capabilities();
|
||||
let _ = admin.refresh_access_control_capabilities().await;
|
||||
|
||||
Reference in new issue
Block a user