Documentation
¶
Overview ¶
Package discovery provides peer discovery mechanisms for cluster formation. Discovery happens before NATS initialization and validates network connectivity.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSingleNode ¶
IsSingleNode returns true when no peers are configured. Single-node deployments skip cluster formation and bootstrap ceremony.
func SummarizeResults ¶
func SummarizeResults(result *DiscoveryResult) string
SummarizeResults returns a human-readable summary of discovery results for logging.
Types ¶
type AWSDiscovery ¶
type AWSDiscovery struct {
// contains filtered or unexported fields
}
AWSDiscovery implements Discovery using AWS EC2 metadata and network interface tags. It queries IMDSv2 for region/instance-id and uses DescribeInstances to find tagged peers in the same region and VPC.
func NewAWSDiscovery ¶
func NewAWSDiscovery(tags map[string]string, opts ...AWSOption) *AWSDiscovery
NewAWSDiscovery creates a new AWSDiscovery with the given tag filters. Tags are used to filter network interfaces - all tags must match (AND logic).
func (*AWSDiscovery) DiscoverPeers ¶
func (ad *AWSDiscovery) DiscoverPeers(ctx context.Context) (*DiscoveryResult, error)
DiscoverPeers implements Discovery.DiscoverPeers. It queries AWS metadata service for self-discovery, then uses EC2 API to find tagged network interfaces in the same region.
type AWSOption ¶
type AWSOption func(*AWSDiscovery)
AWSOption is a functional option for configuring AWSDiscovery.
func WithAWSClusterPort ¶
WithAWSClusterPort sets the port to append to discovered private IPs. Default is 3320 (db-bind-port).
func WithAWSReachabilityTimeout ¶
WithAWSReachabilityTimeout sets the timeout for TCP reachability checks.
func WithAWSVpcID ¶
WithAWSVpcID sets the VPC ID filter for peer discovery. When set, only instances in the specified VPC are discovered.
type AzureDiscovery ¶
type AzureDiscovery struct {
// contains filtered or unexported fields
}
AzureDiscovery implements Discovery using Azure Instance Metadata Service (IMDS) and Azure Compute SDK with client-side tag filtering.
func NewAzureDiscovery ¶
func NewAzureDiscovery(subscriptionID string, tags map[string]string, opts ...Option) *AzureDiscovery
NewAzureDiscovery creates a new AzureDiscovery with the given subscription ID and tags. If subscriptionID is empty, it will be fetched from IMDS during discovery. Tags are used for client-side filtering of VMs (AND logic - all tags must match).
func (*AzureDiscovery) DiscoverPeers ¶
func (ad *AzureDiscovery) DiscoverPeers(ctx context.Context) (*DiscoveryResult, error)
DiscoverPeers implements Discovery.DiscoverPeers. It queries Azure IMDS for region and subscription ID, then enumerates VMs with matching tags in the same region.
type CachedDiscovery ¶
type CachedDiscovery struct {
// contains filtered or unexported fields
}
CachedDiscovery wraps a Discovery implementation with caching and fallback. On API failure, returns last successful result if within TTL.
func NewCachedDiscovery ¶
func NewCachedDiscovery(provider Discovery, cacheTTL time.Duration) *CachedDiscovery
NewCachedDiscovery creates a cached discovery wrapper with specified TTL.
func (*CachedDiscovery) DiscoverPeers ¶
func (cd *CachedDiscovery) DiscoverPeers(ctx context.Context) (*DiscoveryResult, error)
DiscoverPeers implements Discovery.DiscoverPeers with caching. Attempts fresh discovery; falls back to cache on failure if cache is fresh.
func (*CachedDiscovery) GetLastResult ¶
func (cd *CachedDiscovery) GetLastResult() (*DiscoveryResult, time.Time)
GetLastResult returns the cached result for inspection (thread-safe).
type CloudDiscovery ¶
type CloudDiscovery struct {
// contains filtered or unexported fields
}
CloudDiscovery combines cloud provider discovery with static peer list. Provides union of cloud-discovered peers and manually configured peers.
func NewCloudDiscovery ¶
func NewCloudDiscovery(cloudProvider Discovery, staticPeers []string, opts ...Option) *CloudDiscovery
NewCloudDiscovery creates a cloud discovery that combines provider discovery with static peers.
func (*CloudDiscovery) DiscoverPeers ¶
func (cd *CloudDiscovery) DiscoverPeers(ctx context.Context) (*DiscoveryResult, error)
DiscoverPeers implements Discovery.DiscoverPeers. Returns union of cloud-discovered peers and static peers.
type Discovery ¶
type Discovery interface {
// DiscoverPeers returns list of discovered peers with reachability status.
// For static discovery: validates configured peer list
// For cloud discovery (future): queries metadata service
DiscoverPeers(ctx context.Context) (*DiscoveryResult, error)
}
Discovery defines the interface for discovering cluster peers. Implementations validate reachability before cluster formation begins.
type DiscoveryResult ¶
type DiscoveryResult struct {
// Peers is the list of discovered peers with reachability status
Peers []PeerInfo
// SingleNode is true when no peers are configured (single-node deployment)
SingleNode bool
// ReachableCount is the number of reachable peers
ReachableCount int
// TotalCount is the total number of peers discovered
TotalCount int
}
DiscoveryResult contains the results of peer discovery.
type GCPDiscovery ¶
type GCPDiscovery struct {
// contains filtered or unexported fields
}
GCPDiscovery implements Discovery using GCP Compute Engine metadata and instance listing. It discovers instances in the same region with matching labels.
func NewGCPDiscovery ¶
func NewGCPDiscovery(projectID string, labels map[string]string, opts ...Option) *GCPDiscovery
NewGCPDiscovery creates a new GCPDiscovery with the given project ID and label filters. If projectID is empty, it will be fetched from GCP metadata. Labels are used to filter instances (all labels must match - AND logic).
func (*GCPDiscovery) DiscoverPeers ¶
func (gd *GCPDiscovery) DiscoverPeers(ctx context.Context) (*DiscoveryResult, error)
DiscoverPeers implements Discovery.DiscoverPeers. It queries GCP metadata for self-discovery, then lists instances in the same region with matching labels, validates reachability, and returns the results.
type Option ¶
type Option func(*StaticDiscovery)
Option is a functional option for configuring StaticDiscovery.
func WithReachabilityTimeout ¶
WithReachabilityTimeout sets the timeout for TCP reachability checks.
type PeerInfo ¶
type PeerInfo struct {
// Address is the peer address in "host:port" format
Address string
// Reachable indicates if TCP dial succeeded
Reachable bool
// Latency is the RTT for successful dial
Latency time.Duration
// Error contains the error if unreachable
Error error
}
PeerInfo contains information about a discovered peer and its reachability.
func ValidateReachability ¶
ValidateReachability performs parallel TCP dial checks to validate peer reachability. Returns a PeerInfo slice with results for each peer. Checks run in parallel to minimize total validation time.
type StaticDiscovery ¶
type StaticDiscovery struct {
// contains filtered or unexported fields
}
StaticDiscovery implements Discovery using a static list of peer addresses. It validates TCP reachability to each configured peer.
func NewStaticDiscovery ¶
func NewStaticDiscovery(peers []string, opts ...Option) *StaticDiscovery
NewStaticDiscovery creates a new StaticDiscovery with the given peer list. Peers should be in "host:port" format.
func (*StaticDiscovery) DiscoverPeers ¶
func (sd *StaticDiscovery) DiscoverPeers(ctx context.Context) (*DiscoveryResult, error)
DiscoverPeers implements Discovery.DiscoverPeers. For static discovery, it validates reachability of the configured peer list. Returns DiscoveryResult with single-node detection and reachability status.