You can use the Tanzu Service Mesh API to create a service group to manage a group of services collectively.

A service group is a type of resource group in Tanzu Service Mesh. A service group is a collection of services that share certain characteristics. A service group defines one or more conditions that a service must satisfy to be included in that group.

Service groups serve two main purposes:

  • You can create a service group to aggregate and monitor relevant metrics, such as requests per seconds, latency, and error rate, for the services in the group.

  • You can also define and apply consistent policies to the entire service group.

Prerequisites

  • Get an API token and an access code to authenticate your requests to the Tanzu Service Mesh API. You must use the access code in the csp-auth-token header in your requests. For information about generating an API token and getting an access code, see Authentication with the Tanzu Service Mesh REST API.

  • Determine the criteria for membership of services in the service group that you want to create. For example, you want to put all services that are running on a specific cluster and whose name begins with "frontend" into a service group.

Procedure

  • Submit the following request.
    POST https://{server_name}/tsm/v1alpha2/projects/default/resource-groups/services

    Where {server_name} is the host name of the Tanzu Service Mesh server (for example, prod-1.nsxservicemesh.vmware.com).

    Request Body

    {
       "name": string,
       "display_name": string,
       "description": string,
       "color": string,
       "rules":{
          "fn": string,
          "match":[
             {
                "type": string,
                "fn": string,
                "key": string,
                "value": string
             }
          ],
          "rules":[
             
          ]
       }
    }
    Table 1. Request Body Parameters

    Property

    Data type

    Required/Optional

    Description

    name

    String

    Required

    Internal identifier of the service group. This parameter has a minimum length of 2 characters and a maximum length of 256 characters.

    display_name

    String

    Optional

    The name that the service group that will have in the Tanzu Service Mesh Console. If you don't provide a display_name, the value of name will appear for the service group in the Tanzu Service Mesh Console.

    The display_name can be different from the name.

    description

    String

    Optional

    Description of the service group. You can use the description of the service group to indicate its purpose or distinguish it from other service groups.

    color

    String

    Optional

    Color code of the service group. This parameter is reserved for future use.

    rules

    Nested object

    Required

    Contains the conditions that services must satisfy to be included in the group. Define the conditions inside match. Specify the operator (AND or OR) with which to join the conditions as the value of the fn property. See the descriptions of fn and match.

    To nest conditions, add a rules list inside the rules object and define the conditions in a match list inside that rules list. For an example of nested conditions, see the section "Example: Request to Create a Service Group."

    Important:

    Make sure to end the rules object with an empty rules list, as shown in the sample request body. This empty list indicates that no more conditions are nested.

    rules.fn

    String

    Required

    Operator with which to join multiple conditions inside match. To specify that a service must satisfy all the conditions to be added to the group, set fn to AND. To specify that any of the conditions can be true for the service to be added to the group, set fn to OR.

    rules.match[]

    List

    Required

    Defines individual conditions. Add type, fn, key, and value parameters for each condition inside match . See the descriptions of type, fn, key, and value .

    For an example of conditions in match, see the section "Example: Request to Create a Service Group."

    rules.match[].type

    String

    Required

    Type of condition. Set type to one of these values:

    • NAME . The condition for a service name.

    • NAMESPACE . The condition for the Kubernetes namespace of the service.

    • CLUSTER. The condition for the cluster of the service.

    Make sure that the value of type uses all uppercase letters.

    rules.match[].fn

    String

    Required

    Operator for the condition. Set fn to one of these values:

    • EXACT. The condition is true if the key exactly matches the specified value.

    • START_WITH. The condition is true if the key begins with the specified value.

    • END_WITH. The condition is true if the key ends with the specified value.

    • NOT_EXACT. The condition is true the key is an inexact (partial) match to the specified value.

    • NOT_START_WITH. The condition is true if key does not begin with the specified value.

    • NOT_END_WITH. The condition is true if key does not end with the specified value.

    rules.match[].key

    String

    Required

    Service attribute or metric to which the condition applies. Set key to one of these values:

    • name . The condition is for the service name.

    • namespace . The condition is for the Kubernetes namespace that contains the service.

    • cluster. The condition is for the cluster that the service is located in.

    The key must match the type. For example, if you specify a type of NAME, set key to name.

    rules.match[].value

    String

    Required

    Value of the key that is evaluated in the condition.

Results

If the service group was successfully created, the response header from the Tanzu Service Mesh REST API contains a status code of 200 Resource group created. The response includes the name and display_name of the service group.

Example: Request to Create a Service Group

Submit the following request to create a service group with the following membership conditions for services.

  • The service name begins with cart.

  • The service is located in the prod-cluster-ca cluster.

  • The service is contained in the default namespace or the sample-namespace namespace.

POST https://sample-server.servicemesh.biz/tsm/v1alpha2/projects/default/resource-groups/services

Use the following properties in the request body.

{
   "name":"sample-service-group",
   "display_name":"Sample service group",
   "description":"My service group",
   "rules":{
      "fn":"AND",
      "match":[
         {
            "type":"NAME",
            "fn":"START_WITH",
            "key":"name",
            "value":"cart"
         },
         {
            "type":"CLUSTER",
            "fn":"EXACT",
            "key":"cluster",
            "value":"prod-cluster-ca"
         }
      ],
      "rules":[
         {
            "fn":"OR",
            "match":[
               {
                  "type":"NAMESPACE",
                  "fn":"EXACT",
                  "key":"namespace",
                  "value":"default"
               },
               {
                  "type":"NAMESPACE",
                  "fn":"EXACT",
                  "key":"namespace",
                  "value":"sample-namespace"
               }
            ]
         }
      ],
      "rules":[
         
      ]
   }
}

Note the first rules list, which is used to nest the mutually exclusive conditions for the service's namespace. The fn property specifies OR to join these conditions. Also note the empty rules list at the end.