traffic

package
v0.13.235 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0, MIT Imports: 4 Imported by: 7

Documentation

Overview

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
v2:
    Traffic(.1) ->
    "https://api-test-green";

// hit by remaining chance
v1:
    "https://api-test-blue";

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

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

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

// hit by 15% percent chance
catalogTestA:
    Traffic(.15, "catalog-test", "A") ->
    responseCookie("catalog-test", "A") ->
    "https://catalog-test-a";

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

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

Index

Constants

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

Variables

This section is empty.

Functions

func New

func New() routing.PredicateSpec

Creates a new traffic control predicate specification.

Types

This section is empty.

Jump to

Keyboard shortcuts

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