Manage MSE Nacos services with a cloud-native gateway

更新时间:
复制 MD 格式

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

Important

Cloud-native gateways do not support on-premises services that are registered with MSE Nacos or ZooKeeper.

Create a route

  1. Log on to the MSE console. In the top navigation bar, select a region.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.

  3. In the navigation pane on the left, click Routes. On the Routes tab, click Add Route.

  4. 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.

  5. 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.

  6. Set Service Name to nacos-service-consumer and click Save and Advertise.

Configure a routing policy

Test the route without a policy

  1. Log on to the MSE console.

  2. In the top navigation bar, select a region.

  3. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.

  4. 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.

    Note

    The 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.

  5. 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/hello
    Note

    This 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.

  1. Log on to the MSE console. In the top navigation bar, select a region.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.

  3. In the navigation pane on the left, choose Routes.

  4. Find the routing rule that you want to modify and click Policies in the Actions column.

  5. 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.

    1. In the Throttling section, click the Throttling Rules tab.

    2. 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

    3. Click New or Save, and then click OK in the confirmation dialog box.

  6. 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 loop

    Linux

    #!/bin/bash
    URL="http://<public_ingress_ip>/echo-rest/hello"
    while true; do
        curl -i -s $URL
    done

    Expected 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

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Alerts. On the Alerts page, click the Contacts tab.

  3. On the Contacts tab, click Create Contact.

  4. In the Create Contact dialog box, enter the contact Name and Phone Number, and then click OK.

  5. 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

Note

A new alert rule takes effect in about 10 minutes. There may be a delay of 1 to 3 minutes in alert evaluation.

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Alerts. On the Alerts page, click the Alert Policies tab.

  3. On the Cloud-native Gateway Alerts page, click Create Cloud-native Gateway Alert Policy.

  4. 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.

  1. 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.