etcd

package
v5.10.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2019 License: MIT, MIT, MIT Imports: 27 Imported by: 0

Documentation

Overview

Package etcd manages the embedded etcd server that Sensu uses for storing state consistently across sensu-backend processes.

To use the embedded Etcd, you must first call NewEtcd(). This will configure and start Etcd and ensure that it starts correctly. The channel returned by Err() should be monitored--these are terminal/fatal errors for Etcd.

Index

Constants

View Source
const (
	// ClusterStateNew specifies this is a new etcd cluster
	ClusterStateNew = "new"
	// EtcdStartupTimeout is the amount of time we give the embedded Etcd Server
	// to start.
	EtcdStartupTimeout = 60 // seconds

	// DefaultMaxRequestBytes is the default maximum request size for etcd
	// requests (1.5 MB)
	DefaultMaxRequestBytes = 1.5 * (1 << 20)

	// DefaultQuotaBackendBytes is the default database size limit for etcd
	// databases (4 GB)
	DefaultQuotaBackendBytes int64 = (1 << 32)
)

Variables

This section is empty.

Functions

func NewLogrusFormatter

func NewLogrusFormatter() capnslog.Formatter

NewLogrusFormatter creates a new LogrusFormatter

func Sequence

func Sequence(ctx context.Context, kv clientv3.KV, key string) (result string, err error)

Sequence provides an incrementing sequence ID. The ID is a big-endian encoded uint64 value that starts at 0.

If the key provided does not contain a sequence yet, one is created and incremented to 1. If the sequence already exists, then the next ID in the sequence will be returned.

Because sequence IDs are big-endian encoded strings, they can be ordered with lexicographic sorting. This makes them a useful key for ordered collections.

Sequence is not transactional, but is safe to use concurrently. If two clients are both using Sequence on the same key, they will race to be the one who updates the sequence. The loser of the race will execute the routine again.

func Sequences

func Sequences(ctx context.Context, kv clientv3.KV, key string, values int) ([]string, error)

Sequences is like Sequence, but returns a slice of sequences whose length is equal to values.

Types

type BackendIDGetter

type BackendIDGetter struct {
	// contains filtered or unexported fields
}

BackendIDGetter is a type that facilitates identifying a sensu backend.

func NewBackendIDGetter

func NewBackendIDGetter(ctx context.Context, client BackendIDGetterClient) *BackendIDGetter

NewBackendIDGetter creates a new BackendIDGetter. It uses a context that should be valid for the life of the application, to pass to etcd. It requires a BackendIDGetterClient, which users can provide by using an etcd *clientv3.Client.

func (*BackendIDGetter) GetBackendID

func (b *BackendIDGetter) GetBackendID() int64

type BackendIDGetterClient

type BackendIDGetterClient interface {
	Grant(ctx context.Context, ttl int64) (*clientv3.LeaseGrantResponse, error)
	KeepAlive(ctx context.Context, id clientv3.LeaseID) (<-chan *clientv3.LeaseKeepAliveResponse, error)
	Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)
}

BackendIDGetterClient represents the dependencies for BackendIDGetter.

type Config

type Config struct {
	DataDir                  string
	Name                     string // Cluster Member Name
	AdvertiseClientURLs      []string
	ListenPeerURLs           []string
	ListenClientURLs         []string
	InitialCluster           string
	InitialClusterState      string
	InitialClusterToken      string
	InitialAdvertisePeerURLs []string

	ClientTLSInfo TLSInfo
	PeerTLSInfo   TLSInfo

	CipherSuites []string

	MaxRequestBytes   uint
	QuotaBackendBytes int64
}

Config is a configuration for the embedded etcd

func NewConfig

func NewConfig() *Config

NewConfig returns a pointer to an initialized Config object with defaults.

type Etcd

type Etcd struct {
	// contains filtered or unexported fields
}

Etcd is a wrapper around github.com/coreos/etcd/embed.Etcd

func NewEtcd

func NewEtcd(config *Config) (*Etcd, error)

NewEtcd returns a new, configured, and running Etcd. The running Etcd will panic on error. The calling goroutine should recover() from the panic and shutdown accordingly. Callers must also ensure that the running Etcd is cleanly shutdown before the process terminates.

Callers should monitor the Err() channel for the running etcd--these are terminal errors.

func NewTestEtcd

func NewTestEtcd(t *testing.T) (*Etcd, func())

NewTestEtcd creates a new Etcd for testing purposes.

func (*Etcd) BackendID

func (e *Etcd) BackendID() (result string)

BackendID returns the ID of the etcd cluster member

func (*Etcd) ClientURLs

func (e *Etcd) ClientURLs() []string

func (*Etcd) Err

func (e *Etcd) Err() <-chan error

Err returns the error channel for Etcd or nil if no etcd is started.

func (*Etcd) GetClusterVersion

func (e *Etcd) GetClusterVersion() string

GetClusterVersion returns the cluster version of the etcd server

func (*Etcd) Healthy

func (e *Etcd) Healthy() bool

Healthy returns Etcd status information.

func (*Etcd) Name

func (e *Etcd) Name() string

Name returns the configured name for Etcd.

func (*Etcd) NewClient

func (e *Etcd) NewClient() (*clientv3.Client, error)

NewClient returns a new etcd v3 client. Clients must be closed after use.

func (*Etcd) Shutdown

func (e *Etcd) Shutdown() error

Shutdown will cleanly shutdown the running Etcd.

type TLSInfo

type TLSInfo transport.TLSInfo

TLSInfo wraps etcd transport TLSInfo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL