DataDog / kong-plugin-ddtrace

Datadog APM Plugin for Kong Gateway
Apache License 2.0
15 stars 7 forks source link

Construct endpoint in the plugin #19

Closed xpdable closed 8 months ago

xpdable commented 10 months ago

Similar with #15 , we are deploying kong with helm into EKS and the endpoint is dynamic. With the same usage of datadog-kong-plugin (https://docs.konghq.com/hub/kong-inc/datadog/), we fetch the ip and config the plugin as below:

env:
  KONG_DATADOG_AGENT_HOST:
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP
...
dblessConfig:
  config:
    _format_version: "2.1"
    plugins:
      - name: datadog
        config:
          host: "{vault://env/KONG_DATADOG_AGENT_HOST}"
          port: 8125
      - name: ddtrace
        config:
          service_name: kong-ddtrace
          agent_endpoint: "http://{vault://env/KONG_DATADOG_AGENT_HOST}:8126/v0.4/traces"
          environment: 'dev'

The datadog plugin works in this way. however the ddtrace plugin does not work. Please refer the error below:

2023/12/01 10:28:02 [error] 1277#0: *130 [kong] handler.lua:27 agent_writer error failed to request: [cosocket] DNS resolution failed: dns server error: 3 name error. Tried: ["(short)"{vault:(na) - cache-miss",""{vault.rdsdemo.svc.cluster.local:33 - cache-miss/querying/dns server error: 3 name error",""{vault.svc.cluster.local:33 - cache-miss/querying/dns server error: 3 name error",""{vault.cluster.local:33 - cache-miss/querying/dns server error: 3 name error",""{vault.eu-central-1.compute.internal:33 - cache-miss/querying/dns server error: 3 name error",""{vault:33 - cache-miss/querying/dns server error: 3 name error",""{vault.rdsdemo.svc.cluster.local:1 - cache-miss/querying/dns server error: 3 name error",""{vault.svc.cluster.local:1 - cache-miss/querying/dns server error: 3 name error",""{vault.cluster.local:1 - cache-miss/querying/dns server error: 3 name error",""{vault.eu-central-1.compute.internal:1 - cache-miss/querying/dns server error: 3 name error",""{vault:1 - cache-miss/querying/dns server error: 3 name error",""{vault.rdsdemo.svc.cluster.local:5 - cache-miss/querying/dns server error: 3 name error",""{vault.svc.cluster.local:5 - cache-miss/querying/dns server error: 3 name error",""{vault.cluster.local:5 - cache-miss/querying/dns server error: 3 name error",""{vault.eu-central-1.compute.internal:5 - cache-miss/querying/dns server error: 3 name error",""{vault:5 - cache-miss/querying/dns server error: 3 name error"], context: ngx.timer

Can you give some insight? Can ddtrace deal with it in the same way of datadog? Thanks

for example: ( split each part and construct endpoint in the plugin? )

      - name: ddtrace
        config:
          service_name: kong-ddtrace
          host: "{vault://env/KONG_DATADOG_AGENT_HOST}"
          port: :8126
          version: "v4"
          environment: 'dev'

Also workable that if endpoint parameter exists, drop all others i.e. host, port...

xpdable commented 10 months ago

I tested locally, it works. I will refactory the logic and make a PR.

schema.lua:

...
                { host = allow_referenceable(typedefs.ip({ default = "127.0.0.1" })) },
                { port = { type = "string", default = "none" } },
                { version = { type = "string", default = "none" } },
...

handler.lua:

...
local function get_agent_writer(conf)
    if agent_writer_cache[conf] == nil then
--     TODO: logic that tell if agent_endpoint set or host set.
        local host = conf.host
        local port = conf.port
        local version = conf.version
        conf.agent_endpoint = string.format("http://%s:%d/%s/traces", host, port, version)
...
dmehala commented 8 months ago

Hi @xpdable

Thank you for reporting this issue. I wanted to inform you that we recently merged the fix in https://github.com/DataDog/kong-plugin-ddtrace/pull/27. This solution should address the problem you raised, and it will be included in the upcoming release.