This plugin allows you to understand customer API usage and implement usage-based price & billing by metering the requests with Amberflo.io.
It supports high-volume HTTP(S) usage without adding latency.
Amberflo is the simplest way to integrate metering into your application. Sign up for free to get started.
How it works
This plugin intercepts the requests, detects which customer is making it, generates a meter event and sends it to Amberflo.
Customer detection occurs via inspection of the request headers. You can configure Kong Gateway to inject the customerId
as a header before this plugin runs. For example, if you use the Key Authentication plugin, this occurs automatically.
To avoid impacting the performance of your gateway, the plugin batches the meter records and sends them asynchronously to Amberflo.
Installation
This is a server plugin implemented in Go. You only need to make the binary available to Kong Gateway:
GOBIN=/tmp go install github.com/amberflo/kong-plugin-amberflo@latest
mv /tmp/kong-plugin-amberflo /usr/local/bin/amberflo
Then, register the plugin in your kong.conf
file:
plugins = bundled,amberflo
pluginserver_names = amberflo
pluginserver_amberflo_start_cmd = /usr/local/bin/amberflo
pluginserver_amberflo_query_cmd = /usr/local/bin/amberflo -dump
Finally, restart Kong Gateway:
kong restart
Configuration Reference
This plugin is compatible with DB-less mode.
In DB-less mode, you configure Kong Gateway declaratively. Therefore, the Admin API is mostly read-only. The only tasks it can perform are all related to handling the declarative config, including:
- Setting a target's health status in the load balancer
- Validating configurations against schemas
- Uploading the declarative configuration using the
/config
endpoint
The plugin is compatible with any with DB-less mode, including local
, cluster
, and redis
.
Example plugin configuration
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter | Description |
---|---|
name
required Type: string |
The name of the plugin, in this case amberflo . |
service.name or service.id
optional Type: string |
The name or ID of the service the plugin targets. Set one of these parameters if adding the plugin to a service through the top-level Not required if using |
route.name or route.id
optional Type: string |
The name or ID of the route the plugin targets. Set one of these parameters if adding the plugin to a route through the top-level Not required if using |
enabled
optional Type: boolean Default value: |
Whether this plugin will be applied. |
config.apiKey
required |
Your Amberflo API key. |
config.meterApiName
required |
The meter for metering the requests. |
config.customerHeader
required |
The header to get the Amberflo |
config.intervalSeconds
optional Default value: |
The rate (in seconds) at which to send the meter record batch. |
config.batchSize
optional Default value: |
The size at which to send the meter record batch. |
config.methodDimension
optional |
The dimension name for the request method. |
config.hostDimension
optional |
The dimension name for the target URL host. |
config.routeDimension
optional |
The dimension name for the route name. |
config.serviceDimension
optional |
The dimension name for the service name. |
config.dimensionHeaders
optional |
The map of “dimension name” to “header name”, for inclusion in the meter record. |
config.replacements
optional Default value: |
The map of “old” to “new” values for transforming dimension values. |