API Management lets you quickly configure traffic shaping and alerts for APIs in your service project. This topic describes how to configure traffic shaping and alerts for APIs.
Limits
When the high availability (HA) module of DataService Studio is enabled, the traffic shaping rules for a service affect only the primary link, not the backup link.
Alert configuration is not supported for APIs in the development environment.
If the call pattern of an API is switched from synchronous call to asynchronous invocation, the alert rules for average call duration will not take effect. If the alert rules remain unchanged and the call pattern is switched from asynchronous invocation to synchronous call, the corresponding alert rules will still take effect.
Permission description
Super administrators, project administrators, and O&M personnel can configure traffic shaping and alerts for APIs.
Configure traffic shaping
In the top menu bar of the Dataphin home page, choose Service > API O&M.
In the navigation pane on the left, click Traffic Shaping & Alerts. On the API O&M page, find the desired API and click Rate Limiting in the Actions column.
In the API Traffic Shaping Configuration dialog box, configure the parameters.
Parameter
Description
Traffic Shaping Status
Enable or disable traffic shaping.
Time Unit
Select the time unit for traffic shaping. If the network is configured as a built-in gateway, only sec is supported.
Time Unit
Select the time unit for traffic shaping. If the network is configured as Alibaba Cloud API Gateway, the supported units are sec, min, hour, and day.
API Traffic Limit
Enter the traffic limit for the API. For example, if the total traffic purchased by your enterprise is 500 queries per second, and you select sec as the Time Unit, the value of API Traffic Limit should be less than or equal to 500.
APP Traffic Limit
Enter the traffic limit for downstream apps of the API. The rules for setting the App Traffic Limit are as follows:
The App Traffic Limit applies to all apps under the API.
The App Traffic Limit must be less than or equal to the API Traffic Limit.
The API Traffic Limit has a higher priority than the App Traffic Limit. For example, if the API Traffic Limit is 1,000 queries per second, and the traffic limits for App1, App2, and App3 are 500 queries per second each, the sum of the app traffic limits exceeds the API traffic limit. However, the upper limit of traffic is still the API traffic limit.
When the App Traffic Limit is greater than the API Traffic Limit, the system displays an error message.
Add App
Click Add App to configure the Application and Traffic Limit. The rules for setting the Traffic Limit are as follows:
The Traffic Limit for a specific app must be less than or equal to the API Traffic Limit.
When the Traffic Limit for a specific app is greater than the API Traffic Limit, the system displays an error message.
Click OK to complete the traffic shaping configuration for the API.
If the number of requests within a time window reaches the limit, the system protects itself by queuing, waiting, or downgrading.
Configure alerts
On the API O&M page, click Alert in the Actions column of the target API.
On the API Alert page, configure the API alert information.
Parameter
Description
Metric
Select the API monitoring metric for the alert rule. Metrics include the following:
Call Count: The total number of API calls within the specified time period.
Error Rate: The total number of API call errors divided by the total number of API calls within the specified time period.
Average Call Duration: This metric is supported only for synchronous calls. It is calculated as the total duration of API calls divided by the total number of API calls within the specified time period.
Time Unit
Select the time unit for API calls. Time Unit options include 1min, 5min, 10min, 30min, and 60min.
Operator
Select the operator for comparing the metric with the Threshold. Operators include =, >=, <=, <, >, and !=.
Threshold
Enter the threshold value that triggers the alert rule.
Notification Method
Select the method for sending alert notifications.
Notification Recipient
Select the recipients of alert notifications.
Silence Period
For multiple alerts within a short period, you can set a silence period. During the silence period after an alert notification is sent, the system will not send duplicate notifications for the same API alert rule.
Status
Select On or Off.
Click OK to complete the alert configuration for the API.
When an application calls an API and triggers a monitoring alert rule during execution, the system sends you an alert message so that you can quickly identify and handle exceptions.