Documentation ¶
Index ¶
- Constants
- func LevelFilter() *logutils.LevelFilter
- func NewLogWriter(buf int) *logWriter
- 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) Join(addrs []string, replay bool) (n int, err error)
- func (a *Agent) Leave() error
- func (a *Agent) RegisterEventHandler(eh EventHandler)
- func (a *Agent) Serf() *serf.Serf
- func (a *Agent) SerfConfig() *serf.Config
- func (a *Agent) Shutdown() error
- func (a *Agent) ShutdownCh() <-chan struct{}
- func (a *Agent) Start() error
- func (a *Agent) UserEvent(name string, payload []byte, coalesce bool) error
- type AgentIPC
- type AgentMDNS
- type AppendSliceValue
- type Command
- type Config
- type EventFilter
- type EventHandler
- type EventScript
- type GatedWriter
- type IPCClient
- type LogHandler
- type Member
- type MockEventHandler
- type ScriptEventHandler
Constants ¶
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 NewLogWriter ¶ added in v0.3.0
func NewLogWriter(buf int) *logWriter
NewLogWriter creates a logWriter with the given buffer capacity
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 ¶ added in v0.3.0
func (a *Agent) DeregisterEventHandler(eh EventHandler)
DeregisterEventHandler removes an EventHandler and prevents more invocations
func (*Agent) ForceLeave ¶ added in v0.3.0
ForceLeave is used to eject a failed node from the cluster
func (*Agent) Leave ¶ added in v0.3.0
Leave prepares for a graceful shutdown of the agent and its processes
func (*Agent) RegisterEventHandler ¶ added in v0.3.0
func (a *Agent) RegisterEventHandler(eh EventHandler)
RegisterEventHandler adds an event handler to recieve event notifications
func (*Agent) SerfConfig ¶
Returns the Serf config of the running Agent.
func (*Agent) Shutdown ¶
Shutdown closes this agent and all of its processes. Should be preceeded by a Leave for a graceful shutdown.
func (*Agent) ShutdownCh ¶ added in v0.3.0
func (a *Agent) ShutdownCh() <-chan struct{}
ShutdownCh returns a channel that can be selected to wait for the agent to perform a shutdown.
type AgentIPC ¶ added in v0.3.0
type AgentMDNS ¶ added in v0.4.0
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"` // 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"` // 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"` // 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"` // 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"` }
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 ¶ added in v0.2.0
DecodeConfig reads the configuration from the given reader in JSON format and decodes it into a proper Config structure.
func DefaultConfig ¶ added in v0.2.0
func DefaultConfig() *Config
DefaultConfig contains the defaults for configurations.
func MergeConfig ¶ added in v0.2.0
MergeConfig merges two configurations together to make a single new configuration.
func ReadConfigPaths ¶ added in v0.2.0
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 ¶ added in v0.4.0
BindAddrParts returns the parts of the BindAddr that should be used to configure Serf.
func (*Config) EncryptBytes ¶ added in v0.2.0
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 EventFilter ¶ added in v0.3.0
EventFilter is used to filter which events are processed
func ParseEventFilter ¶ added in v0.3.0
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 ¶ added in v0.3.0
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 ¶ added in v0.3.0
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 ¶ added in v0.3.0
type IPCClient struct {
// contains filtered or unexported fields
}
type LogHandler ¶ added in v0.3.0
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 ScriptEventHandler ¶
type ScriptEventHandler struct { Self 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 ¶ added in v0.3.0
func (h *ScriptEventHandler) UpdateScripts(scripts []EventScript)
UpdateScripts is used to safely update the scripts we invoke in a thread safe manner