agent

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2017 License: MPL-2.0 Imports: 79 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// OriginStart and OriginEnd are the available parameters for the origin
	// argument when streaming a file. They respectively offset from the start
	// and end of a file.
	OriginStart = "start"
	OriginEnd   = "end"
)
View Source
const (
	// ErrInvalidMethod is used if the HTTP method is not supported
	ErrInvalidMethod = "Invalid method"

	// ErrEntOnly is the error returned if accessing an enterprise only
	// endpoint
	ErrEntOnly = "Nomad Enterprise only endpoint"
)

Variables

View Source
var (
	// HeartbeatStreamFrame is the StreamFrame to send as a heartbeat, avoiding
	// creating many instances of the empty StreamFrame
	HeartbeatStreamFrame = &StreamFrame{}
)
View Source
var TempDir = os.TempDir()

TempDir defines the base dir for temporary directories.

Functions

func ApiConstraintToStructs added in v0.5.5

func ApiConstraintToStructs(c1 *api.Constraint, c2 *structs.Constraint)

func ApiJobToStructJob added in v0.5.5

func ApiJobToStructJob(job *api.Job) *structs.Job

func ApiTaskToStructsTask added in v0.5.5

func ApiTaskToStructsTask(apiTask *api.Task, structsTask *structs.Task)

func ApiTgToStructsTG added in v0.5.5

func ApiTgToStructsTG(taskGroup *api.TaskGroup, tg *structs.TaskGroup)

func LevelFilter

func LevelFilter() *logutils.LevelFilter

LevelFilter returns a LevelFilter that is configured with the log levels that we use.

func NewLogWriter

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 ACLConfig added in v0.7.0

type ACLConfig struct {
	// Enabled controls if we are enforce and manage ACLs
	Enabled bool `mapstructure:"enabled"`

	// TokenTTL controls how long we cache ACL tokens. This controls
	// how stale they can be when we are enforcing policies. Defaults
	// to "30s". Reducing this impacts performance by forcing more
	// frequent resolution.
	TokenTTL time.Duration `mapstructure:"token_ttl"`

	// PolicyTTL controls how long we cache ACL policies. This controls
	// how stale they can be when we are enforcing policies. Defaults
	// to "30s". Reducing this impacts performance by forcing more
	// frequent resolution.
	PolicyTTL time.Duration `mapstructure:"policy_ttl"`

	// ReplicationToken is used by servers to replicate tokens and policies
	// from the authoritative region. This must be a valid management token
	// within the authoritative region.
	ReplicationToken string `mapstructure:"replication_token"`
}

ACLConfig is configuration specific to the ACL system

func (*ACLConfig) Merge added in v0.7.0

func (a *ACLConfig) Merge(b *ACLConfig) *ACLConfig

Merge is used to merge two ACL configs together. The settings from the input always take precedence.

type Addresses

type Addresses struct {
	HTTP string `mapstructure:"http"`
	RPC  string `mapstructure:"rpc"`
	Serf string `mapstructure:"serf"`
}

Addresses encapsulates all of the addresses we bind to for various network services. Everything is optional and defaults to BindAddr.

func (*Addresses) Merge

func (a *Addresses) Merge(b *Addresses) *Addresses

Merge is used to merge two address configs together.

type AdvertiseAddrs

type AdvertiseAddrs struct {
	HTTP string `mapstructure:"http"`
	RPC  string `mapstructure:"rpc"`
	Serf string `mapstructure:"serf"`
}

AdvertiseAddrs is used to control the addresses we advertise out for different network services. All are optional and default to BindAddr and their default Port.

func (*AdvertiseAddrs) Merge

Merge merges two advertise addrs configs together.

type Agent

type Agent struct {
	InmemSink *metrics.InmemSink
	// contains filtered or unexported fields
}

Agent is a long running daemon that is used to run both clients and servers. Servers are responsible for managing state and making scheduling decisions. Clients can be scheduled to, and are responsible for interfacing with servers to run allocations.

func NewAgent

func NewAgent(config *Config, logOutput io.Writer, inmem *metrics.InmemSink) (*Agent, error)

NewAgent is used to create a new agent with the given configuration

func (*Agent) Client

func (a *Agent) Client() *client.Client

Client returns the configured client or nil

func (*Agent) Leave

func (a *Agent) Leave() error

Leave is used gracefully exit. Clients will inform servers of their departure so that allocations can be rescheduled.

func (*Agent) RPC

func (a *Agent) RPC(method string, args interface{}, reply interface{}) error

RPC is used to make an RPC call to the Nomad servers

func (*Agent) Server

func (a *Agent) Server() *nomad.Server

Server returns the configured server or nil

func (*Agent) Shutdown

func (a *Agent) Shutdown() error

Shutdown is used to terminate the agent.

func (*Agent) Stats

func (a *Agent) Stats() map[string]map[string]string

Stats is used to return statistics for debugging and insight for various sub-systems

type AtlasConfig

type AtlasConfig struct {
	// Infrastructure is the name of the infrastructure
	// we belong to. e.g. hashicorp/stage
	Infrastructure string `mapstructure:"infrastructure"`

	// Token is our authentication token from Atlas
	Token string `mapstructure:"token" json:"-"`

	// Join controls if Atlas will attempt to auto-join the node
	// to it's cluster. Requires Atlas integration.
	Join bool `mapstructure:"join"`

	// Endpoint is the SCADA endpoint used for Atlas integration. If
	// empty, the defaults from the provider are used.
	Endpoint string `mapstructure:"endpoint"`
}

AtlasConfig is used to enable an parameterize the Atlas integration

func (*AtlasConfig) Merge added in v0.2.2

func (a *AtlasConfig) Merge(b *AtlasConfig) *AtlasConfig

Merge merges two Atlas configurations together.

type ClientConfig

type ClientConfig struct {
	// Enabled controls if we are a client
	Enabled bool `mapstructure:"enabled"`

	// StateDir is the state directory
	StateDir string `mapstructure:"state_dir"`

	// AllocDir is the directory for storing allocation data
	AllocDir string `mapstructure:"alloc_dir"`

	// Servers is a list of known server addresses. These are as "host:port"
	Servers []string `mapstructure:"servers"`

	// NodeClass is used to group the node by class
	NodeClass string `mapstructure:"node_class"`

	// Options is used for configuration of nomad internals,
	// like fingerprinters and drivers. The format is:
	//
	//  namespace.option = value
	Options map[string]string `mapstructure:"options"`

	// Metadata associated with the node
	Meta map[string]string `mapstructure:"meta"`

	// A mapping of directories on the host OS to attempt to embed inside each
	// task's chroot.
	ChrootEnv map[string]string `mapstructure:"chroot_env"`

	// Interface to use for network fingerprinting
	NetworkInterface string `mapstructure:"network_interface"`

	// NetworkSpeed is used to override any detected or default network link
	// speed.
	NetworkSpeed int `mapstructure:"network_speed"`

	// CpuCompute is used to override any detected or default total CPU compute.
	CpuCompute int `mapstructure:"cpu_total_compute"`

	// MaxKillTimeout allows capping the user-specifiable KillTimeout.
	MaxKillTimeout string `mapstructure:"max_kill_timeout"`

	// ClientMaxPort is the upper range of the ports that the client uses for
	// communicating with plugin subsystems
	ClientMaxPort int `mapstructure:"client_max_port"`

	// ClientMinPort is the lower range of the ports that the client uses for
	// communicating with plugin subsystems
	ClientMinPort int `mapstructure:"client_min_port"`

	// Reserved is used to reserve resources from being used by Nomad. This can
	// be used to target a certain utilization or to prevent Nomad from using a
	// particular set of ports.
	Reserved *Resources `mapstructure:"reserved"`

	// GCInterval is the time interval at which the client triggers garbage
	// collection
	GCInterval time.Duration `mapstructure:"gc_interval"`

	// GCParallelDestroys is the number of parallel destroys the garbage
	// collector will allow.
	GCParallelDestroys int `mapstructure:"gc_parallel_destroys"`

	// GCDiskUsageThreshold is the disk usage threshold given as a percent
	// beyond which the Nomad client triggers GC of terminal allocations
	GCDiskUsageThreshold float64 `mapstructure:"gc_disk_usage_threshold"`

	// GCInodeUsageThreshold is the inode usage threshold beyond which the Nomad
	// client triggers GC of the terminal allocations
	GCInodeUsageThreshold float64 `mapstructure:"gc_inode_usage_threshold"`

	// GCMaxAllocs is the maximum number of allocations a node can have
	// before garbage collection is triggered.
	GCMaxAllocs int `mapstructure:"gc_max_allocs"`

	// NoHostUUID disables using the host's UUID and will force generation of a
	// random UUID.
	NoHostUUID *bool `mapstructure:"no_host_uuid"`
}

ClientConfig is configuration specific to the client mode

func (*ClientConfig) Merge

func (a *ClientConfig) Merge(b *ClientConfig) *ClientConfig

Merge is used to merge two client configs together

type Command

type Command struct {
	Version    *version.VersionInfo
	Ui         cli.Ui
	ShutdownCh <-chan struct{}
	// contains filtered or unexported fields
}

Command is a Command implementation that runs a Nomad 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.

func (*Command) AutocompleteArgs added in v0.6.0

func (c *Command) AutocompleteArgs() complete.Predictor

func (*Command) AutocompleteFlags added in v0.6.0

func (c *Command) AutocompleteFlags() complete.Flags

func (*Command) Help

func (c *Command) Help() string

func (*Command) Run

func (c *Command) Run(args []string) int

func (*Command) Synopsis

func (c *Command) Synopsis() string

type Config

type Config struct {
	// Region is the region this agent is in. Defaults to global.
	Region string `mapstructure:"region"`

	// Datacenter is the datacenter this agent is in. Defaults to dc1
	Datacenter string `mapstructure:"datacenter"`

	// NodeName is the name we register as. Defaults to hostname.
	NodeName string `mapstructure:"name"`

	// DataDir is the directory to store our state in
	DataDir string `mapstructure:"data_dir"`

	// LogLevel is the level of the logs to putout
	LogLevel string `mapstructure:"log_level"`

	// BindAddr is the address on which all of nomad's services will
	// be bound. If not specified, this defaults to 127.0.0.1.
	BindAddr string `mapstructure:"bind_addr"`

	// EnableDebug is used to enable debugging HTTP endpoints
	EnableDebug bool `mapstructure:"enable_debug"`

	// Ports is used to control the network ports we bind to.
	Ports *Ports `mapstructure:"ports"`

	// Addresses is used to override the network addresses we bind to.
	//
	// Use normalizedAddrs if you need the host+port to bind to.
	Addresses *Addresses `mapstructure:"addresses"`

	// AdvertiseAddrs is used to control the addresses we advertise.
	AdvertiseAddrs *AdvertiseAddrs `mapstructure:"advertise"`

	// Client has our client related settings
	Client *ClientConfig `mapstructure:"client"`

	// Server has our server related settings
	Server *ServerConfig `mapstructure:"server"`

	// ACL has our acl related settings
	ACL *ACLConfig `mapstructure:"acl"`

	// Telemetry is used to configure sending telemetry
	Telemetry *Telemetry `mapstructure:"telemetry"`

	// LeaveOnInt is used to gracefully leave on the interrupt signal
	LeaveOnInt bool `mapstructure:"leave_on_interrupt"`

	// LeaveOnTerm is used to gracefully leave on the terminate signal
	LeaveOnTerm bool `mapstructure:"leave_on_terminate"`

	// EnableSyslog is used to enable sending logs to syslog
	EnableSyslog bool `mapstructure:"enable_syslog"`

	// SyslogFacility is used to control the syslog facility used.
	SyslogFacility string `mapstructure:"syslog_facility"`

	// DisableUpdateCheck is used to disable the periodic update
	// and security bulletin checking.
	DisableUpdateCheck bool `mapstructure:"disable_update_check"`

	// DisableAnonymousSignature is used to disable setting the
	// anonymous signature when doing the update check and looking
	// for security bulletins
	DisableAnonymousSignature bool `mapstructure:"disable_anonymous_signature"`

	// AtlasConfig is used to configure Atlas
	Atlas *AtlasConfig `mapstructure:"atlas"`

	// Consul contains the configuration for the Consul Agent and
	// parameters necessary to register services, their checks, and
	// discover the current Nomad servers.
	Consul *config.ConsulConfig `mapstructure:"consul"`

	// Vault contains the configuration for the Vault Agent and
	// parameters necessary to derive tokens.
	Vault *config.VaultConfig `mapstructure:"vault"`

	// NomadConfig is used to override the default config.
	// This is largly used for testing purposes.
	NomadConfig *nomad.Config `mapstructure:"-" json:"-"`

	// ClientConfig is used to override the default config.
	// This is largly used for testing purposes.
	ClientConfig *client.Config `mapstructure:"-" json:"-"`

	// DevMode is set by the -dev CLI flag.
	DevMode bool `mapstructure:"-"`

	// Version information is set at compilation time
	Version *version.VersionInfo

	// List of config files that have been loaded (in order)
	Files []string `mapstructure:"-"`

	// TLSConfig provides TLS related configuration for the Nomad server and
	// client
	TLSConfig *config.TLSConfig `mapstructure:"tls"`

	// HTTPAPIResponseHeaders allows users to configure the Nomad http agent to
	// set arbritrary headers on API responses
	HTTPAPIResponseHeaders map[string]string `mapstructure:"http_api_response_headers"`

	// Sentinel holds sentinel related settings
	Sentinel *config.SentinelConfig `mapstructure:"sentinel"`
	// contains filtered or unexported fields
}

Config is the configuration for the Nomad agent.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is a the baseline configuration for Nomad

func DevConfig

func DevConfig() *Config

DevConfig is a Config that is used for dev mode of Nomad.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads the configuration at the given path, regardless if its a file or directory.

func LoadConfigDir

func LoadConfigDir(dir string) (*Config, error)

LoadConfigDir loads all the configurations in the given directory in alphabetical order.

func ParseConfig added in v0.3.1

func ParseConfig(r io.Reader) (*Config, error)

ParseConfig parses the config from the given io.Reader.

Due to current internal limitations, the entire contents of the io.Reader will be copied into memory first before parsing.

func ParseConfigFile added in v0.3.1

func ParseConfigFile(path string) (*Config, error)

ParseConfigFile parses the given path as a config file.

func (*Config) Listener

func (c *Config) Listener(proto, addr string, port int) (net.Listener, error)

Listener can be used to get a new listener using a custom bind address. If the bind provided address is empty, the BindAddr is used instead.

func (*Config) Merge

func (c *Config) Merge(b *Config) *Config

Merge merges two configurations.

type HTTPCodedError

type HTTPCodedError interface {
	error
	Code() int
}

HTTPCodedError is used to provide the HTTP error code

func CodedError

func CodedError(c int, s string) HTTPCodedError

type HTTPServer

type HTTPServer struct {
	Addr string
	// contains filtered or unexported fields
}

HTTPServer is used to wrap an Agent and expose it over an HTTP interface

func NewHTTPServer

func NewHTTPServer(agent *Agent, config *Config) (*HTTPServer, error)

NewHTTPServer starts new HTTP server over the agent

func (*HTTPServer) ACLPoliciesRequest added in v0.7.0

func (s *HTTPServer) ACLPoliciesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) ACLPolicySpecificRequest added in v0.7.0

func (s *HTTPServer) ACLPolicySpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) ACLTokenBootstrap added in v0.7.0

func (s *HTTPServer) ACLTokenBootstrap(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) ACLTokenSpecificRequest added in v0.7.0

func (s *HTTPServer) ACLTokenSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) ACLTokensRequest added in v0.7.0

func (s *HTTPServer) ACLTokensRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AgentForceLeaveRequest

func (s *HTTPServer) AgentForceLeaveRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AgentJoinRequest

func (s *HTTPServer) AgentJoinRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AgentMembersRequest

func (s *HTTPServer) AgentMembersRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AgentSelfRequest

func (s *HTTPServer) AgentSelfRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AgentServersRequest

func (s *HTTPServer) AgentServersRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

AgentServersRequest is used to query the list of servers used by the Nomad Client for RPCs. This endpoint can also be used to update the list of servers for a given agent.

func (*HTTPServer) AllocSpecificRequest

func (s *HTTPServer) AllocSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) AllocsRequest

func (s *HTTPServer) AllocsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) ClientAllocRequest added in v0.4.0

func (s *HTTPServer) ClientAllocRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) ClientGCRequest added in v0.5.2

func (s *HTTPServer) ClientGCRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) ClientStatsRequest added in v0.4.0

func (s *HTTPServer) ClientStatsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) DeploymentSpecificRequest added in v0.6.0

func (s *HTTPServer) DeploymentSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) DeploymentsRequest added in v0.6.0

func (s *HTTPServer) DeploymentsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) DirectoryListRequest added in v0.3.0

func (s *HTTPServer) DirectoryListRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) EvalSpecificRequest

func (s *HTTPServer) EvalSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) EvalsRequest

func (s *HTTPServer) EvalsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) FileCatRequest added in v0.3.2

func (s *HTTPServer) FileCatRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) FileReadAtRequest added in v0.3.0

func (s *HTTPServer) FileReadAtRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) FileStatRequest added in v0.3.0

func (s *HTTPServer) FileStatRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) FsRequest added in v0.3.1

func (s *HTTPServer) FsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) GarbageCollectRequest added in v0.3.0

func (s *HTTPServer) GarbageCollectRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) HealthRequest added in v0.7.0

func (s *HTTPServer) HealthRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) JobSpecificRequest

func (s *HTTPServer) JobSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) JobsRequest

func (s *HTTPServer) JobsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) KeyringOperationRequest added in v0.5.0

func (s *HTTPServer) KeyringOperationRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

KeyringOperationRequest allows an operator to install/delete/use keys

func (*HTTPServer) Logs added in v0.4.1

func (s *HTTPServer) Logs(resp http.ResponseWriter, req *http.Request) (interface{}, error)

Logs streams the content of a log blocking on EOF. The parameters are:

  • task: task name to stream logs for.
  • type: stdout/stderr to stream.
  • follow: A boolean of whether to follow the logs.
  • offset: The offset to start streaming data at, defaults to zero.
  • origin: Either "start" or "end" and defines from where the offset is applied. Defaults to "start".

func (*HTTPServer) MetricsRequest added in v0.7.0

func (s *HTTPServer) MetricsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

MetricsRequest returns metrics for the agent. Metrics are JSON by default but Prometheus is an optional format.

func (*HTTPServer) NodeSpecificRequest

func (s *HTTPServer) NodeSpecificRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) NodesRequest

func (s *HTTPServer) NodesRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) OperatorRaftConfiguration added in v0.5.5

func (s *HTTPServer) OperatorRaftConfiguration(resp http.ResponseWriter, req *http.Request) (interface{}, error)

OperatorRaftConfiguration is used to inspect the current Raft configuration. This supports the stale query mode in case the cluster doesn't have a leader.

func (*HTTPServer) OperatorRaftPeer added in v0.5.5

func (s *HTTPServer) OperatorRaftPeer(resp http.ResponseWriter, req *http.Request) (interface{}, error)

OperatorRaftPeer supports actions on Raft peers. Currently we only support removing peers by address.

func (*HTTPServer) OperatorRequest added in v0.5.5

func (s *HTTPServer) OperatorRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) ReconcileJobSummaries added in v0.4.1

func (s *HTTPServer) ReconcileJobSummaries(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) RegionListRequest added in v0.2.1

func (s *HTTPServer) RegionListRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) SearchRequest added in v0.6.1

func (s *HTTPServer) SearchRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

SearchRequest accepts a prefix and context and returns a list of matching IDs for that context.

func (*HTTPServer) Shutdown

func (s *HTTPServer) Shutdown()

Shutdown is used to shutdown the HTTP server

func (*HTTPServer) StatusLeaderRequest

func (s *HTTPServer) StatusLeaderRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) StatusPeersRequest

func (s *HTTPServer) StatusPeersRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

func (*HTTPServer) Stream added in v0.4.1

func (s *HTTPServer) Stream(resp http.ResponseWriter, req *http.Request) (interface{}, error)

Stream streams the content of a file blocking on EOF. The parameters are:

  • path: path to file to stream.
  • offset: The offset to start streaming data at, defaults to zero.
  • origin: Either "start" or "end" and defines from where the offset is applied. Defaults to "start".

func (*HTTPServer) ValidateJobRequest added in v0.5.5

func (s *HTTPServer) ValidateJobRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error)

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 Member

type Member struct {
	Name        string
	Addr        net.IP
	Port        uint16
	Tags        map[string]string
	Status      string
	ProtocolMin uint8
	ProtocolMax uint8
	ProtocolCur uint8
	DelegateMin uint8
	DelegateMax uint8
	DelegateCur uint8
}

type Ports

type Ports struct {
	HTTP int `mapstructure:"http"`
	RPC  int `mapstructure:"rpc"`
	Serf int `mapstructure:"serf"`
}

Ports encapsulates the various ports we bind to for network services. If any are not specified then the defaults are used instead.

func (*Ports) Merge

func (a *Ports) Merge(b *Ports) *Ports

Merge is used to merge two port configurations.

type ReadCloserWrapper added in v0.4.1

type ReadCloserWrapper struct {
	io.Reader
	io.Closer
}

ReadCloserWrapper wraps a LimitReader so that a file is closed once it has been read

func (*ReadCloserWrapper) CodecDecodeSelf added in v0.6.1

func (x *ReadCloserWrapper) CodecDecodeSelf(d *codec1978.Decoder)

func (*ReadCloserWrapper) CodecEncodeSelf added in v0.6.1

func (x *ReadCloserWrapper) CodecEncodeSelf(e *codec1978.Encoder)

type Resources added in v0.3.1

type Resources struct {
	CPU                 int    `mapstructure:"cpu"`
	MemoryMB            int    `mapstructure:"memory"`
	DiskMB              int    `mapstructure:"disk"`
	IOPS                int    `mapstructure:"iops"`
	ReservedPorts       string `mapstructure:"reserved_ports"`
	ParsedReservedPorts []int  `mapstructure:"-"`
}

func (*Resources) Merge added in v0.3.1

func (r *Resources) Merge(b *Resources) *Resources

func (*Resources) ParseReserved added in v0.3.1

func (r *Resources) ParseReserved() error

ParseReserved expands the ReservedPorts string into a slice of port numbers. The supported syntax is comma separated integers or ranges separated by hyphens. For example, "80,120-150,160"

type ServerConfig

type ServerConfig struct {
	// Enabled controls if we are a server
	Enabled bool `mapstructure:"enabled"`

	// AuthoritativeRegion is used to control which region is treated as
	// the source of truth for global tokens and ACL policies.
	AuthoritativeRegion string `mapstructure:"authoritative_region"`

	// BootstrapExpect tries to automatically bootstrap the Consul cluster,
	// by withholding peers until enough servers join.
	BootstrapExpect int `mapstructure:"bootstrap_expect"`

	// DataDir is the directory to store our state in
	DataDir string `mapstructure:"data_dir"`

	// ProtocolVersion is the protocol version to speak. This must be between
	// ProtocolVersionMin and ProtocolVersionMax.
	ProtocolVersion int `mapstructure:"protocol_version"`

	// NumSchedulers is the number of scheduler thread that are run.
	// This can be as many as one per core, or zero to disable this server
	// from doing any scheduling work.
	NumSchedulers int `mapstructure:"num_schedulers"`

	// EnabledSchedulers controls the set of sub-schedulers that are
	// enabled for this server to handle. This will restrict the evaluations
	// that the workers dequeue for processing.
	EnabledSchedulers []string `mapstructure:"enabled_schedulers"`

	// NodeGCThreshold controls how "old" a node must be to be collected by GC.
	// Age is not the only requirement for a node to be GCed but the threshold
	// can be used to filter by age.
	NodeGCThreshold string `mapstructure:"node_gc_threshold"`

	// JobGCThreshold controls how "old" a job must be to be collected by GC.
	// Age is not the only requirement for a Job to be GCed but the threshold
	// can be used to filter by age.
	JobGCThreshold string `mapstructure:"job_gc_threshold"`

	// EvalGCThreshold controls how "old" an eval must be to be collected by GC.
	// Age is not the only requirement for a eval to be GCed but the threshold
	// can be used to filter by age.
	EvalGCThreshold string `mapstructure:"eval_gc_threshold"`

	// DeploymentGCThreshold controls how "old" a deployment must be to be
	// collected by GC.  Age is not the only requirement for a deployment to be
	// GCed but the threshold can be used to filter by age.
	DeploymentGCThreshold string `mapstructure:"deployment_gc_threshold"`

	// HeartbeatGrace is the grace period beyond the TTL to account for network,
	// processing delays and clock skew before marking a node as "down".
	HeartbeatGrace time.Duration `mapstructure:"heartbeat_grace"`

	// MinHeartbeatTTL is the minimum time between heartbeats. This is used as
	// a floor to prevent excessive updates.
	MinHeartbeatTTL time.Duration `mapstructure:"min_heartbeat_ttl"`

	// MaxHeartbeatsPerSecond is the maximum target rate of heartbeats
	// being processed per second. This allows the TTL to be increased
	// to meet the target rate.
	MaxHeartbeatsPerSecond float64 `mapstructure:"max_heartbeats_per_second"`

	// 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"`

	// RetryJoin is a list of addresses to join with retry enabled.
	RetryJoin []string `mapstructure:"retry_join"`

	// RetryMaxAttempts specifies the maximum number of times to retry joining a
	// host on startup. This is useful for cases where we know the node will be
	// online eventually.
	RetryMaxAttempts int `mapstructure:"retry_max"`

	// RetryInterval specifies the amount of time to wait in between join
	// attempts on agent start. The minimum allowed value is 1 second and
	// the default is 30s.
	RetryInterval string `mapstructure:"retry_interval"`

	// RejoinAfterLeave controls our interaction with the cluster after leave.
	// When set to false (default), a leave causes Consul 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.
	RejoinAfterLeave bool `mapstructure:"rejoin_after_leave"`

	// Encryption key to use for the Serf communication
	EncryptKey string `mapstructure:"encrypt" json:"-"`
	// contains filtered or unexported fields
}

ServerConfig is configuration specific to the server mode

func (*ServerConfig) EncryptBytes added in v0.5.0

func (s *ServerConfig) EncryptBytes() ([]byte, error)

EncryptBytes returns the encryption key configured.

func (*ServerConfig) Merge

func (a *ServerConfig) Merge(b *ServerConfig) *ServerConfig

Merge is used to merge two server configs together

type StreamFrame added in v0.4.1

type StreamFrame struct {
	// Offset is the offset the data was read from
	Offset int64 `json:",omitempty"`

	// Data is the read data
	Data []byte `json:",omitempty"`

	// File is the file that the data was read from
	File string `json:",omitempty"`

	// FileEvent is the last file event that occurred that could cause the
	// streams position to change or end
	FileEvent string `json:",omitempty"`
}

StreamFrame is used to frame data of a file when streaming

func (*StreamFrame) Clear added in v0.5.1

func (s *StreamFrame) Clear()

func (*StreamFrame) CodecDecodeSelf added in v0.6.1

func (x *StreamFrame) CodecDecodeSelf(d *codec1978.Decoder)

func (*StreamFrame) CodecEncodeSelf added in v0.6.1

func (x *StreamFrame) CodecEncodeSelf(e *codec1978.Encoder)

func (*StreamFrame) IsCleared added in v0.5.1

func (s *StreamFrame) IsCleared() bool

func (*StreamFrame) IsHeartbeat added in v0.4.1

func (s *StreamFrame) IsHeartbeat() bool

IsHeartbeat returns if the frame is a heartbeat frame

type StreamFramer added in v0.4.1

type StreamFramer struct {
	Err error
	// contains filtered or unexported fields
}

StreamFramer is used to buffer and send frames as well as heartbeat.

func NewStreamFramer added in v0.4.1

func NewStreamFramer(out io.WriteCloser, plainTxt bool,
	heartbeatRate, batchWindow time.Duration, frameSize int) *StreamFramer

NewStreamFramer creates a new stream framer that will output StreamFrames to the passed output. If plainTxt is set we do not frame and just batch plain text data.

func (*StreamFramer) CodecDecodeSelf added in v0.6.1

func (x *StreamFramer) CodecDecodeSelf(d *codec1978.Decoder)

func (*StreamFramer) CodecEncodeSelf added in v0.6.1

func (x *StreamFramer) CodecEncodeSelf(e *codec1978.Encoder)

func (*StreamFramer) Destroy added in v0.4.1

func (s *StreamFramer) Destroy()

Destroy is used to cleanup the StreamFramer and flush any pending frames

func (*StreamFramer) ExitCh added in v0.4.1

func (s *StreamFramer) ExitCh() <-chan struct{}

ExitCh returns a channel that will be closed when the run loop terminates.

func (*StreamFramer) Run added in v0.4.1

func (s *StreamFramer) Run()

Run starts a long lived goroutine that handles sending data as well as heartbeating

func (*StreamFramer) Send added in v0.4.1

func (s *StreamFramer) Send(file, fileEvent string, data []byte, offset int64) error

Send creates and sends a StreamFrame based on the passed parameters. An error is returned if the run routine hasn't run or encountered an error. Send is asynchronous and does not block for the data to be transferred.

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.

func (*SyslogWrapper) Write

func (s *SyslogWrapper) Write(p []byte) (int, error)

Write is used to implement io.Writer

type Telemetry

type Telemetry struct {
	StatsiteAddr       string `mapstructure:"statsite_address"`
	StatsdAddr         string `mapstructure:"statsd_address"`
	DataDogAddr        string `mapstructure:"datadog_address"`
	PrometheusMetrics  bool   `mapstructure:"prometheus_metrics"`
	DisableHostname    bool   `mapstructure:"disable_hostname"`
	UseNodeName        bool   `mapstructure:"use_node_name"`
	CollectionInterval string `mapstructure:"collection_interval"`

	PublishAllocationMetrics bool `mapstructure:"publish_allocation_metrics"`
	PublishNodeMetrics       bool `mapstructure:"publish_node_metrics"`

	// DisableTaggedMetrics disables a new version of generating metrics which
	// uses tags
	DisableTaggedMetrics bool `mapstructure:"disable_tagged_metrics"`

	// BackwardsCompatibleMetrics allows for generating metrics in a simple
	// key/value structure as done in older versions of Nomad
	BackwardsCompatibleMetrics bool `mapstructure:"backwards_compatible_metrics"`

	// CirconusAPIToken is a valid API Token used to create/manage check. If provided,
	// metric management is enabled.
	// Default: none
	CirconusAPIToken string `mapstructure:"circonus_api_token"`
	// CirconusAPIApp is an app name associated with API token.
	// Default: "nomad"
	CirconusAPIApp string `mapstructure:"circonus_api_app"`
	// CirconusAPIURL is the base URL to use for contacting the Circonus API.
	// Default: "https://api.circonus.com/v2"
	CirconusAPIURL string `mapstructure:"circonus_api_url"`
	// CirconusSubmissionInterval is the interval at which metrics are submitted to Circonus.
	// Default: 10s
	CirconusSubmissionInterval string `mapstructure:"circonus_submission_interval"`
	// CirconusCheckSubmissionURL is the check.config.submission_url field from a
	// previously created HTTPTRAP check.
	// Default: none
	CirconusCheckSubmissionURL string `mapstructure:"circonus_submission_url"`
	// CirconusCheckID is the check id (not check bundle id) from a previously created
	// HTTPTRAP check. The numeric portion of the check._cid field.
	// Default: none
	CirconusCheckID string `mapstructure:"circonus_check_id"`
	// CirconusCheckForceMetricActivation will force enabling metrics, as they are encountered,
	// if the metric already exists and is NOT active. If check management is enabled, the default
	// behavior is to add new metrics as they are encoutered. If the metric already exists in the
	// check, it will *NOT* be activated. This setting overrides that behavior.
	// Default: "false"
	CirconusCheckForceMetricActivation string `mapstructure:"circonus_check_force_metric_activation"`
	// CirconusCheckInstanceID serves to uniquely identify the metrics coming from this "instance".
	// It can be used to maintain metric continuity with transient or ephemeral instances as
	// they move around within an infrastructure.
	// Default: hostname:app
	CirconusCheckInstanceID string `mapstructure:"circonus_check_instance_id"`
	// CirconusCheckSearchTag is a special tag which, when coupled with the instance id, helps to
	// narrow down the search results when neither a Submission URL or Check ID is provided.
	// Default: service:app (e.g. service:nomad)
	CirconusCheckSearchTag string `mapstructure:"circonus_check_search_tag"`
	// CirconusCheckTags is a comma separated list of tags to apply to the check. Note that
	// the value of CirconusCheckSearchTag will always be added to the check.
	// Default: none
	CirconusCheckTags string `mapstructure:"circonus_check_tags"`
	// CirconusCheckDisplayName is the name for the check which will be displayed in the Circonus UI.
	// Default: value of CirconusCheckInstanceID
	CirconusCheckDisplayName string `mapstructure:"circonus_check_display_name"`
	// CirconusBrokerID is an explicit broker to use when creating a new check. The numeric portion
	// of broker._cid. If metric management is enabled and neither a Submission URL nor Check ID
	// is provided, an attempt will be made to search for an existing check using Instance ID and
	// Search Tag. If one is not found, a new HTTPTRAP check will be created.
	// Default: use Select Tag if provided, otherwise, a random Enterprise Broker associated
	// with the specified API token or the default Circonus Broker.
	// Default: none
	CirconusBrokerID string `mapstructure:"circonus_broker_id"`
	// CirconusBrokerSelectTag is a special tag which will be used to select a broker when
	// a Broker ID is not provided. The best use of this is to as a hint for which broker
	// should be used based on *where* this particular instance is running.
	// (e.g. a specific geo location or datacenter, dc:sfo)
	// Default: none
	CirconusBrokerSelectTag string `mapstructure:"circonus_broker_select_tag"`
	// contains filtered or unexported fields
}

Telemetry is the telemetry configuration for the server

func (*Telemetry) Merge

func (a *Telemetry) Merge(b *Telemetry) *Telemetry

Merge is used to merge two telemetry configs together

type TestAgent added in v0.6.0

type TestAgent struct {
	// T is the testing object
	T testing.T

	// Name is an optional name of the agent.
	Name string

	// ConfigCallback is an optional callback that allows modification of the
	// configuration before the agent is started.
	ConfigCallback func(*Config)

	// Config is the agent configuration. If Config is nil then
	// TestConfig() is used. If Config.DataDir is set then it is
	// the callers responsibility to clean up the data directory.
	// Otherwise, a temporary data directory is created and removed
	// when Shutdown() is called.
	Config *Config

	// LogOutput is the sink for the logs. If nil, logs are written
	// to os.Stderr.
	LogOutput io.Writer

	// DataDir is the data directory which is used when Config.DataDir
	// is not set. It is created automatically and removed when
	// Shutdown() is called.
	DataDir string

	// Key is the optional encryption key for the keyring.
	Key string

	// Server is a reference to the started HTTP endpoint.
	// It is valid after Start().
	Server *HTTPServer

	// Agent is the embedded Nomad agent.
	// It is valid after Start().
	*Agent

	// RootToken is auto-bootstrapped if ACLs are enabled
	RootToken *structs.ACLToken
}

TestAgent encapsulates an Agent with a default configuration and startup procedure suitable for testing. It manages a temporary data directory which is removed after shutdown.

func NewTestAgent added in v0.6.0

func NewTestAgent(t testing.T, name string, configCallback func(*Config)) *TestAgent

NewTestAgent returns a started agent with the given name and configuration. The caller should call Shutdown() to stop the agent and remove temporary directories.

func (*TestAgent) Client added in v0.6.0

func (a *TestAgent) Client() *api.Client

func (*TestAgent) HTTPAddr added in v0.6.0

func (a *TestAgent) HTTPAddr() string

func (*TestAgent) Shutdown added in v0.6.0

func (a *TestAgent) Shutdown() error

Shutdown stops the agent and removes the data directory if it is managed by the test agent.

func (*TestAgent) Start added in v0.6.0

func (a *TestAgent) Start() *TestAgent

Start starts a test agent.

type UIAssetWrapper added in v0.7.0

type UIAssetWrapper struct {
	FileSystem *assetfs.AssetFS
}

func (*UIAssetWrapper) Open added in v0.7.0

func (fs *UIAssetWrapper) Open(name string) (http.File, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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