kong icon indicating copy to clipboard operation
kong copied to clipboard

chore(zipkin) Add zipkin prefix to timer logs

Open dcarley opened this issue 2 years ago • 3 comments

Summary

These run on a timer so they don't get the namespace automatically appended to the log line which makes it hard to determine which plugin they come from:

[error] 1099#0: *436751 [kong] handler.lua:102 reporter flush failed to request: operation timed out, context: ngx.timer, client: 172.17.0.1, server: 0.0.0.0:8443

I've tried looking for a way to solve this generically that would benefit other plugins like rate-limiting but can't see a way to set the logger or get access to the plugin name when the timer is running.

I've omitted the square brackets from zipkin to make it clearer that it's not coming from the automatic namespace formatting.

Full changelog

  • feat(zipkin) Add zipkin prefix to timer logs

Issue reference

N/A

Other notes

I'm open to suggestions about how this could be solved generically in a way that would benefit all plugins.

This PR depends on the tests from #8735. I can't see a way to change the base branch, so it will need rebasing after that PR is merged.

dcarley avatar May 09 '22 14:05 dcarley

The changes should go to chore instead of feat, and I think this small change is unnecessary to be included in the changelog.

mayocream avatar May 26 '22 02:05 mayocream

Sorry for the delay. I've rebased against master, changed the commit to chore, and removed the CHANGELOG entry.

dcarley avatar Jul 04 '22 15:07 dcarley

Shouldn't we be fixing the underlying problem with kong.log to also provide the proper namespace when in a timer context?

@kikito any opinions? iirc you were involved when kong.log was first implemented.

Tieske avatar Jul 05 '22 09:07 Tieske

Shouldn't we be fixing the underlying problem with kong.log to also provide the proper namespace when in a timer context?

I'd love to, but can't see a way to set the logger or get access to the plugin name when the timer is running. The only option I can think of is to provide a wrapper over ngx.timer.at that sets the logger, but even then there's no guarantee that every plugin will use it. Any other ideas?

dcarley avatar Aug 19 '22 14:08 dcarley

@ADD-SP is this something we can fix with the timer-ng lib?

Tieske avatar Aug 31 '22 07:08 Tieske

The prefix is lost because our plugins iterator sets a custom timer on each phase of a plugin iterator, but it gets lost on timers. I believe this is a general issue. For now we could get over that by the logger inside the reporter:

local function get_reporter(conf)
  if reporter_cache[conf] == nil then
    reporter_cache[conf] = new_zipkin_reporter(conf.http_endpoint,
                                               conf.default_service_name,
                                               conf.local_service_name,
                                               conf.connect_timeout,
                                               conf.send_timeout,
                                               conf.read_timeout,
                                               kong.log)
  end
  return reporter_cache[conf]
end

And using a method like reporter.logger.log instead of kong.log

kikito avatar Nov 08 '22 10:11 kikito

Solved by #9874

mayocream avatar Dec 05 '22 07:12 mayocream

Thanks!

dcarley avatar Dec 05 '22 10:12 dcarley