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

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.
-
Log on to the EDAS consoleEDAS console.
In the navigation pane on the left, choose System Administration > Permission Assistant.
On the Permission Assistant page, click Create Policy.
On the Create Custom Policy tab of the Create Policy wizard, set the Policy Name and Note.
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.
For Effect, select Allow.
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.

In the Create Policy wizard, click Next.
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.
Step 2: Configure the account and environment
In the test plan, choose Add > Config Element > EDAS Config to open the configuration page.
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
In the test plan, choose Add > Sampler > EDAS Spring Cloud Sample.

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.
NoteThe 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.
NoteTo 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
After you complete the configuration, click the
icon to start the test. To view detailed logs of the engine initialization and invocation process, click the
icon in the upper-right corner.NoteWhen 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.

Test a Dubbo API
In the test plan, choose Add > Sampler > EDAS Dubbo Sample.

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.
NoteThe 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.
NoteTo 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
idandnameproperties.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".
After you complete the configuration, click the
icon to start the test. To view detailed logs of the engine initialization and invocation process, click the
icon in the upper-right corner.NoteWhen 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.

(Optional) View the API response
In the test plan, choose Add > Listener > View Results Tree.

After the listener is added, click the
icon again to run the test and view the API response.
Feedback
If you have any questions about these features, join the DingTalk group (ID: 34556175) and contact a product technical expert for assistance.




