pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

[improve][fn] Flush logs to log-topic periodically for Go Pulsar functions

Open DavidRayner opened this issue 1 year ago • 0 comments

Motivation

Currently log messages for Go pulsar functions are only sent out to the log topic when addLogTopicHandler is called, which only happens when a Pulsar message is received (just before it is processed).

Therefore, if a function is not processing any data, any log statements from healthchecks etc will not be sent to the log topic. Also, any log statements that occur when processing a message will only appear when another message is processed.

Modifications

After logAppender.Start is called, a new method setupLogHandlerTicker is called to start a ticker in a goroutine.
The ticker calls flushLogsToTopicHandler (previously named addLogTopicHandler) every 100ms.

The logAppender.Stop method has been updated to stop the ticker after one final flush of logs to the log-topic.

A mutex has been added to flushLogsToTopicHandler to ensure that the ticker does not attempt to flush log statements to the log-topic whilst they are being flushed when a Pulsar message is received.

Verifying this change

  • [ ] Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Unit tests have been added to test that the new ticker will flush logs out to the log-topic.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • [ ] Dependencies (add or upgrade a dependency)
  • [ ] The public API
  • [ ] The schema
  • [ ] The default values of configurations
  • [ ] The threading model
  • [ ] The binary protocol
  • [ ] The REST endpoints
  • [ ] The admin CLI options
  • [ ] The metrics
  • [ ] Anything that affects deployment

Documentation

  • [ ] doc
  • [ ] doc-required
  • [x] doc-not-needed
  • [ ] doc-complete

Matching PR in forked repository

PR in forked repository: https://github.com/DavidRayner/pulsar/pull/2

DavidRayner avatar Apr 16 '24 12:04 DavidRayner