Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadLastGoodConfig ¶
func LoadLastGoodConfig()
LoadLastGoodConfig loads the last known "good" config from file
Types ¶
type Action ¶
type Action int
Action represents some outcome that is attached to a route, telling us what we should do next
type ControlPlane ¶
type ControlPlane struct { // @TODO: Use atomic.Value in Go >=1.4 tomb.Tomb // contains filtered or unexported fields }
ControlPlane represents our config-based system for controlling Hailo traffic both in terms of routing of requests to regions (region "pinning") and also routing of traffic to H1 vs H2 backends
func New ¶
func New() *ControlPlane
New initialises a control plane that loads via the config service
func (*ControlPlane) HobModes ¶
func (cp *ControlPlane) HobModes() HobModes
func (*ControlPlane) HobRegions ¶
func (cp *ControlPlane) HobRegions() HobRegions
HobRegions obtains the current hob to region mappings from the control plane
func (*ControlPlane) Regions ¶
func (cp *ControlPlane) Regions() Regions
Regions obtains the current region config from the control plane
func (*ControlPlane) Router ¶
func (cp *ControlPlane) Router(req *http.Request) Router
Router takes a request and prepares us for routing it to a backend and/or region
func (*ControlPlane) Rules ¶
func (cp *ControlPlane) Rules() SortedRules
type Extractor ¶
type Extractor interface { Hob() string // Hob is the city code Value(name string) string // Value is some POST or GET value Path() string // Path is the pathname of the request SetHob(string) // Set the hob on the request parameters Source() string // Source is whether this came from "customer" or "driver" API - expecting return one of these two Host() string // Host of request Header(name string) string // Header is some HTTP header }
Extractor allows us to extract stuff about requests when matching
type HobRegions ¶
HobRegions maps HOBs to primary regions
func (HobRegions) Find ¶
func (hr HobRegions) Find(hob string) string
Find locates the region ID for a HOB, falling back to "default" if none found and returning "" if that isn't present
type Match ¶
type Match struct { Hob string `json:"regulatoryArea,omitempty"` // Hob is our city code, worked out either from hostname or explicit city=FOO parameter (POST or GET) Path string `json:"path,omitempty"` // Path is the pathname, like /v1/foo/bar Source string `json:"source,omitempty"` // Source is either "customer" or "driver" or "", where we work this out from the hostname (contains customer or driver or not) Proportion float32 `json:"proportion,omitempty"` // Proportion is a float from 0 to 1 that gives us sampling Sampler Sampler `json:"sampler,omitempty"` // Sampler tells us how to sample }
Match represents some criteria to match an HTTP request against
type Payload ¶
type Payload struct { Body string `json:"body,omitempty"` HttpStatus int `json:"httpStatus,omitempty"` Headers map[string]string `json:"headers,omitempty"` }
Payload represents the information we want to use when serving throttled calls
type Region ¶
type Region struct { Id string `json:"id,omitempty"` // ID of this region, eg: us-east-1 Status string `json:"status,omitempty"` // Status is ONLINE or OFFLINE - not a bool to cope with possible future additions Failover []string `json:"failover,omitempty"` // Failover regions (if this one down) Apps map[string]Urls `json:"apps,omitempty"` // Apps and their URL config for pinning }
Region defines config for a single AWS region
type Regions ¶
Regions represents a map of all region definitions for app pinning purposes, indexed by ID
type Router ¶
type Router interface { Route() *Rule GetHobMode() string SetHob(string) Region() (region *Region, version int64) CorrectHostname(rw http.ResponseWriter) (err error, isCorrect bool, urls Urls, version int64) }
A Router routes a request to a backend (H1, H2, or throttle) according to the first matching rule (rules are sorted by specificity)
type Rule ¶
type Rule struct { Match *Match `json:"match,omitempty"` Action Action `json:"action,omitempty"` Payload *Payload `json:"payload,omitempty"` Weight int `json:"weight,omitempty"` }
Rule represents some matching criteria plus an action
func (*Rule) Specificity ¶
Specificity returns a number that tells us how specific this rule is - in a similar vein to CSS. We will then check the most specific first.
type RuleRouter ¶
type RuleRouter struct {
// contains filtered or unexported fields
}
func (*RuleRouter) CorrectHostname ¶
func (r *RuleRouter) CorrectHostname(rw http.ResponseWriter) (err error, isCorrect bool, urls Urls, version int64)
CorrectHostname tests if the request hostname matches the expected hostname for the active region, and if not, returns the right one
func (*RuleRouter) GetHobMode ¶
func (r *RuleRouter) GetHobMode() string
GetHobMode returns the mode
func (*RuleRouter) Region ¶
func (r *RuleRouter) Region() (region *Region, version int64)
Region identifies the region, and its config, that we should be sending API requests to for a given HTTP request
func (*RuleRouter) Route ¶
func (r *RuleRouter) Route() *Rule
Route routes a request to a backend (H1, H2 or throttle) according to the first matching rule (rules sorted by specificity)
func (*RuleRouter) SetHob ¶
func (r *RuleRouter) SetHob(hob string)
type Sampler ¶
type Sampler int
Sampler defines how we should sample requests for matching
const ( // RandomSampler samples completely randomly RandomSampler Sampler = 0 // CustomerSampler samples by "customer" POST or GET parameter CustomerSampler Sampler = 1 // DriverSampler samples by "driver" POST or GET parameter DriverSampler Sampler = 2 // DeviceSampler samples by "device" POST or GET parameter DeviceSampler Sampler = 3 // SessionSampler samples by "api_token" or "session_id" POST or GET parameter SessionSampler Sampler = 4 )
type SortedRules ¶
type SortedRules []*Rule
SortedRules represents a set of rules, sorted by specificity
func (SortedRules) Validate ¶
func (s SortedRules) Validate() error
Validate tests if the sorted rules are considered a valid set