Use JMeter to test microservice APIs

Updated at:

This topic describes how to use JMeter to test the APIs of Spring Cloud or Dubbo services on the cloud.

Test workflow

测试流程..png

Permissions

Before you run JMeter, obtain the following permissions to prevent accidental API calls in your cloud environment.

  • Read permissions on the target application: This permission lets you select the application to access its APIs.

  • API access permissions: This permission lets you call the APIs.

  1. Log on to the EDAS consoleEDAS console.

  2. In the navigation pane on the left, choose System Administration > Permission Assistant.

  3. On the Permission Assistant page, click Create Policy.

  4. On the Create Custom Policy tab of the Create Policy wizard, set the Policy Name and Note.

  5. On the Create Custom Policy tab, click Add Authorization Statement. In the Add Authorization Statement panel, set the application's view and API access permissions, and then click OK.

    1. For Effect, select Allow.

    2. In the permission list on the left side of the Authorize Operations and Resources section, select Application > View Application and Application > API Access. In the resource list on the right, set the Region, Microservices Namespace, and Application as needed.

      资源授权

  6. In the Create Policy wizard, click Next.

  7. On the Preview Policy tab, preview the permissions. Follow the on-screen instructions to create a custom policy in the Resource Access Management (RAM) console and grant the permissions to the RAM user. Then, click Finish. For more information, see Step 3: Create a RAM user and grant permissions.

    After the policy is successfully granted, a message is displayed. Click Return to List to go to the Permission Assistant page and view the new policy template.

Procedure

Step 1: Install the plug-in

Download and decompress the jmeter-plugins-edas.jar.zip package. Place the extracted jmeter-plugins-edas.jar file into the lib/ext directory of your JMeter installation, and then start JMeter.image.jpeg

Step 2: Configure the account and environment

  1. In the test plan, choose Add > Config Element > EDAS Config to open the configuration page.

  2. On the EDAS Config page, set the AccessKeyId and AccessKeySecret for your account, and configure the target test environment.

Step 3: Test the API

Test a Spring Cloud API

  1. In the test plan, choose Add > Sampler > EDAS Spring Cloud Sample.

    image.jpeg

  2. The configuration of the EDAS Spring Cloud Sample sampler is shown in the following figure.

    The configuration is as follows:

    Configuration Module

    Configuration Item

    Description

    Example

    Service

    Service

    The target Spring Cloud service.

    service-provider

    Path

    The API path of the target Spring Cloud service.

    /echo/{string}

    Specify Target for Invocation (Optional)

    Application

    By default, the JMeter plug-in initiates API access to the target Spring Cloud service in the microservices namespace. If the Spring Cloud service has multiple applications, you can specify an application to invoke.

    None

    Instance

    By default, the JMeter plug-in initiates API access to the target Spring Cloud service in the microservices namespace. If the Spring Cloud service has multiple instances, you can specify an instance to invoke.

    Note

    The instance IP address of a Kubernetes application changes after each deployment. Therefore, avoid specifying a target instance in scenarios such as regression testing.

    None

    Test Channel

    EDAS Test Engine: Invoke

    By default, the EDAS test engine sends test requests and limits the request frequency. We recommend that you do not send more than 5 requests per second.

    Used by default

    Use EDAS Cloud Native Kit to invoke

    Send test requests through the EDAS Cloud Native Kit. This method does not limit the request frequency.

    Note

    To configure this method, join the DingTalk group (ID: 34556175) and contact a product technical expert for assistance.

    None

    Parameters

    Params

    Set the query parameters for the request.

    Set the following query parameters:

    • key: name

    • value: Jack

    Body

    Set the body parameters for POST and PUT requests. The following body parameter types are supported:

    • none (no body parameters)

    • x-www-form-urlencoded

    • json

    • xml

    • text/plain

    • Set the body parameter type:

      x-www-form-urlencoded

    • Set key/value:

      • key: age

      • value: 20

    Headers

    Set the header parameters for the request.

    Set the following header:

    • key: User-Agent

    • value: Mozilla/5.0

    Cookies

    Set the cookie parameters for the request.

    Set the following cookie:

    • key: SessionId

    • value: 123

  3. After you complete the configuration, click the 运行..png icon to start the test. To view detailed logs of the engine initialization and invocation process, click the 查看日志..png icon in the upper-right corner.

    Note

    When you start a test for the first time, the cloud-based Deep Packet Inspection (DPI) engine must be initialized. This process takes about 10 to 20 seconds. After the engine is initialized, it remains initialized for one hour.

    image.jpeg

Test a Dubbo API

  1. In the test plan, choose Add > Sampler > EDAS Dubbo Sample.

    image.jpeg

  2. The configuration of the EDAS Dubbo Sample sampler is shown in the following figure.

    The following describes the configurations:

    Configuration Module

    Configuration Item

    Description

    Example

    Service

    Interface

    The target Dubbo interface.

    org.apache.dubbo.springboot.demo.DemoService(Version:1.0.0,Group:dev)

    Method

    The target Dubbo method.

    sayHello

    Specify Target for Invocation (Optional)

    Application

    By default, the JMeter plug-in initiates API access to the target Dubbo service in the microservices namespace. If the Dubbo service has multiple applications, you can specify an application to invoke.

    None

    Instance

    By default, the JMeter plug-in initiates API access to the target Dubbo service in the microservices namespace. If the Dubbo service has multiple instances, you can specify an instance to invoke.

    Note

    The instance IP address of a Kubernetes application changes after each deployment. Therefore, avoid specifying a target instance in scenarios such as regression testing.

    None

    Test Channel

    Invoke using the EDAS Test Engine

    By default, test requests are sent using the EDAS test engine, which limits the request frequency. We recommend that you send no more than 5 requests per second.

    Used by default

    Use EDAS Cloud Native Kit to invoke

    Send test requests through the EDAS Cloud Native Kit. This method does not limit the request frequency.

    Note

    To configure this method, join the DingTalk group (ID: 34556175) and contact a product technical expert for assistance.

    None

    Parameters

    Interface Parameters

    Set the parameters for the Dubbo method.

    • paramType: The parameter type.

    • paramValue: The parameter value.

    • null: Sets the parameter value to NULL.

    • Parameter type (paramType):

      java.lang.String

    • Parameter value (paramValue):

      helloworld

    Attachment

    Set the implicit parameters for the Dubbo method call.

    • key: The key of the implicit parameter.

    • value: The value of the implicit parameter.

    For more information, see Pass implicit parameters through the call chain.

    • key: color

    • value: blue

    The following table provides more examples of Dubbo interface parameters.

    paramType

    paramValue

    Notes

    • int

    • java.lang.String

    • 100

    • Jack

    The interface uses two parameters. The first is an integer and the second is a string.

    java.util.Map

    {"color": "blue"}

    Map type parameters use the JSON object format, which is enclosed in braces: {"color": "blue"}.

    java.util.List

    ["Apple", "Banana", "Orange"]

    In this example, the interface parameter is of the List type, and its elements are strings. List type parameters use the JSON array format, such as ["Apple", "Banana", "Orange"].

    com.test.User

    {"id": 100, "name": "Sam"}

    In this example, the interface parameter is a custom User type, which contains the id and name properties.

    AbstractUser

    {"id": 100, "name": "Sam", "class": "com.test.User"}

    In this example, the interface parameter is defined as the abstract class AbstractUser. In the actual parameter, you must use the class property to specify the actual type of the current parameter, such as "class": "com.test.User".

  3. After you complete the configuration, click the 运行..png icon to start the test. To view detailed logs of the engine initialization and invocation process, click the 日志..png icon in the upper-right corner.

    Note

    When you start a test for the first time, the cloud-based DPI engine must be initialized. This process takes about 10 to 20 seconds. After the engine is initialized, it remains initialized for one hour.

    2023-04-28-10..jpeg

(Optional) View the API response

  1. In the test plan, choose Add > Listener > View Results Tree.2023-04-28-11..jpeg

  2. After the listener is added, click the 运行..png icon again to run the test and view the API response.2023-04-28-12..jpeg

Feedback

If you have any questions about these features, join the DingTalk group (ID: 34556175) and contact a product technical expert for assistance.