All Products
Search
Document Center

Using alias in traffic shifting

Last Updated: Dec 20, 2018

When updating the alias to point to a different version, incoming traffic through the alias instantly points to the updated version, any potential instabilities introduced by the new version will affect that alias. Function Compute allows you to point to two versions at the same time, and specify the incoming traffic weight of each version.

When promoting the new version, you can first set it as the additional version with the traffic shifting weight. When the new version is running stable, you can update the major version to completely switch to the new version. Note that you do not need to specify the weight of the major version, Function Compute will calculate the weight of the major version based on the additional version weight you specify.

Shifting traffic using console

Create alias with additional version

  1. Make sure the version you want to use exists in “Version” dropdown list. If you don’t have version, please publish version first.
  2. Select the version in “Version” dropdown list, and choose “Create Alias” in “Operations” dropdown button.
    createalias

  3. Fill in the alias name, description, and additional version and weight. As shown in the figure: Create an alias named “test” with a major version 7 and an additional version 6. The additional version has a weight of 5%, and the major version has a weight of 95%.
    ca

  4. Click “ok” to confirm.

Update alias with additional version

  1. Make sure the version you want to use exists in “Version” dropdown list. If you don’t have version, please publish version first.
  2. Select the alias in “Alias” dropdown list, and choose “Update Alias” in “Operations” dropdown button.
    uac
  3. Update the additional version and the weight. As shown in the figure, update the weight of version 6 to 10%
    uad
  4. Click “ok” to confirm.

Shifting traffic using fcli

Using —route(-r) parameter to specify the additional version and the weight

Create alias with additional version

Using the command line below to create an alias myAlias within myService, myAlias pointing to major version 1, and shifting 50% of incoming traffic to version 2

  1. fcli alias create -s myService -a myAlias -v 1 -r 2=0.05

Update alias with additional version

Using the command line below to update myAlias shifting 10% of incoming traffic to version 2

  1. fcli alias update -s myService -a myAlias -r 2=0.10

Determining Which Version Has Been Invoked

When the additionalVersionWeight is set, Function Compute will allocate invocation traffic to dark launch version according to the weight you specify. You can determine the version being called in the following ways:

Function execution logs

If the log project and log store have been set, with each function invocation, you can see the corresponding request in the configured log service. The “isDarkLaunch” field in the log indicates that the request hits the additional version. The “externalServiceVersion” field in the log indicates the specific version used for this request. Please refer metrics for more versioning related log fields.

Context object

You can obtain “qualifier” and “versionId” fields from Context object during function execution. See more about Context.

Response payload of synchronous invocations

The response payload to the synchronous invocations contains an “x-fc-invocation-service-version” header to indicate the version that has been invoked.