Reference HostIP for KongPlugin Declarations

This is a bit of a necro but it seems there’s been no official resolution on this yet and this is the newest thread I see :slight_smile:

I was tipped off that kong Lua can access environment variables from the ‘init phase’ aka before any configuration is loaded, as seen when loading ambient authority environment variables.

With this in mind, it’s possible for a plugin to load a specific environment variable – as long as the variable name is hardcoded.

For example, I made a copy of the datadog plugin and added this line at the very top of handler.lua:

local ENV_DD_AGENT_HOST = os.getenv 'KONG_DD_AGENT_HOST'

(KONG_ prefix added because Kong’s official helm chart has literally no support for non-prefixed environment variables, lmao)

then I can use that value to ‘fix up’ the plugin config within the handler functions:

local function log(premature, conf, message)
  [...]
  if conf.host == "from-environment" and ENV_DD_AGENT_HOST then
    conf.host = ENV_DD_AGENT_HOST
  end

This appeared to work for me and it probably makes sense to upstream similar logic into the real datadog plugin. The current plugin is effectively incompatible with a normal Datadog daemonset installation.

Other threads I’ve found: