The tag-based routing feature allows you to allocate one or more application instances to the same group by using tags. This way, you can forward traffic to application instances in specific groups. The tag-based routing feature can be used in scenarios such as multi-version development and testing, traffic adjustment for a multi-version application, and A/B testing.

Background information

The tag-based routing feature is available only for applications that are deployed in Elastic Compute Service (ECS) clusters.

Scenarios

  • Multi-version development and testing

    If multiple versions are developed at the same time, you must prepare a development environment for each version. The costs of development environments are high. To reduce costs, you can use tag-based routing to implement end-to-end traffic adjustment.

    End-to-end traffic adjustment is implemented based on the tag-based routing feature. End-to-end traffic adjustment allows you to route specific traffic to a specific development environment. For example, if only Application B and Application D are modified in Development Environment 1, you can create Tag 1 for the versions of the two applications in Development Environment 1, and create a tag-based routing rule. This way, when Application A calls Application B, the system checks whether the traffic meets the conditions of the tag-based routing rule. If yes, the traffic is routed to Application B V1.1 in Development Environment 1. If no, the traffic is routed to Application B V1 in the baseline environment. When Application C calls Application D, the traffic is routed to Application D V1 or Application D V1.1 based on the tag-based routing rule.

  • Traffic adjustment for a multi-version application

    If multiple versions of an application run online at the same time and are deployed in different environments, you can use the tag-based routing feature to isolate the traffic that is destined for different versions in different environments. For example, you can route the traffic of flash sale orders or the traffic of orders from different channels to the special environment, and route common traffic to the common environment. This way, the traffic destined for the special environment is not routed to the common environment even if exceptions occur in the special environment, and the common environment is not affected.

  • A/B testing

    Multiple versions of an application run online at the same time. To perform A/B testing on the different versions, you can use end-to-end traffic adjustment to route the traffic that is initiated from Region A, such as the China (Hangzhou) region, to Application V1, and route the traffic that is initiated from Region B, such as the China (Shanghai) region, to Application V1.1. Then, you can verify the different versions. This helps reduce risks when you publish new products or features and facilitate product innovation.

Procedure

In this example, Application A is deployed on ECS instances. Application A has a default group, and the group contains three application instances.

The following steps describe how to configure tag-based routing:

  1. Create tags: Create Group 1 and Group 2 for Application A, allocate one application instance in the default group to Group 1 and one application instance to Group 2, and then create tags for Group 1 and Group 2.
  2. Create tag-based routing rules: Create tag-based routing rules based on the tags of Group 1 and Group 2.

After tag-based routing is configured, when Application B calls Application A, traffic is routed to Group 1 and Group 2 based on the tag-based routing rules. Other traffic that does not meet the conditions of the tag-based routing rules is routed to the default group.

Create a tag

Create a group for an application and add an instance to the group. Then, select JVM from the Group Settings drop-down list to create a tag.

  1. Log on to the EDAS console.
  2. Create a group for an application. For more information, see Create a group.
  3. Add an application instance to the new group. You can allocate an application instance of the default group to the new group, or purchase a new instance. For more information, see Add an instance.
    Notice After the application instance of the default group is allocated to the new group, you must restart the application instance. Otherwise, the system does not identify the tag. If you purchase a new instance for the new group, you do not need to restart the instance.
  4. In the upper-right corner of the new group list, select JVM from the Group Settings drop-down list.
    Grouping Settings - JVM
  5. In the Group Settings dialog box, click Custom. In the Custom section, turn on the switch in the Custom column. In the Configuration Body field, configure a tag for the group and click Configure JVM Parameters.

    You must configure a tag in the Dalicloud.service.tag=tag1 format. tag1 indicates the tag name. Set the tag name based on your business requirements.

    Group Settings- JVM - Custom

Create a tag-based routing rule

After a tag is created, you can create a tag-based routing rule based on the tag.

  1. Log on to the EDAS console.
  2. In the left-side navigation pane, choose Microservices Governance > Spring Cloud.
  3. In the navigation tree of the Spring Cloud page, click Tag-based Routing.
  4. On the Tag-based Routing page, select a region and a microservice namespace. Then, click Create label routing.
  5. In the Create label routing panel, set the parameters and click OK.
    Create label routing

    The following table describes the parameters.

    Parameter Description
    Namespace Select a region and a microservice namespace based on your business requirements.
    Route Name Enter the name of the tag-based routing rule. For example, you can enter lable-routing-group1.
    Description Enter the description of the tag-based routing rule.
    Application Select an application from the drop-down list.
    Label Select a tag from the drop-down list, which is the value of the custom JVM parameter -Dalicloud.service.tag that you set for the new group.

    Then, the IP address and port number of the instance in the group are displayed in the Application instance section.

    Link Delivery Turn on Link Delivery if you want to use end-to-end traffic adjustment.
    Note The end-to-end traffic adjustment feature is in canary release. If you want to use end-to-end traffic adjustment, join the DingTalk group whose ID is 31723701 to contact technical support.
    Traffic rules
    Frame type Select Spring Cloud or Dubbo based on your business requirements.
    • Spring Cloud: You can specify only a URL, such as /getIp.
    • Dubbo: You can select a specific service and an interface.
    Conditional mode Select At the same time meet the following conditions or Meet any of the following conditions based on your business requirements.
    Condition list Select Parameter, Cookie, or Header from the drop-down list. Examples:
    • If you select Parameter, you must specify the value in the name=xiaoming format in the Value column.
    • If you select Cookie, you must specify the value in the hello = "world" or hello = "world2" format in the Value column.

Verify the result

This topic provides an example on how to create a tag-based route for an application. You can configure a tag-based route for the application by referring to the example, and then verify the route based on your business requirements.