Documentation ¶
Index ¶
- Constants
- func LevelFilter() *logutils.LevelFilter
- func MarshalTags(tags map[string]string) []string
- func NewLogWriter(buf int) *logWriter
- func UnmarshalTags(tags []string) (map[string]string, error)
- func ValidateLevelFilter(minLevel logutils.LogLevel, filter *logutils.LevelFilter) bool
- type Agent
- func (a *Agent) DeregisterEventHandler(eh EventHandler)
- func (a *Agent) ForceLeave(node string) error
- func (a *Agent) InstallKey(key string) (*serf.KeyResponse, error)
- func (a *Agent) Join(addrs []string, replay bool) (n int, err error)
- func (a *Agent) Leave() error
- func (a *Agent) ListKeys() (*serf.KeyResponse, error)
- func (a *Agent) Query(name string, payload []byte, params *serf.QueryParam) (*serf.QueryResponse, error)
- func (a *Agent) RegisterEventHandler(eh EventHandler)
- func (a *Agent) RemoveKey(key string) (*serf.KeyResponse, error)
- func (a *Agent) Serf() *serf.Serf
- func (a *Agent) SerfConfig() *serf.Config
- func (a *Agent) SetTags(tags map[string]string) error
- func (a *Agent) Shutdown() error
- func (a *Agent) ShutdownCh() <-chan struct{}
- func (a *Agent) Start() error
- func (a *Agent) Stats() map[string]map[string]string
- func (a *Agent) UseKey(key string) (*serf.KeyResponse, error)
- func (a *Agent) UserEvent(name string, payload []byte, coalesce bool) error
- type AgentIPC
- type AgentMDNS
- type AppendSliceValue
- type Command
- type Config
- type DiscoverdEventHandler
- type EventFilter
- type EventHandler
- type EventScript
- type GatedWriter
- type IPCClient
- type LogHandler
- type Member
- type MockEventHandler
- type MockQueryHandler
- type ScriptEventHandler
- type SyslogWrapper
Constants ¶
const ( RSCommand = "rs" URSCommand = "us" QRPCAddrCommand = "qr" )
const ( MinIPCVersion = 1 MaxIPCVersion = 1 )
const DefaultBindPort int = 7946
This is the default port that we use for Serf communication
Variables ¶
This section is empty.
Functions ¶
func LevelFilter ¶
func LevelFilter() *logutils.LevelFilter
LevelFilter returns a LevelFilter that is configured with the log levels that we use.
func MarshalTags ¶
MarshalTags is a utility function which takes a map of tag key/value pairs and returns the same tags as strings in 'key=value' format.
func NewLogWriter ¶
func NewLogWriter(buf int) *logWriter
NewLogWriter creates a logWriter with the given buffer capacity
func UnmarshalTags ¶
UnmarshalTags is a utility function which takes a slice of strings in key=value format and returns them as a tag mapping.
func ValidateLevelFilter ¶
func ValidateLevelFilter(minLevel logutils.LogLevel, filter *logutils.LevelFilter) bool
ValidateLevelFilter verifies that the log levels within the filter are valid.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent starts and manages a Serf instance, adding some niceties on top of Serf such as storing logs that you can later retrieve, and invoking EventHandlers when events occur.
func (*Agent) DeregisterEventHandler ¶
func (a *Agent) DeregisterEventHandler(eh EventHandler)
DeregisterEventHandler removes an EventHandler and prevents more invocations
func (*Agent) ForceLeave ¶
ForceLeave is used to eject a failed node from the cluster
func (*Agent) InstallKey ¶
func (a *Agent) InstallKey(key string) (*serf.KeyResponse, error)
InstallKey initiates a query to install a new key on all members
func (*Agent) ListKeys ¶
func (a *Agent) ListKeys() (*serf.KeyResponse, error)
ListKeys sends a query to all members to return a list of their keys
func (*Agent) Query ¶
func (a *Agent) Query(name string, payload []byte, params *serf.QueryParam) (*serf.QueryResponse, error)
Query sends a Query on Serf, see Serf.Query.
func (*Agent) RegisterEventHandler ¶
func (a *Agent) RegisterEventHandler(eh EventHandler)
RegisterEventHandler adds an event handler to receive event notifications
func (*Agent) RemoveKey ¶
func (a *Agent) RemoveKey(key string) (*serf.KeyResponse, error)
RemoveKey sends a query to all members to remove a key from the keyring
func (*Agent) SerfConfig ¶
Returns the Serf config of the running Agent.
func (*Agent) SetTags ¶
SetTags is used to update the tags. The agent will make sure to persist tags if necessary before gossiping to the cluster.
func (*Agent) Shutdown ¶
Shutdown closes this agent and all of its processes. Should be preceded by a Leave for a graceful shutdown.
func (*Agent) ShutdownCh ¶
func (a *Agent) ShutdownCh() <-chan struct{}
ShutdownCh returns a channel that can be selected to wait for the agent to perform a shutdown.
func (*Agent) Start ¶
Start is used to initiate the event listeners. It is separate from create so that there isn't a race condition between creating the agent and registering handlers
type AgentIPC ¶
func NewAgentIPC ¶
func NewAgentIPC(agent *Agent, authKey string, listener net.Listener, logOutput io.Writer, logWriter *logWriter) *AgentIPC
NewAgentIPC is used to create a new Agent IPC handler
func (*AgentIPC) SetDiscoverd ¶
type AgentMDNS ¶
type AgentMDNS struct {
// contains filtered or unexported fields
}
AgentMDNS is used to advertise ourself using mDNS and to attempt to join peers periodically using mDNS queries.
type AppendSliceValue ¶
type AppendSliceValue []string
AppendSliceValue implements the flag.Value interface and allows multiple calls to the same variable to append a list.
func (*AppendSliceValue) Set ¶
func (s *AppendSliceValue) Set(value string) error
func (*AppendSliceValue) String ¶
func (s *AppendSliceValue) String() string
type Command ¶
type Command struct { Ui cli.Ui ShutdownCh <-chan struct{} // contains filtered or unexported fields }
Command is a Command implementation that runs a Serf agent. The command will not end unless a shutdown message is sent on the ShutdownCh. If two messages are sent on the ShutdownCh it will forcibly exit.
type Config ¶
type Config struct { // All the configurations in this section are identical to their // Serf counterparts. See the documentation for Serf.Config for // more info. NodeName string `mapstructure:"node_name"` Role string `mapstructure:"role"` DisableCoordinates bool `mapstructure:"disable_coordinates"` // Tags are used to attach key/value metadata to a node. They have // replaced 'Role' as a more flexible meta data mechanism. For compatibility, // the 'role' key is special, and is used for backwards compatibility. Tags map[string]string `mapstructure:"tags"` // TagsFile is the path to a file where Serf can store its tags. Tag // persistence is desirable since tags may be set or deleted while the // agent is running. Tags can be reloaded from this file on later starts. TagsFile string `mapstructure:"tags_file"` // BindAddr is the address that the Serf agent's communication ports // will bind to. Serf will use this address to bind to for both TCP // and UDP connections. If no port is present in the address, the default // port will be used. BindAddr string `mapstructure:"bind"` // AdvertiseAddr is the address that the Serf agent will advertise to // other members of the cluster. Can be used for basic NAT traversal // where both the internal ip:port and external ip:port are known. AdvertiseAddr string `mapstructure:"advertise"` // EncryptKey is the secret key to use for encrypting communication // traffic for Serf. The secret key must be exactly 16-bytes, base64 // encoded. The easiest way to do this on Unix machines is this command: // "head -c16 /dev/urandom | base64". If this is not specified, the // traffic will not be encrypted. EncryptKey string `mapstructure:"encrypt_key"` // KeyringFile is the path to a file containing a serialized keyring. // The keyring is used to facilitate encryption. KeyringFile string `mapstructure:"keyring_file"` // LogLevel is the level of the logs to output. // This can be updated during a reload. LogLevel string `mapstructure:"log_level"` // RPCAddr is the address and port to listen on for the agent's RPC // interface. RPCAddr string `mapstructure:"rpc_addr"` // RestAddr is the address and port to listen on for the agent's Rest // interface. RestAddr string `mapstructure:"rest_addr"` // ServiceTTL is the service's ttl that registed to blued ServiceTTL int `mapstructure:"service_ttl"` // RPCAuthKey is a key that can be set to optionally require that // RPC's provide an authentication key. This is meant to be // a very simple authentication control RPCAuthKey string `mapstructure:"rpc_auth"` // Protocol is the Serf protocol version to use. Protocol int `mapstructure:"protocol"` // ReplayOnJoin tells Serf to replay past user events // when joining based on a `StartJoin`. ReplayOnJoin bool `mapstructure:"replay_on_join"` // StartJoin is a list of addresses to attempt to join when the // agent starts. If Serf is unable to communicate with any of these // addresses, then the agent will error and exit. StartJoin []string `mapstructure:"start_join"` // EventHandlers is a list of event handlers that will be invoked. // These can be updated during a reload. EventHandlers []string `mapstructure:"event_handlers"` // Profile is used to select a timing profile for Serf. The supported choices // are "wan", "lan", and "local". The default is "lan" Profile string `mapstructure:"profile"` // SnapshotPath is used to allow Serf to snapshot important transactional // state to make a more graceful recovery possible. This enables auto // re-joining a cluster on failure and avoids old message replay. SnapshotPath string `mapstructure:"snapshot_path"` // LeaveOnTerm controls if Serf does a graceful leave when receiving // the TERM signal. Defaults false. This can be changed on reload. LeaveOnTerm bool `mapstructure:"leave_on_terminate"` // SkipLeaveOnInt controls if Serf skips a graceful leave when receiving // the INT signal. Defaults false. This can be changed on reload. SkipLeaveOnInt bool `mapstructure:"skip_leave_on_interrupt"` // Discover is used to setup an mDNS Discovery name. When this is set, the // agent will setup an mDNS responder and periodically run an mDNS query // to look for peers. For peers on a network that supports multicast, this // allows Serf agents to join each other with zero configuration. Discover string `mapstructure:"discover"` // Interface is used to provide a binding interface to use. It can be // used instead of providing a bind address, as Serf will discover the // address of the provided interface. It is also used to set the multicast // device used with `-discover`. Interface string `mapstructure:"interface"` // ReconnectIntervalRaw is the string reconnect interval time. This interval // controls how often we attempt to connect to a failed node. ReconnectIntervalRaw string `mapstructure:"reconnect_interval"` ReconnectInterval time.Duration `mapstructure:"-"` // ReconnectTimeoutRaw is the string reconnect timeout. This timeout controls // for how long we attempt to connect to a failed node before removing // it from the cluster. ReconnectTimeoutRaw string `mapstructure:"reconnect_timeout"` ReconnectTimeout time.Duration `mapstructure:"-"` // TombstoneTimeoutRaw is the string tombstone timeout. This timeout controls // for how long we remember a left node before removing it from the cluster. TombstoneTimeoutRaw string `mapstructure:"tombstone_timeout"` TombstoneTimeout time.Duration `mapstructure:"-"` // By default Serf will attempt to resolve name conflicts. This is done by // determining which node the majority believe to be the proper node, and // by having the minority node shutdown. If you want to disable this behavior, // then this flag can be set to true. DisableNameResolution bool `mapstructure:"disable_name_resolution"` // EnableSyslog is used to also tee all the logs over to syslog. Only supported // on linux and OSX. Other platforms will generate an error. EnableSyslog bool `mapstructure:"enable_syslog"` // SyslogFacility is used to control which syslog facility messages are // sent to. Defaults to LOCAL0. SyslogFacility string `mapstructure:"syslog_facility"` // RetryJoin is a list of addresses to attempt to join when the // agent starts. Serf will continue to retry the join until it // succeeds or RetryMaxAttempts is reached. RetryJoin []string `mapstructure:"retry_join"` // RetryMaxAttempts is used to limit the maximum attempts made // by RetryJoin to reach other nodes. If this is 0, then no limit // is imposed, and Serf will continue to try forever. Defaults to 0. RetryMaxAttempts int `mapstructure:"retry_max_attempts"` // RetryIntervalRaw is the string retry interval. This interval // controls how often we retry the join for RetryJoin. This defaults // to 30 seconds. RetryIntervalRaw string `mapstructure:"retry_interval"` RetryInterval time.Duration `mapstructure:"-"` // RejoinAfterLeave controls our interaction with the snapshot file. // When set to false (default), a leave causes a Serf to not rejoin // the cluster until an explicit join is received. If this is set to // true, we ignore the leave, and rejoin the cluster on start. This // only has an affect if the snapshot file is enabled. RejoinAfterLeave bool `mapstructure:"rejoin_after_leave"` // StatsiteAddr is the address of a statsite instance. If provided, // metrics will be streamed to that instance. StatsiteAddr string `mapstructure:"statsite_addr"` // StatsdAddr is the address of a statsd instance. If provided, // metrics will be sent to that instance. StatsdAddr string `mapstructure:"statsd_addr"` }
Config is the configuration that can be set for an Agent. Some of these configurations are exposed as command-line flags to `serf agent`, whereas many of the more advanced configurations can only be set by creating a configuration file.
func DecodeConfig ¶
DecodeConfig reads the configuration from the given reader in JSON format and decodes it into a proper Config structure.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig contains the defaults for configurations.
func MergeConfig ¶
MergeConfig merges two configurations together to make a single new configuration.
func ReadConfigPaths ¶
ReadConfigPaths reads the paths in the given order to load configurations. The paths can be to files or directories. If the path is a directory, we read one directory deep and read any files ending in ".json" as configuration files.
func (*Config) AddrParts ¶
BindAddrParts returns the parts of the BindAddr that should be used to configure Serf.
func (*Config) EncryptBytes ¶
EncryptBytes returns the encryption key configured.
func (*Config) EventScripts ¶
func (c *Config) EventScripts() []EventScript
EventScripts returns the list of EventScripts associated with this configuration and specified by the "event_handlers" configuration.
type DiscoverdEventHandler ¶
type DiscoverdEventHandler struct {
// contains filtered or unexported fields
}
func (*DiscoverdEventHandler) HandleEvent ¶
func (h *DiscoverdEventHandler) HandleEvent(e serf.Event)
type EventFilter ¶
EventFilter is used to filter which events are processed
func ParseEventFilter ¶
func ParseEventFilter(v string) []EventFilter
ParseEventFilter a string with the event type filters and parses it into a series of EventFilters if it can.
func (*EventFilter) Invoke ¶
func (s *EventFilter) Invoke(e serf.Event) bool
Invoke tests whether or not this event script should be invoked for the given Serf event.
func (*EventFilter) Valid ¶
func (s *EventFilter) Valid() bool
Valid checks if this is a valid agent event script.
type EventHandler ¶
EventHandler is a handler that does things when events happen.
type EventScript ¶
type EventScript struct { EventFilter Script string }
EventScript is a single event script that will be executed in the case of an event, and is configured from the command-line or from a configuration file.
func ParseEventScript ¶
func ParseEventScript(v string) []EventScript
ParseEventScript takes a string in the format of "type=script" and parses it into an EventScript struct, if it can.
func (*EventScript) String ¶
func (s *EventScript) String() string
type GatedWriter ¶
GatedWriter is an io.Writer implementation that buffers all of its data into an internal buffer until it is told to let data through.
func (*GatedWriter) Flush ¶
func (w *GatedWriter) Flush()
Flush tells the GatedWriter to flush any buffered data and to stop buffering.
type IPCClient ¶
type IPCClient struct {
// contains filtered or unexported fields
}
func (*IPCClient) RegisterQuery ¶
RegisterQuery is used to register a pending query that may get a response. The ID of the query is returned
type LogHandler ¶
type LogHandler interface {
HandleLog(string)
}
LogHandler interface is used for clients that want to subscribe to logs, for example to stream them over an IPC mechanism
type MockEventHandler ¶
MockEventHandler is an EventHandler implementation that can be used for tests.
func (*MockEventHandler) HandleEvent ¶
func (h *MockEventHandler) HandleEvent(e serf.Event)
type MockQueryHandler ¶
MockQueryHandler is an EventHandler implementation used for tests, it always responds to a query with a given response
func (*MockQueryHandler) HandleEvent ¶
func (h *MockQueryHandler) HandleEvent(e serf.Event)
type ScriptEventHandler ¶
type ScriptEventHandler struct { SelfFunc func() serf.Member Scripts []EventScript Logger *log.Logger // contains filtered or unexported fields }
ScriptEventHandler invokes scripts for the events that it receives.
func (*ScriptEventHandler) HandleEvent ¶
func (h *ScriptEventHandler) HandleEvent(e serf.Event)
func (*ScriptEventHandler) UpdateScripts ¶
func (h *ScriptEventHandler) UpdateScripts(scripts []EventScript)
UpdateScripts is used to safely update the scripts we invoke in a thread safe manner
type SyslogWrapper ¶
type SyslogWrapper struct {
// contains filtered or unexported fields
}
SyslogWrapper is used to cleaup log messages before writing them to a Syslogger. Implements the io.Writer interface.