pub struct ClusterNodeBuilder { /* private fields */ }Expand description
Builder for creating ClusterNode instances with custom configuration.
This builder provides a fluent API for configuring cluster nodes with optional features like metrics collection.
§Example
use photon_etcd_cluster::{ClusterNodeBuilder, SystemMetricsCollector};
// Basic usage (no metrics)
let node = ClusterNodeBuilder::new(
vec!["http://localhost:2379".to_string()],
"worker-1".to_string(),
"192.168.1.10".parse()?,
"my-service".to_string(),
)
.ttl(5)
.build();
// With system metrics
let node = ClusterNodeBuilder::new(
vec!["http://localhost:2379".to_string()],
"worker-1".to_string(),
"192.168.1.10".parse()?,
"my-service".to_string(),
)
.ttl(5)
.metrics_collector(SystemMetricsCollector::new())
.metrics_update_interval(5) // Update every 5 seconds
.build();Implementations§
Source§impl ClusterNodeBuilder
impl ClusterNodeBuilder
Sourcepub fn new(
etcd_endpoints: Vec<String>,
node_id: String,
node_ip: IpAddr,
group_name: String,
) -> Self
pub fn new( etcd_endpoints: Vec<String>, node_id: String, node_ip: IpAddr, group_name: String, ) -> Self
Creates a new builder with required parameters.
§Arguments
etcd_endpoints- List of etcd endpoints (e.g.,["http://localhost:2379"])node_id- Unique identifier for this nodenode_ip- IP address of this node (used for service discovery)group_name- Logical group name for cluster membership
§Panics
Panics if etcd_endpoints is empty or contains invalid URLs.
Sourcepub fn ttl(self, ttl: i64) -> Self
pub fn ttl(self, ttl: i64) -> Self
Sets the lease TTL in seconds.
The TTL determines how long etcd will wait before considering the node as failed if heartbeats stop. Default is 5 seconds.
§Arguments
ttl- Lease TTL in seconds (must be > 0)
Sourcepub fn metrics_collector<C: MetricsCollector + 'static>(
self,
collector: C,
) -> Self
pub fn metrics_collector<C: MetricsCollector + 'static>( self, collector: C, ) -> Self
Sets a custom metrics collector.
The collector will be called periodically to gather metrics that are stored in etcd alongside the node registration. These metrics can be used by load balancers for weighted routing decisions.
By default, a NoopMetricsCollector is used which produces no metrics.
§Example
use photon_etcd_cluster::{ClusterNodeBuilder, SystemMetricsCollector};
let node = ClusterNodeBuilder::new(endpoints, id, ip, group)
.metrics_collector(SystemMetricsCollector::new())
.metrics_update_interval(5)
.build();Sourcepub fn metrics_update_interval(self, interval: u64) -> Self
pub fn metrics_update_interval(self, interval: u64) -> Self
Sets the interval in seconds for metrics updates.
When set to a value > 0, a background task will periodically update the node’s metrics in etcd at the specified interval.
Set to 0 (default) to disable periodic metrics updates. In this case, metrics will only be set during initial registration.
Recommended value: Same as or slightly less than the TTL to ensure fresh metrics are available for load balancing decisions.
§Arguments
interval- Update interval in seconds (0 = disabled)
Sourcepub fn build(self) -> ClusterNode
pub fn build(self) -> ClusterNode
Builds the ClusterNode with the configured options.
Auto Trait Implementations§
impl Freeze for ClusterNodeBuilder
impl !RefUnwindSafe for ClusterNodeBuilder
impl Send for ClusterNodeBuilder
impl Sync for ClusterNodeBuilder
impl Unpin for ClusterNodeBuilder
impl !UnwindSafe for ClusterNodeBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request