pub struct Cluster {
pub name: Arc<str>,
pub connection_timeout_ms: Option<u64>,
pub endpoints: Vec<Endpoint>,
pub health_check: Option<HealthCheckConfig>,
pub idle_timeout_ms: Option<u64>,
pub load_balancer_strategy: LoadBalancerStrategy,
pub read_timeout_ms: Option<u64>,
pub tls: Option<ClusterTls>,
pub total_connection_timeout_ms: Option<u64>,
pub write_timeout_ms: Option<u64>,
}Expand description
A named group of upstream endpoints.
let yaml = r#"
name: "backend"
endpoints: ["10.0.0.1:8080"]
connection_timeout_ms: 5000
idle_timeout_ms: 30000
"#;
let cluster: Cluster = serde_yaml::from_str(yaml).unwrap();
assert_eq!(cluster.connection_timeout_ms, Some(5000));
assert_eq!(cluster.idle_timeout_ms, Some(30000));
assert!(cluster.read_timeout_ms.is_none());
assert!(cluster.tls.is_none());Fields§
§name: Arc<str>Unique name for the cluster.
connection_timeout_ms: Option<u64>TCP connection timeout in milliseconds.
endpoints: Vec<Endpoint>List of endpoints for the cluster. Each entry is either a plain
"host:port" string or a { address, weight } object.
health_check: Option<HealthCheckConfig>Active health check configuration for this cluster.
idle_timeout_ms: Option<u64>Idle connection timeout in milliseconds.
load_balancer_strategy: LoadBalancerStrategyLoad-balancing algorithm for this cluster. Defaults to round_robin.
read_timeout_ms: Option<u64>Read timeout in milliseconds.
tls: Option<ClusterTls>TLS settings for upstream connections.
Presence implies TLS is enabled. Omit for plaintext HTTP.
total_connection_timeout_ms: Option<u64>Total connection timeout in milliseconds (TCP + TLS).
write_timeout_ms: Option<u64>Write timeout in milliseconds.
Implementations§
Source§impl Cluster
impl Cluster
Sourcepub fn with_defaults(name: &str, endpoints: Vec<Endpoint>) -> Self
pub fn with_defaults(name: &str, endpoints: Vec<Endpoint>) -> Self
Build a cluster with only a name and endpoints; all other
fields use their defaults (no timeouts, no TLS, no health
check, round_robin strategy).
use praxis_core::config::Cluster;
use praxis_tls::ClusterTls;
let c = Cluster {
tls: Some(ClusterTls::default()),
..Cluster::with_defaults("backend", vec!["10.0.0.1:443".into()])
};
assert_eq!(&*c.name, "backend");
assert!(c.tls.is_some());
assert!(c.tls.as_ref().unwrap().verify);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Cluster
impl<'de> Deserialize<'de> for Cluster
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&Cluster> for ConnectionOptions
Converts cluster timeout fields (milliseconds) to Duration values.
impl From<&Cluster> for ConnectionOptions
Converts cluster timeout fields (milliseconds) to Duration values.
use std::time::Duration;
use praxis_core::{config::Cluster, connectivity::ConnectionOptions};
let cluster: Cluster = serde_yaml::from_str(
r#"
name: backend
endpoints: ["10.0.0.1:80"]
connection_timeout_ms: 5000
"#,
)
.unwrap();
let opts = ConnectionOptions::from(&cluster);
assert_eq!(opts.connection_timeout, Some(Duration::from_secs(5)));