kong-plugin-amberflo

command module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2022 License: MIT Imports: 8 Imported by: 0

README

Amberflo Kong Metering Plugin

CI Status

Amberflo is the simplest way to integrate metering into your application. Sign up for free to get started.

This if the official Amberflo plugin for Kong. Use it to meter the requests handled by your Kong instance and monetize your APIs. Check out our docs to learn more.

go install github.com/amberflo/kong-plugin-amberflo@latest

⚡ How it Works

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

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

To avoid impacting the performance of your gateway, the plugin will batch the 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, telling it the metering plugin is available.

    • 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, checkout 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 meaning.

Name Type Required? Default Description
apiKey string yes Your Amberflo API key
meterApiName string yes Meter for metering the requests
customerHeader string yes Header from which to get the Amberflo customerId
intervalSeconds int no 1 Send the meter record batch every x seconds
batchSize int no 10 Send the meter record batch when it reaches this size
debug bool no false Enable debug mode of the Amberflo API client (for development)
methodDimension string no Dimension name for the request method
hostDimension string no Dimension name for the target url host
routeDimension string no Dimension name for the route name
serviceDimension string no Dimension name for the service name
dimensionHeaders map[string]string no Map of "dimension name" to "header name", for inclusion in the meter record
replacements map[string]string no {"/": ":"} Map of "old" to "new" values for transforming dimension values

👷 Developers

  1. Build the plugin
make
  1. Start Kong. We're using docker-compose, based on their template:
make kong-up
  1. On the first time, setup a test service, route and user (see this tutorial)
make kong-init
  1. Restart the kong server whenever you rebuild the plugin
make update
  1. Use the helper scripts to interact with Kong:
./scripts/admin.sh GET /plugins
./scripts/test.sh GET /mock/requests -H 'x-api-key: super-secret-key' -i
  1. To update the plugin configuration:
./scripts/admin.sh PUT /plugins/<plugin-id> -d @metering.json
  1. To stop and clean-up docker resources
make kong-down

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL