Skip to content

Add metrics/observability support for AsyncAppenderBase#1006

Open
guizmaii wants to merge 8 commits intoqos-ch:masterfrom
guizmaii:async-appender-metrics
Open

Add metrics/observability support for AsyncAppenderBase#1006
guizmaii wants to merge 8 commits intoqos-ch:masterfrom
guizmaii:async-appender-metrics

Conversation

@guizmaii
Copy link

@guizmaii guizmaii commented Jan 27, 2026

Summary

This PR adds observability/metrics support for the AsyncAppenderBase class, addressing the request in issue #754.

New public methods:

  • getTotalAppendedCount() - Returns the total number of events submitted to append()
  • getDiscardedByThresholdCount() - Returns events discarded because the queue was nearly full and the event was deemed discardable
  • getDiscardedByQueueFullCount() - Returns events discarded when the queue was completely full (neverBlock=true mode)
  • getTotalDiscardedCount() - Returns the sum of all discarded events
  • getDispatchedCount() - Returns the number of events successfully dispatched to the attached appender
  • getFailedDispatchCount() - Returns the number of events that failed during dispatch (uncaught exceptions)
  • resetMetrics() - Resets all counters to zero

Design decisions:

  • Simple approach: Following @ceki's guidance in the issue discussion, this keeps things simple and doesn't add explicit support for metrics frameworks (Micrometer, Prometheus, etc.). Users can poll these methods and integrate with their monitoring system of choice.
  • High-performance counters: Uses LongAdder instead of AtomicLong for better performance under high contention from multiple threads.
  • Batch counting: The worker thread uses local counters and batch updates to minimize atomic operations.
  • Non-invasive: The core logic remains unchanged; only counters are incremented at appropriate points.

Use cases:

These metrics enable users to:

  • Monitor async appender queue depth and throughput
  • Detect backpressure issues when events are being discarded
  • Alert on excessive event loss
  • Track successful vs failed dispatches
  • Integrate with monitoring dashboards

Test plan

  • Added tests for getTotalAppendedCount()
  • Added tests for getDiscardedByThresholdCount()
  • Added tests for getDiscardedByQueueFullCount()
  • Added tests for getDispatchedCount()
  • Added tests for getFailedDispatchCount()
  • Added tests for resetMetrics()
  • Verified existing tests still pass
  • All tests pass: mvn test -pl logback-core -Dtest=AsyncAppenderBaseTest

Closes #754

@guizmaii guizmaii force-pushed the async-appender-metrics branch from 05712ff to 546c703 Compare January 27, 2026 06:52
@guizmaii guizmaii marked this pull request as draft January 27, 2026 06:52
@guizmaii guizmaii force-pushed the async-appender-metrics branch 3 times, most recently from 147895c to 0518f23 Compare January 27, 2026 07:02
Signed-off-by: Jules Ivanic <jules.ivanic@gmail.com>
@guizmaii guizmaii force-pushed the async-appender-metrics branch from 0518f23 to 0cd1af8 Compare January 27, 2026 07:03
@guizmaii guizmaii marked this pull request as ready for review January 27, 2026 07:03
Signed-off-by: Jules Ivanic <jules.ivanic@gmail.com>
Signed-off-by: Jules Ivanic <jules.ivanic@gmail.com>
@guizmaii guizmaii marked this pull request as draft January 27, 2026 07:27
Signed-off-by: Jules Ivanic <jules.ivanic@gmail.com>
Signed-off-by: Jules Ivanic <jules.ivanic@gmail.com>
@guizmaii guizmaii force-pushed the async-appender-metrics branch from cf65ef3 to 5b29efe Compare January 27, 2026 07:29
Signed-off-by: Jules Ivanic <jules.ivanic@gmail.com>
Signed-off-by: Jules Ivanic <jules.ivanic@gmail.com>
Signed-off-by: Jules Ivanic <jules.ivanic@gmail.com>
@guizmaii guizmaii marked this pull request as ready for review January 27, 2026 07:57
@guizmaii guizmaii marked this pull request as draft January 27, 2026 08:33
@guizmaii guizmaii marked this pull request as ready for review January 27, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Observability of async logging queue

1 participant