Documentation
¶
Overview ¶
Package cluster collects and publishes cluster configuration data from files, etcd and Tarantool config storage, optionally with integrity checks.
The API of this package is alpha and may change incompatibly.
Index ¶
- Variables
- func NewStorageConnection(connOpts ConnectOpts, opts sdkconnect.URIOpts) (gstorage.Storage, gsconnect.CleanupFunc, string, error)
- func NewTCSStorage(ctx context.Context, cfg gsconnect.Config) (gstorage.Storage, gsconnect.CleanupFunc, error)
- type ConnectOpts
- type Data
- type DataCollector
- type DataPublisher
- type Factory
- type FileCollector
- type FilePublisher
- type FileReadFunc
- type IntegrityOptions
- type Option
- type RawStorage
- func (r *RawStorage) Close() error
- func (r *RawStorage) Collect() ([]Data, error)
- func (r *RawStorage) Get(ctx context.Context, key string) ([]Data, error)
- func (r *RawStorage) Publish(revision int64, data []byte) error
- func (r *RawStorage) Put(ctx context.Context, key, value string) error
- func (r *RawStorage) SetCleanup(cleanup func())
- func (r *RawStorage) Watch(ctx context.Context, key string) (<-chan WatchEvent, error)
- type StorageDataType
- type WatchEvent
Constants ¶
This section is empty.
Variables ¶
var ErrIntegrityCheckFailed = errors.New("integrity check failed")
ErrIntegrityCheckFailed reports data in a storage that fails the integrity checks: its hash or signature is missing, does not match the data or was made with another key. The error that wraps it names the storage, the key and the reason.
var ErrNoConfiguration = errors.New("a configuration data not found in ")
ErrNoConfiguration reports a storage that holds no configuration under the prefix a collector reads. The error that wraps it names the storage and the prefix.
Functions ¶
func NewStorageConnection ¶
func NewStorageConnection( connOpts ConnectOpts, opts sdkconnect.URIOpts, ) (gstorage.Storage, gsconnect.CleanupFunc, string, error)
NewStorageConnection determines a storage based on the opts.
func NewTCSStorage ¶
func NewTCSStorage(ctx context.Context, cfg gsconnect.Config, ) (gstorage.Storage, gsconnect.CleanupFunc, error)
NewTCSStorage connects to the first reachable endpoint using tt's selected TLS backend. SSL.Enable determines the transport: false explicitly selects plaintext even when SSL file paths are set. Each endpoint is bounded by DialTimeout (5 seconds when zero), with ctx as the overall setup limit.
The connection supports reads from read-only endpoints; writes return the server's usual read-only error. The caller must invoke cleanup when finished.
Types ¶
type ConnectOpts ¶
ConnectOpts is additional connect options specified by a user.
type Data ¶
type Data struct {
// Source is the origin of data, i.e. key in case of etcd or tarantool-based collectors.
Source string
// Value is data collected.
Value []byte
// Revision is data revision.
Revision int64
}
Data represents collected data with its source.
type DataCollector ¶
DataCollector interface must be implemented by a source collector.
type DataPublisher ¶
type DataPublisher interface {
// Publish publishes the data or returns an error.
Publish(revision int64, data []byte) error
}
DataPublisher interface must be implemented by a raw data publisher.
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory creates collectors and publishers for cluster configuration data. A zero Factory is usable and behaves like a plain (no-integrity) factory.
func NewFactory ¶
NewFactory creates a new Factory configured by the given options.
func (Factory) NewFileCollector ¶
func (f Factory) NewFileCollector(path string) DataCollector
NewFileCollector creates a file-based DataCollector. If the factory was configured with WithFileReadFunc, that function is used instead of os.Open.
func (Factory) NewFilePublisher ¶
func (f Factory) NewFilePublisher(path string) (DataPublisher, error)
NewFilePublisher creates a file-based DataPublisher. It is unsupported when the factory has integrity options configured (file storage cannot carry the auxiliary data needed for signatures).
func (Factory) NewRemoteStorage ¶
func (f Factory) NewRemoteStorage(stor storage.Storage, prefix, key string, timeout time.Duration, storageType string, ) (*RawStorage, error)
NewRemoteStorage creates a *RawStorage bound to the given storage backend. The returned value implements both DataCollector and DataPublisher.
type FileCollector ¶
type FileCollector struct {
// contains filtered or unexported fields
}
FileCollector collects data from a YAML file.
func NewFileCollector ¶
func NewFileCollector(path string) FileCollector
NewFileCollector creates a new file collector for a path.
func (FileCollector) Collect ¶
func (collector FileCollector) Collect() ([]Data, error)
Collect collects a configuration from a file located at a specified path.
type FilePublisher ¶
type FilePublisher struct {
// contains filtered or unexported fields
}
FilePublisher publishes data into a file as is.
func NewFilePublisher ¶
func NewFilePublisher(path string) FilePublisher
NewFilePublisher creates a new FilePublisher that writes published data into the file at the given path.
type FileReadFunc ¶
type FileReadFunc func(path string) (io.ReadCloser, error)
type IntegrityOptions ¶
type IntegrityOptions struct {
Hashers []hasher.Hasher
Signers []gcrypto.Signer
Verifiers []gcrypto.Verifier
SignerVerifiers []gcrypto.SignerVerifier
}
IntegrityOptions configure integrity-aware typed storage builder options.
type Option ¶
type Option func(*Factory)
Option configures a Factory.
func WithFileReadFunc ¶
func WithFileReadFunc(fileReadFunc FileReadFunc) Option
WithFileReadFunc overrides file reading for file-backed collectors.
func WithIntegrity ¶
func WithIntegrity(opts IntegrityOptions) Option
WithIntegrity enables typed storage integrity settings for storage-backed collectors and publishers. Defensive copies of the slices are taken.
type RawStorage ¶
type RawStorage struct {
// contains filtered or unexported fields
}
RawStorage is a connection-bound view of a remote configuration storage (etcd or tarantool config storage). It implements both DataCollector and DataPublisher as well as direct Get/Put/Watch/Close operations on individual keys.
func NewStorage ¶
func NewStorage( storage gstorage.Storage, prefix string, timeout time.Duration, key string, storageType string, integrityOpts *IntegrityOptions, objectLocation string, ) (*RawStorage, error)
NewStorage returns a *RawStorage bound to the given backend.
Most callers should use Factory.NewRemoteStorage, which fills objectLocation with the default configLocation. Use this directly only when a different objectLocation (or none) is required, such as for the failover command namespace.
func (*RawStorage) Close ¶
func (r *RawStorage) Close() error
Close releases the underlying storage connection (if SetCleanup was called).
func (*RawStorage) Collect ¶
func (r *RawStorage) Collect() ([]Data, error)
Collect collects values from storage by prefix (if no key bound) or by key.
func (*RawStorage) Publish ¶
func (r *RawStorage) Publish(revision int64, data []byte) error
Publish publishes the configuration data into the storage. If the collector key is empty, it publishes to all keys with the prefix (deleting other keys under the prefix). Otherwise, it publishes to a specific key.
func (*RawStorage) Put ¶
func (r *RawStorage) Put(ctx context.Context, key, value string) error
Put puts a key-value pair into config storage.
func (*RawStorage) SetCleanup ¶
func (r *RawStorage) SetCleanup(cleanup func())
SetCleanup attaches a cleanup callback that Close will invoke. Used when the caller wants Close to also release an underlying connection.
func (*RawStorage) Watch ¶
func (r *RawStorage) Watch(ctx context.Context, key string) (<-chan WatchEvent, error)
Watch watches on a key and return watched events through the returned channel.
type StorageDataType ¶
type StorageDataType = []byte
type WatchEvent ¶
WatchEvent is delivered on Watch channels when a watched key changes.