v0.21.99 Latest Latest

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

Go to latest
Published: May 23, 2024 License: Apache-2.0, MIT Imports: 4 Imported by: 7



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") ->



View Source
const (
	// Deprecated, use predicates.TrafficName instead
	PredicateName = predicates.TrafficName


This section is empty.


func New

func New() routing.PredicateSpec

Creates a new traffic control predicate specification.

func NewSegment added in v0.16.58

func NewSegment() routing.WeightedPredicateSpec

NewSegment creates a new traffic segment predicate specification


This section is empty.

Jump to

Keyboard shortcuts

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