Documentation
¶
Overview ¶
Package cluster implements the cluster service, where multiple instances of Alloy connect to each other for work distribution.
Index ¶
- Constants
- type Cluster
- type Component
- type ComponentBlock
- type Options
- type Service
- func (s *Service) ChangeState(ctx context.Context, targetState peer.State) error
- func (s *Service) Data() any
- func (s *Service) Definition() service.Definition
- func (s *Service) Run(ctx context.Context, host service.Host) error
- func (s *Service) ServiceHandler(_ service.Host) (base string, handler http.Handler)
- func (s *Service) Update(_ any) error
Constants ¶
const (
// ServiceName defines the name used for the cluster service.
ServiceName = "cluster"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster interface {
// Lookup determines the set of replicationFactor owners for a given key.
// peer.Peer.Self can be used to determine if the local node is the owner,
// allowing for short-circuiting logic to connect directly to the local node
// instead of using the network.
//
// Callers can use github.com/grafana/ckit/shard.StringKey or
// shard.NewKeyBuilder to create a key.
//
// An error will be returned if the type of eligible peers for the provided
// op is less than numOwners.
//
// NOTE: If the cluster is not ready to accept traffic as designated by Ready, the local node should not accept
// traffic to prevent overload. Always use Ready to verify before assigning work to instance.
Lookup(key shard.Key, replicationFactor int, op shard.Op) ([]peer.Peer, error)
// Peers returns the current set of peers for a Node.
//
// NOTE: If the cluster is not ready to accept traffic as designated by Ready, the local node should not accept
// traffic to prevent overload. Always use Ready to verify before assigning work to instance.
Peers() []peer.Peer
// Ready returns true if the cluster is ready to accept traffic; otherwise, false. The cluster is ready to accept
// traffic when:
// - there is no minimum size requirement specified
// - there is a minimum size requirement and the cluster size is >= that size
// - there is a minimum size requirement and cluster size is too small, but the configured wait deadline has passed.
Ready() bool
}
Cluster is a read-only view of a cluster.
type Component ¶
type Component interface {
component.Component
// NotifyClusterChange notifies the component that the state of the cluster
// has changed.
//
// Implementations should ignore calls to this method if they are configured
// to not utilize clustering.
NotifyClusterChange()
}
Component is a component which subscribes to clustering updates.
type ComponentBlock ¶
type ComponentBlock struct {
Enabled bool `alloy:"enabled,attr"`
}
ComponentBlock holds common arguments for clustering settings within a component. ComponentBlock is intended to be exposed as a block called "clustering".
type Options ¶
type Options struct {
Log log.Logger // Where to send logs to.
Metrics prometheus.Registerer // Where to send metrics to.
Tracer trace.TracerProvider // Where to send traces.
// EnableClustering toggles clustering as a whole. When EnableClustering is
// false, the instance of Alloy acts as a single-node cluster, and it is not
// possible for other nodes to join the cluster.
EnableClustering bool
NodeName string // Name to use for this node in the cluster.
AdvertiseAddress string // Address to advertise to other nodes in the cluster.
EnableTLS bool // Specifies whether TLS should be used for communication between peers.
TLSCAPath string // Path to the CA file.
TLSCertPath string // Path to the certificate file.
TLSKeyPath string // Path to the key file.
TLSServerName string // Server name to use for TLS communication.
RejoinInterval time.Duration // How frequently to rejoin the cluster to address split brain issues.
ClusterMaxJoinPeers int // Number of initial peers to join from the discovered set.
ClusterName string // Name to prevent nodes without this identifier from joining the cluster.
MinimumClusterSize int // Minimum cluster size before admitting traffic to components that use clustering.
MinimumSizeWaitTimeout time.Duration // Maximum duration to wait for minimum cluster size before proceeding; 0 means no timeout.
// Function to discover peers to join. If this function is nil or returns an
// empty slice, no peers will be joined.
DiscoverPeers discovery.DiscoverFn
}
Options are used to configure the cluster service. Options are constant for the lifetime of the cluster service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the cluster service.
func (*Service) ChangeState ¶
ChangeState changes the state of the service. If clustering is enabled, ChangeState will block until the state change has been propagated to another node; cancel the current context to stop waiting. ChangeState fails if the current state cannot move to the provided targetState.
Note that the state must be StateParticipant to receive writes.
func (*Service) Definition ¶
func (s *Service) Definition() service.Definition
Definition returns the definition of the cluster service.
func (*Service) Run ¶
Run starts the cluster service. It will run until the provided context is canceled or there is a fatal error.
func (*Service) ServiceHandler ¶
ServiceHandler returns the service handler for the clustering service. The resulting handler always returns 404 when clustering is disabled.