Rate-Limit on EnRoute Standalone Gateway

Rate-Limit on EnRoute Standalone Gateway

Published January 23, 2021
Last Modified January 29, 2021

EnRoute Universal Gateway

EnRoute Universal Gateway is a flexible API gateway built to support traditional and cloud-native use cases. It is designed to run either as an Kubernetes Ingress Gateway, Standalone Gateway, Horizontally scaling L7 API gateway or a Mesh of Gateways. EnRoute can support a wide range of topologies. Depending on the need of the user, the environment, the application, either one or many of these solutions can be deployed. EnRoute also supports plugins/filters to extend functionality and enforce policies. The features page lists the available plugins for the Gateway. More details about each of the plugin can also be found on plugin pages.

A consistent policy framework across all these network components makes the EnRoute Universal Gateway a versatile and powerful solution.

This article covers how to get started with the EnRoute Standalone Gateway.

What this article covers.

Setting up EnRoute gateway is shown in four simple steps. This is the fourth step where a rate-limit config throttles the request rate to a service.

Create rate-limit filter

First we create a filter of type route_filter_ratelimit

curl -s -X POST localhost:1323/filter \
     -d 'Filter_name=rl_filter_demo' \
     -d 'Filter_type=route_filter_ratelimit'
{
  "data": {
    "insert_saaras_db_filter": {
      "affected_rows": 1
    }
  }
}

Next we create a file to hold rate-limit script

cat >rl.json <<EOL
{
  "descriptors" :
  [
    {
      "generic_key":
      {
        "descriptor_value":"default"
      }
    }
  ]
}
EOL
curl -X POST \
  -F 'Config=@rl.json' \
  http://localhost:1323/filter/rl_filter_demo/config
{
  "data": {
    "insert_saaras_db_filter": {
      "affected_rows": 1
    }
  }
}

Next we attach the rate-limit filter to the route

curl -s -X POST localhost:1323/service/demo/route/gs_route/filter/rl_filter_demo
{
  "data": {
    "insert_saaras_db_service_filter": {
      "affected_rows": 3
    }
  }
}

Dump service to see rl filter is attached to the service

curl -s localhost:1323/service/dump/demo
Create global rate-limit filter config

Create the globalconfig object

curl -s -X POST localhost:1323/globalconfig -d 'globalconfig_name=gc' -d 'globalconfig_type=globalconfig_ratelimit' | jq
{
  "data": {
    "insert_saaras_db_globalconfig": {
      "affected_rows": 1
    }
  }
}

Setup rate-limits for global config

cat >gc.json <<EOL
{
  "domain": "enroute",
  "descriptors" :
  [
    {
      "key" : "generic_key",
      "value" : "default",
      "rate_limit" :
      {
        "unit" : "second",
        "requests_per_unit" : 2
      }
    }
  ]
}
EOL

Read global config from file

curl -s -X POST localhost:1323/globalconfig/gc/config -F 'Config=@gc.json' | jq
{
  "data": {
    "update_saaras_db_globalconfig": {
      "affected_rows": 1
    }
  }
}
Send traffic

Send a request to the listener

curl -k -vvv https://enroute.local:8443 --resolve enroute.local:8443:127.0.0.1
Check envoy stats
curl -k -vvv http://localhost:9001/stats

Next steps

EnRoute standalone gateway provides simple APIs to configure Envoy proxy. Additionally you can -