liveBook · Manning

Cleanup callback

As explained in Logs and Telemetry

A cleanup callback is a framework-invoked function that releases resources associated with a completed processing cycle.

A cleanup callback is a Fluent Bit framework hook that releases resources associated with one completed input-callback cycle. It retrieves contextual resource values, performs cleanup, and returns status to the core. section 10.6.2

Implement cleanup around the callback’s operational context:

  • Release resources specific to the current callback cycle rather than retaining uncontrolled connection data. section 10.6.2
  • Close the source connection when its type requires it, especially when an empty query could leave the connection waiting. section 10.6.2
  • Pass cleanup errors to the callback, log them, and report failure to the Fluent Bit core. section 10.6.2
  • Use the framework grace period to allow resources to close during shutdown. section 10.6.2
Listing 10.4 Implementation of the cleanup callback function: in.go
//export FLBPluginInputCleanupCallback
func FLBPluginInputCleanupCallback(data unsafe.Pointer) int {
  // err := releaseResources(data)     #1
  // if err != nil {
  //  log.Printf("%s had an error during cleanup, error is %s\n",
  //      Plugin_Name, err)
  //  return input.FLB_ERROR    #2
  //}
  return input.FLB_OK          #2
}

The Go implementation shows the cleanup callback’s framework-facing signature and an OK return when no resource-release error is reported. section 10.6.2

How Logs and Telemetry covers it

How deep it goes
Explains contextual release, conditional connection closure, error propagation, and grace-period shutdown, but leaves release code commented in the example.
Examples
Uses a database-reading input plugin and a Go cleanup callback that returns FLB_OK.
What it assumes
Assumes familiarity with Fluent Bit input-plugin callbacks and contextual values while keeping connection-management details deliberately simple.
What you can do after
Build it from scratch by implementing resource release, error reporting, and callback status handling in a Go input plugin.
How it connects
Connects cleanup callbacks with input callbacks, input plugins, source connections, and Fluent Bit core status handling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Logs and Telemetry. The section links point to the parts of the book it draws on.