Documentation ¶
Index ¶
- func DoClient(conf DOConfig) *godo.Client
- func RemoveDroplet(conf Config, drop Droplet) error
- type Backend
- type BackendConfig
- type Config
- type DOConfig
- type Droplet
- type DropletBackend
- func (b DropletBackend) Close()
- func (b DropletBackend) Connections() int
- func (b DropletBackend) Healthy() bool
- func (b DropletBackend) Host() string
- func (d *DropletBackend) ID() string
- func (d *DropletBackend) Name() string
- func (b DropletBackend) Statistics() *Stats
- func (b DropletBackend) Transport() http.RoundTripper
- type Droplets
- type Duration
- type ErrUnableToDelete
- type Inventory
- type LBConfig
- type LBStats
- type LoadBalancer
- type ProvisionConfig
- type Provisioner
- type ReverseProxy
- type Server
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RemoveDroplet ¶
RemoveDroplet will query DO to remove a droplet. The ID of the droplet is used to identify the droplet. If an error is returned the droplet most likely has not been removed.
Types ¶
type Backend ¶
type Backend interface { Transport() http.RoundTripper // Returns a transport for the backend ID() string // A string identifier of this specific backend Name() string // A name for this backend Host() string // Returns the hostname of the backend Healthy() bool // Is the backend healthy? Statistics() *Stats // Returns a copy of the latest statistics. Updated every second. Connections() int // Return the current number of connections Close() // Close the backend (before shutdown/reload). }
A Backend is a single running backend instance. It will monitor itself and update health and stats every second.
func NewDropletBackend ¶
func NewDropletBackend(d Droplet, bec BackendConfig) Backend
NewDropletBackend returns a Backend configured with the Droplet information.
type BackendConfig ¶
type BackendConfig struct { DialTimeout Duration `toml:"dial-timeout"` // Timeout for connecting to a backend. LatencyAvg int `toml:"latency-average-seconds"` // Measure latency over this many seconds HealthTimeout Duration `toml:"health-check-timeout"` // Timeout for a health check. Should be less than 1 second. HostPort int `toml:"new-host-port"` // Host port the proxy should connect to. HealthPath string `toml:"new-host-health-path"` // Health path to use. HealthHTTPS bool `toml:"new-host-health-https"` // Set to true if the health check on new backs is https. DisableHealth bool `toml:"disable-health-check"` // Disable health checks. }
BackendConfig contains configuration for handling backends. This information is mainly used to instantiate and destroy backends on demand.
func (BackendConfig) Validate ¶
func (c BackendConfig) Validate() error
Validate backend configuration. Will return the first error found. FIXME: Check remaining settings.
type Config ¶
type Config struct { Bind string `toml:"bind"` Https bool `toml:"https"` CertFile string `toml:"tls-cert-file"` KeyFile string `toml:"tls-key-file"` AddForwarded bool `toml:"add-x-forwarded-for"` WatchConfig bool `toml:"watch-config"` // Watch the configuration file for changes LoadBalancing LBConfig `toml:"loadbalancing"` InventoryFile string `toml:"inventory-file"` Backend BackendConfig `toml:"backend"` Provision ProvisionConfig `toml:"provisioning"` DO DOConfig `toml:"do-provisioner"` }
Config contains the main server configuration This maps directly to the main config file.
func ReadConfigFile ¶
ReadConfigFile will open the file with the supplied name and return the configuration. The configuration is validated.
type DOConfig ¶
type DOConfig struct { Enable bool `toml:"enable"` HostPrefix string `toml:"hostname-prefix"` Region string `toml:"region"` Size string `toml:"size"` Image string `toml:"image"` UserData string `toml:"user-data"` Backups bool `toml:"backups"` Token string `toml:"token"` SSHKeyID []int `toml:"ssh-key-ids"` }
DigitalOcean provisioning config
type Droplet ¶
type Droplet struct { ID int `toml:"id"` Name string `toml:"name"` PublicIP string `toml:"public-ip"` PrivateIP string `toml:"private-ip"` ServerHost string `toml:"server-host"` HealthURL string `toml:"health-url"` Started time.Time `toml:"started-time"` }
A Droplet as defined in the inventory file.
func CreateDroplet ¶
CreateDroplet will provision a new droplet as backend with the parameters given in the main configuration file. If no name is given, a random name with the configured prefix and 10 random characters will be generated.
type DropletBackend ¶
type DropletBackend struct { Droplet Droplet // contains filtered or unexported fields }
dropletBackend is a a backend instance with a DigitalOcean droplet behind it.
func (DropletBackend) Close ¶
func (b DropletBackend) Close()
Close the backend, which will shut down monitoring of the backend.
func (DropletBackend) Connections ¶
func (b DropletBackend) Connections() int
Connections returns the number of currently running requests. Does not include websocket connections.
func (DropletBackend) Healthy ¶
func (b DropletBackend) Healthy() bool
Healthy returns the healthy state of the backend
func (DropletBackend) Host ¶
func (b DropletBackend) Host() string
Host returns the host address of the backend.
func (*DropletBackend) ID ¶
func (d *DropletBackend) ID() string
ID returns a unique ID of this backend
func (*DropletBackend) Name ¶
func (d *DropletBackend) Name() string
ID returns a name of this backend
func (DropletBackend) Statistics ¶
func (b DropletBackend) Statistics() *Stats
Healthy returns the healthy state of the backend
func (DropletBackend) Transport ¶
func (b DropletBackend) Transport() http.RoundTripper
Transport returns a RoundTripper that will collect stats about the backend.
type Droplets ¶
type Droplets struct {
Droplets []Droplet `toml:"droplet"`
}
Droplets contains all backend droplets.
func ListDroplets ¶
ListDroplets list all droplets currently running.
type Duration ¶
Duration is our own time.Duration that fulfills the toml.UnmarshalTOML interface.
func (*Duration) UnmarshalTOML ¶
type ErrUnableToDelete ¶
type ErrUnableToDelete struct {
// contains filtered or unexported fields
}
func (ErrUnableToDelete) Error ¶
func (e ErrUnableToDelete) Error() string
type Inventory ¶
type Inventory struct {
// contains filtered or unexported fields
}
Inventory contains all backends in your inventory. This is used by the load balancer to select a backend to send incoming requests to.
func NewInventory ¶
func NewInventory(b []Backend, bec BackendConfig) *Inventory
NewInventory will a return a new Inventory with the supplied backends and config.
func ReadInventory ¶
func ReadInventory(file string, bec BackendConfig) (*Inventory, error)
ReadInventory will read an inventory file and return the found items. TODO: Make sure Id is unique
func (*Inventory) AddBackend ¶
AddBackend will add a backend to the inventory At the moment no checks are performed, but that could happen in the future.
func (*Inventory) BackendID ¶
BackendID will return a backend with the specified ID, as well as a boolean indicating if it was found.
func (*Inventory) Close ¶
func (i *Inventory) Close()
Close all backends associated with this inventory. This will stop all stats and monitoring of the backends.
func (*Inventory) Remove ¶
Remove will remove a backend from the inventory If the backend cannot be found an error will be returned.
func (*Inventory) SaveDroplets ¶
SaveDroplets will save all Doplets in the current inventory to a specified file. If the file exists it will be overwritten.
type LBConfig ¶
type LBConfig struct {
Type string `toml:"type"`
}
LBConfig contains settings for the load balancer.
type LoadBalancer ¶
type LoadBalancer interface { // Return a single backend instance. // If none can be found nil will be returned. Backend() Backend // Close all backends and stop monitoring them Close() }
A LoadBalancer is an interface for algorithms that implement various methods for returning a backend.
func NewLoadBalancer ¶
func NewLoadBalancer(conf LBConfig, i *Inventory) (LoadBalancer, error)
NewLoadBalancer returns a new load balancer described by the supplied configuration and inventory.
type ProvisionConfig ¶
type ProvisionConfig struct { Enable bool `toml:"enable"` // The minimum number of running backends. MinBackends int `toml:"min-backends"` // The maximum number of running backends. MaxBackends int `toml:"max-backends"` // If latency is below this, deprovision one server. DownscaleLatency Duration `toml:"downscale-latency"` // How long should the latency be below threshold before a server is deprovisioned. // This is an Exponentially Weighted Moving Average. DownscaleTime Duration `toml:"downscale-time"` // How long between a server can be deprovisioned. DownscaleEvery Duration `toml:"downscale-every"` // If the latency is above this, provision a new server. UpscaleLatency Duration `toml:"upscale-latency"` // How long should the latency be below threshold before a server is provisioned. // This is an Exponentially Weighted Moving Average. UpscaleTime Duration `toml:"upscale-time"` // How long between a new server can be provisioned. UpscaleEvery Duration `toml:"upscale-every"` // If a server fails this many health consequtive health checks, it will be deprovisioned. // Health checks is performed every second. MaxHealthFailures int `toml:"max-health-failures"` }
ProvisionConfig contains configuration for starting and stopping backends. This information is mainly used to instantiate and destroy backends on demand.
func (ProvisionConfig) Validate ¶
func (c ProvisionConfig) Validate() error
Validate provisioning configuration. Will return the first error found.
type Provisioner ¶
type ReverseProxy ¶
type ReverseProxy struct {
// contains filtered or unexported fields
}
func NewReverseProxy ¶
func NewReverseProxy() *ReverseProxy
NewReverseProxy will create a new reverse proxy. You must set the backend and configuration before it is usable.
func NewReverseProxyConfig ¶
func NewReverseProxyConfig(conf Config, lb LoadBalancer) *ReverseProxy
NewReverseProxyConfig will create a new reverse proxy with the supplied configuration and backend.
func (*ReverseProxy) GetBackend ¶
func (h *ReverseProxy) GetBackend() Backend
GetBackend will return a backend from the current load balancer.
func (*ReverseProxy) GetConfig ¶
func (h *ReverseProxy) GetConfig() Config
GetConfig will return a copy of the latest configuration.
func (*ReverseProxy) ServeHTTP ¶
func (h *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles reverse proxying requests. The function should be able to keep serving request and keep them alive, even if the configuration changes. It is ok to keep using the configuration from when the request was initiated for the rest of the call.
func (*ReverseProxy) SetBackends ¶
func (h *ReverseProxy) SetBackends(balancer LoadBalancer)
SetBackends will replace the current backends with the new ones. Requests currently being served will still go to the old backends, but new ones will go to a new one.
func (*ReverseProxy) SetConfig ¶
func (h *ReverseProxy) SetConfig(conf Config)
Replace the configuration with another one.
type Server ¶
type Server struct { Config Config // contains filtered or unexported fields }
Server contains the main server configuration and server-wide information. Since there is no global data, it is possible to run multiple servers at once with different configurations.
func NewServer ¶
NewServer will read the supplied config file, and return a new server. A file watcher will be set up to monitor the configuration file and reload settings if changes are detected.
func (*Server) MonitorInventory ¶
MonitorInventory will monitor the inventory file and reload the inventory if changes are detected. The monitor can be shut down by sending a channel on (Server).exitMonInv. The monitor will exit and close the supplied channel.
func (*Server) ReadConfig ¶
ReadConfig will open the file with the supplied name and read the configuration from that. Use init, to initialize the configuration on startup, if you are reloading the configuration set it to false. If successful, the new config will be applied to the server.
func (*Server) UpdateConfig ¶
UpdateConfig will check and apply a revised config. If the new config results in an error, the old config will remain.
type Stats ¶
type Stats struct { Healthy bool Latency ewma.MovingAverage FailureRate ewma.MovingAverage // contains filtered or unexported fields }
Stats contain regularly updated statistics about a backend. To access be sure to hold the 'mu' mutex.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Based on: https://gist.github.com/jarcoal/8940980 Modified so you don't need to register each individual URL, but register per method.
|
Based on: https://gist.github.com/jarcoal/8940980 Modified so you don't need to register each individual URL, but register per method. |