API Gateway - Kong

You can use Amberflo's API Metering plugin for Kong to meter the requests handled by your Kong instance and monetize your APIs. See the repository for more details.

⚡ How it Works

This plugin will intercept the requests, detect which customer is making the request, generate a meter event and send it to Amberflo.

Customer detection happens via inspection of the request headers. You can configure Kong to inject the customer id as a header before this plugin runs. For instance, if you use Kong's Key Authentication plugin, this happens automatically.

To avoid impacting the performance of your gateway, the plugin will batch meter records and send them asynchronously to Amberflo.

🚀 Installation

  1. Compile and make the binary available to your Kong instance.

    • Make sure your compilation environment is compatible with your Kong environment, otherwise the compile binary won't work.
  2. Update your Kong configuration with the now-available metering plugin.

    • For instance. Suppose you place the plugin server binary at /opt/amberflo/metering on the Kong server. Then the plugin-related parts of your kong.conf file should look like this one.
    • For more details on how to configure Kong, check out their docs here and here
  3. Enable the plugin

    • Either by adding it to your kong.yaml file or making an Admin API request.

📜 Configuration

Please find a sample configuration file here.

Here's a breakdown of the fields and their respective meanings.

apiKeystringyesYour Amberflo API key
meterApiNamestringyesMeter for metering the requests
customerHeaderstringyesHeader from which to get the Amberflo customerId
intervalSecondsintno1Send the meter record batch every x seconds
batchSizeintno10Send the meter record batch when it reaches this size
debugboolnofalseEnable debug mode of the Amberflo API client (for development)
methodDimensionstringnoDimension name for the request method
hostDimensionstringnoDimension name for the target url host
routeDimensionstringnoDimension name for the route name
serviceDimensionstringnoDimension name for the service name
dimensionHeadersmap[string]stringnoMap of "dimension name" to "header name", for inclusion in the meter record
replacementsmap[string]stringno{"/": ":"}Map of "old" to "new" values for transforming dimension values