skipper: Index | Files

package traffic

import ""

Package traffic implements a predicate to control the matching probability for a given route by setting its weight.

The probability for matching a route is defined by the mandatory first parameter, that must be a decimal number between 0.0 and 1.0 (both inclusive).

The optional second argument is used to specify the cookie name for the traffic group, in case you want to use stickiness. Stickiness allows all subsequent requests from the same client to match the same route. Stickiness of traffic is supported by the optional third parameter, indicating whether the request being matched belongs to the traffic group of the current route. If yes, the predicate matches ignoring the chance argument.

You always have to specify one argument, if you do not need stickiness, and three arguments, if your service requires stickiness.

Predicates cannot modify the response, so the responsibility of setting the traffic group cookie remains to either a filter or the backend service.

The below example, shows a possible eskip document used for green-blue deployments of APIS, which usually don't require stickiness:

// hit by 10% percent chance
    Traffic(.1) ->

// hit by remaining chance

The below example, shows a possible eskip document with two, independent traffic controlled route sets, which uses session stickiness:

// hit by 5% percent chance
    Traffic(.05, "cart-test", "test") && Path("/cart") ->
    responseCookie("cart-test", "test") ->

// hit by remaining chance
    Path("/cart") ->
    responseCookie("cart-test", "default") ->

// hit by 15% percent chance
    Traffic(.15, "catalog-test", "A") ->
    responseCookie("catalog-test", "A") ->

// hit by 30% percent chance
    Traffic(.3, "catalog-test", "B") ->
    responseCookie("catalog-test", "B") ->

// hit by remaining chance
    * ->
    responseCookie("catalog-test", "default") ->


Package Files



const (
    // The eskip name of the predicate.
    PredicateName = "Traffic"

func New Uses

func New() routing.PredicateSpec

Creates a new traffic control predicate specification.

Package traffic imports 4 packages (graph) and is imported by 7 packages. Updated 2020-05-14. Refresh now. Tools for package owners.