Skip to main content
Version: 3.9

Plugin Metadata

Description#

In this document, you will learn the basic concept of plugin metadata in APISIX and why you may need them.

Explore additional resources at the end of the document for more information on related topics.

Overview#

In APISIX, a plugin metadata object is used to configure the common metadata field(s) of all plugin instances sharing the same plugin name. It is useful when a plugin is enabled across multiple objects and requires a universal update to their metadata fields.

The following diagram illustrates the concept of plugin metadata using two instances of syslog plugins on two different routes, as well as a plugin metadata object setting a global log_format for the syslog plugin:

Without otherwise specified, the log_format on plugin metadata object should apply the same log format uniformly to both syslog plugins. However, since the syslog plugin on the /orders route has a different log_format, requests visiting this route will generate logs in the log_format specified by the plugin in route.

Metadata properties set at the plugin level is more granular and has a higher priority over the "global" metadata object.

Plugin metadata objects should only be used for plugins that have metadata fields. Check the specific plugin documentation to know more.

Example usage#

The example below shows how you can configure through the Admin API:

curl http://127.0.0.1:9180/apisix/admin/plugin_metadata/http-logger \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"log_format": {
"host": "$host",
"@timestamp": "$time_iso8601",
"client_ip": "$remote_addr"
}
}'

With this configuration, your logs would be formatted as shown below:

{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}
{"host":"localhost","@timestamp":"2020-09-23T19:05:05-04:00","client_ip":"127.0.0.1","route_id":"1"}

Additional Resource(s)#

Key Concepts - Plugins