feat(config): integrate etcd for service discovery and config management

- Add etcd-client dependency for distributed configuration storage
- Implement EtcdConfig with priority: etcd > environment variables > defaults
- Add ServiceRegistry for service registration with lease keep-alive
- Integrate etcd-based service discovery for appks gRPC connections
- Add service watcher for real-time service instance updates
- Migrate Redis configuration from single URL to cluster node list
- Update Dockerfile with default IMKS_HOST and IMKS_PORT environment variables
- Add etcd bootstrap configuration through environment variables
- Implement Redis cluster URL building with optional authentication
This commit is contained in:
zhenyi
2026-06-11 16:22:23 +08:00
parent 1b300865d9
commit e72866db8d
9 changed files with 316 additions and 62 deletions
+19 -4
View File
@@ -10,8 +10,11 @@ use std::env;
pub struct DeployConfig {
/// "local" | "redis" | "nats"
pub adapter_mode: String,
/// Redis connection URL (used when adapter_mode = "redis").
pub redis_url: String,
/// Redis cluster nodes, comma-separated host:port pairs.
/// Example: "redis1:6379,redis2:6379,redis3:6379"
pub redis_cluster_nodes: String,
/// Redis password (optional).
pub redis_password: String,
/// NATS connection URL (used when adapter_mode = "nats").
pub nats_url: String,
/// Unique server ID for this node.
@@ -32,8 +35,9 @@ impl DeployConfig {
Self {
adapter_mode: env::var("IMKS_ADAPTER").unwrap_or_else(|_| "local".into()),
redis_url: env::var("IMKS_REDIS_URL")
.unwrap_or_else(|_| "redis://localhost:6379".into()),
redis_cluster_nodes: env::var("IMKS_REDIS_CLUSTER_NODES")
.unwrap_or_else(|_| "localhost:6379,localhost:6380,localhost:6381".into()),
redis_password: env::var("IMKS_REDIS_PASSWORD").unwrap_or_default(),
nats_url: env::var("IMKS_NATS_URL").unwrap_or_else(|_| "nats://localhost:4222".into()),
server_id,
webtransport_enabled: env::var("IMKS_WT_ENABLED")
@@ -47,6 +51,17 @@ impl DeployConfig {
key_path: env::var("IMKS_WT_KEY_PATH").unwrap_or_default(),
}
}
/// Build a redis-cluster URL from cluster_nodes and optional password.
/// Format: redis-cluster://[:password@]host1:port1,host2:port2,...
pub fn redis_cluster_url(&self) -> String {
let auth = if self.redis_password.is_empty() {
String::new()
} else {
format!(":{}@", self.redis_password)
};
format!("redis-cluster://{}{}", auth, self.redis_cluster_nodes)
}
}
impl Default for DeployConfig {