A cloud-native gateway acts as the entry point for your system architecture, combining the functions of a traditional traffic gateway and a microservices gateway. This integration significantly reduces network overhead and operational costs, while providing comprehensive traffic governance and observability. This topic describes how to configure a routing policy and set up alerts by associating a cloud-native gateway with services in an MSE Nacos service registry.
Prerequisites
-
A cloud-native gateway is created. For more information, see Create a cloud-native gateway.
-
An MSE Nacos engine is created. For more information, see Create an MSE Nacos engine.
-
A service is registered with MSE Nacos. For more information, see Use MSE Nacos as the service registry for a Spring Cloud application.
Cloud-native gateways do not support on-premises services that are registered with MSE Nacos or ZooKeeper.
Create a route
-
Log on to the MSE console. In the top navigation bar, select a region.
-
In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.
-
In the navigation pane on the left, click Routes. On the Routes tab, click Add Route.
-
On the Add Route page, set Route Name to
springcloud-demo, select * for Domain Name, and set the Path match rule to Prefix with a value of /. For the route destination, select Single Service, and then click Associate Service under Service Name. -
In the Associate Service panel, configure the parameters and click OK.
Set Source Type to MSE Nacos, select the target Namespace, and select the nacos-service-consumer service from the service list.
-
Set Service Name to
nacos-service-consumerand click Save and Advertise.
Configure a routing policy
Test the route without a policy
-
Log on to the MSE console.
-
In the top navigation bar, select a region.
-
In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.
-
On the Overview page, click the Gateway Ingress tab to view the Ingress IP Address of the gateway.
The list contains public and private-facing SLB instances. The Ingress IP Address of a public-facing instance, such as
8.136.xxx.xxx, is the public ingress of the gateway.NoteThe ingress IP address of a cloud-native gateway is the IP address of an associated SLB instance. You can replace the associated SLB instance with your own. For more information, see Manage gateway ingress SLB.
-
Run the following command to send a test request. Replace <public_ingress_ip> with the public ingress IP address you obtained in the previous step.
curl -I http://<public_ingress_ip>/echo-rest/helloNoteThis command sends a request to the demo service sourced from MSE Nacos. You can modify the request path based on your actual backend service.
A successful request returns the following response:
HTTP/1.1 200 OK Content-Type: text/plain;charset=UTF-8 Content-Length: 5 Date: Thu, 29 Aug 2024 08:21:47 GMT req-cost-time: 9 req-arrive-time: 1724919707979 resp-start-time: 1724919707988 x-envoy-upstream-service-time: 8 server: istio-envoy
Configure a throttling policy
In high-concurrency scenarios, a surge in requests can overload backend services without proper throttling. This can degrade response times or even cause service crashes. Throttling ensures that the request volume stays within a manageable range. A cloud-native gateway allows you to configure a throttling policy to protect your services. For more information about other routing policies, see Routing policies.
-
Log on to the MSE console. In the top navigation bar, select a region.
-
In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.
-
In the navigation pane on the left, choose Routes.
Find the routing rule that you want to modify and click Policies in the Actions column.
-
On the Policies tab, click Throttling.
A flow control rule monitors the QPS (queries per second) metric of a route. When the metric reaches the specified threshold, the gateway immediately blocks subsequent traffic. This prevents backend services from being overwhelmed by sudden traffic spikes and helps ensure high availability.
-
In the Throttling section, click the Throttling Rules tab.
-
In the Throttling Rules area, configure the following settings.
Parameter
Description
Example
Overall QPS Threshold
Specifies theOverall QPS Threshold.
1
Web fallback behavior
Set Web fallback behavior to Returns the specified content or Jump to the specified page.
Return specified content
HTTP Status Code
Specifies the HTTP Status Code to return for a throttled request. The default value is 429.
429
Returned Content-Type
Set the Returned Content-Type to Plain text or JSON.
Plain text
Returned HTTP Text
Specifies the body of the fallback response.
springcloud-demo flow limit
Whether to open
Enables or disables this rule.
Selected
-
Click New or Save, and then click OK in the confirmation dialog box.
-
-
Run the following script to test the policy. Replace <public_ingress_ip> with your public ingress IP address.
Windows
@echo off set "localUrl=http://<public_ingress_ip>/echo-rest/hello" :loop curl -i -s %localUrl% goto loopLinux
#!/bin/bash URL="http://<public_ingress_ip>/echo-rest/hello" while true; do curl -i -s $URL doneExpected response: After the throttling policy is enabled, requests that exceed the QPS threshold are blocked and receive an HTTP 429 status code and the custom message.
HTTP/1.1 429 Too Many Requests content-type: text/plain; charset=UTF-8 content-length: 26 date: Thu, 29 Aug 2024 08:54:46 GMT server: istio-envoy springcloud-demo flow limit
Monitoring and alerts
MSE cloud-native gateways send real-time alerts through email, SMS, or DingTalk when an alert is triggered, to help you proactively identify anomalies.
Add an alert contact
-
Log on to the MSE console, and select a region in the top navigation bar.
-
In the left-side navigation pane, choose Cloud-native Gateway > Alerts. On the Alerts page, click the Contacts tab.
On the Contacts tab, click Create Contact.
-
In the Create Contact dialog box, enter the contact Name and Phone Number, and then click OK.
-
Select the checkbox for the contact, click Batch Verify Mobile Number, and then confirm the verification link in the SMS message that you receive.
Configure an alert rule
A new alert rule takes effect in about 10 minutes. There may be a delay of 1 to 3 minutes in alert evaluation.
-
Log on to the MSE console, and select a region in the top navigation bar.
-
In the left-side navigation pane, choose Cloud-native Gateway > Alerts. On the Alerts page, click the Alert Policies tab.
-
On the Cloud-native Gateway Alerts page, click Create Cloud-native Gateway Alert Policy.
-
On the Create Cloud-native Gateway Alert Policy page, configure the alert parameters, and then click Complete. For more information, see Manage alert rules.
Example configuration: For Alert Group, select Cloud-native Gateway (Standard Instance). For Alert Metric, select Gateway Route QPS Alert. Set the alert condition to trigger when Gateway Route QPS is greater than 1, and set Alert Level to P3. To add a recipient, click + New Notification Target, add a contact, and select SMS and Email as notification methods. Set the notification period from 14:00 to 23:59.
-
Use a load testing tool to send requests to
http://<public_ingress_ip>/echo-rest/hello. You will receive an alert notification similar to the following:[Alibaba Cloud] A P3 alert has occurred. Alert Name: ** Cluster Name: cloud-product-prometheus_cn-hangzhou Notification Policy: [Default] ***_Notification Policy Alert Time: 2024-08-30 18:22:15 Alert Content: Cloud-native Gateway Instance ID **-Gateway (Standard Instance) route springcloud-demo QPS exceeds the threshold. Current value: 1.67
Related documentation
For troubleshooting, see the Cloud-native gateway FAQ. You can also use the built-in diagnostics feature. For more information, see AI diagnostics for cloud-native gateways.