ClusterNodeBuilder

Struct ClusterNodeBuilder 

Source
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

Source

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 node
  • node_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.

Source

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)
Source

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();
Source

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)
Source

pub fn build(self) -> ClusterNode

Builds the ClusterNode with the configured options.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more