Documentation ¶
Index ¶
- func SetPickerStrategy(s string) error
- func SetTable(t Table)
- type Route
- type Routes
- type Table
- func (t Table) AddRoute(service, prefix, target string, weight float64, tags []string) error
- func (t Table) AddRouteWeight(service, prefix string, weight float64, tags []string) error
- func (t Table) Config(addWeight bool) []string
- func (t Table) DelRoute(service, prefix, target string) error
- func (t Table) Lookup(req *http.Request, trace string) *Target
- func (t Table) String() string
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetPickerStrategy ¶
SetPickerStrategy sets the picker function for the proxy.
Types ¶
type Route ¶ added in v1.0.6
type Route struct { // Host contains the host of the route. // not used for routing but for config generation // Table has a map with the host as key // for faster lookup and smaller search space. Host string // Path is the path prefix from a request uri Path string // Targets contains the list of URLs Targets []*Target // contains filtered or unexported fields }
Route maps a path prefix to one or more target URLs. routes can have a share value which describes the amount of traffic this route should get. You can specify that a route should get a fixed percentage of the traffic independent of how many instances are running.
type Routes ¶ added in v1.0.6
type Routes []*Route
Routes stores a list of routes usually for a single host.
type Table ¶
Table contains a set of routes grouped by host. The host routes are sorted from most to least specific by sorting the routes in reverse order by path.
func GetTable ¶
func GetTable() Table
GetTable returns the active routing table. The function is safe to be called from multiple goroutines and the value is never nil.
func Parse ¶
Parse loads a routing table from a set of route commands.
The commands are parsed in order and order matters. Deleting a route that has not been created yet yields a different result than the other way around.
Route commands can have the following form:
route add <svc> <src> <dst> weight <w> tags "<t1>,<t2>,..."
- Add route for service svc from src to dst and assign weight and tags
route add <svc> <src> <dst> weight <w>
- Add route for service svc from src to dst and assign weight
route add <svc> <src> <dst> tags "<t1>,<t2>,..."
- Add route for service svc from src to dst and assign tags
route add <svc> <src> <dst>
- Add route for service svc from src to dst
route del <svc> <src> <dst>
- Remove route matching svc, src and dst
route del <svc> <src>
- Remove all routes of services matching svc and src
route del <svc>
- Remove all routes of service matching svc
route weight <svc> <src> weight <w> tags "<t1>,<t2>,..."
- Route w% of traffic to all services matching svc, src and tags
route weight <src> weight <w> tags "<t1>,<t2>,..."
- Route w% of traffic to all services matching src and tags
route weight <svc> <src> weight <w>
- Route w% of traffic to all services matching svc and src
route weight service host/path weight w tags "tag1,tag2"
Route w% of traffic to all services matching service, host/path and tags
w is a float > 0 describing a percentage, e.g. 0.5 == 50% w <= 0: means no fixed weighting. Traffic is evenly distributed w > 0: route will receive n% of traffic. If sum(w) > 1 then w is normalized. sum(w) >= 1: only matching services will receive traffic
Note that the total sum of traffic sent to all matching routes is w%.
func ParseString ¶
ParseString loads a routing table from a string.
func (Table) AddRouteWeight ¶
func (Table) DelRoute ¶
DelRoute removes one or more routes depending on the arguments. If service, prefix and target are provided then only this route is removed. Are only service and prefix provided then all routes for this service and prefix are removed. This removes all active instances of the service from the route. If only the service is provided then all routes for this service are removed. The service will no longer receive traffic. Routes with no targets are removed.
type Target ¶ added in v1.0.5
type Target struct { // Service is the name of the service the targetURL points to Service string // Tags are the list of tags for this target Tags []string // URL is the endpoint the service instance listens on URL *url.URL // FixedWeight is the weight assigned to this target. // If the value is 0 the targets weight is dynamic. FixedWeight float64 // Weight is the actual weight for this service in percent. Weight float64 // Timer measures throughput and latency of this target Timer gometrics.Timer // contains filtered or unexported fields }