mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-07-31 07:24:31 +00:00
🐛 fix closed async backlog accounting
This commit is contained in:
@@ -36,6 +36,7 @@ Detailed rules explaining key parameters and behaviors
|
|||||||
- The counter increases when overflow policy discards records.
|
- The counter increases when overflow policy discards records.
|
||||||
- The counter can also increase when `close(clear=true)` or `shutdown(clear=true)` abandons queued records.
|
- The counter can also increase when `close(clear=true)` or `shutdown(clear=true)` abandons queued records.
|
||||||
- It can also increase when shutdown fallback logic converts remaining pending records into dropped records during a clear-close path.
|
- It can also increase when shutdown fallback logic converts remaining pending records into dropped records during a clear-close path.
|
||||||
|
- Later log attempts against an already closed queue do not add to this counter by themselves.
|
||||||
- This is a cumulative counter for the lifetime of the logger value.
|
- This is a cumulative counter for the lifetime of the logger value.
|
||||||
- Use this helper when you need a focused loss metric rather than a full `state()` snapshot.
|
- Use this helper when you need a focused loss metric rather than a full `state()` snapshot.
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ Detailed rules explaining key parameters and behaviors
|
|||||||
- Context fields, patch logic, and filter logic are applied before enqueue.
|
- Context fields, patch logic, and filter logic are applied before enqueue.
|
||||||
- If timestamping is enabled, `@env.now()` is captured before the record enters the queue.
|
- If timestamping is enabled, `@env.now()` is captured before the record enters the queue.
|
||||||
- Overflow behavior depends on the configured `AsyncOverflowPolicy`.
|
- Overflow behavior depends on the configured `AsyncOverflowPolicy`.
|
||||||
|
- Closed-on-log behavior is runtime-dependent: compatibility runtimes short-circuit before enqueue work, while native-worker runtimes may still reach the queue operations and then treat a closed queue as a non-accepted write.
|
||||||
|
|
||||||
### How to Use
|
### How to Use
|
||||||
|
|
||||||
@@ -82,6 +83,8 @@ e.g.:
|
|||||||
|
|
||||||
- If the logger is closed or overflow policy rejects the record, enqueue may not proceed as a normal accepted write.
|
- If the logger is closed or overflow policy rejects the record, enqueue may not proceed as a normal accepted write.
|
||||||
|
|
||||||
|
- A closed queue does not count as a newly accepted pending record.
|
||||||
|
|
||||||
### Notes
|
### Notes
|
||||||
|
|
||||||
1. Use this API when the call site needs full control instead of a fixed severity helper.
|
1. Use this API when the call site needs full control instead of a fixed severity helper.
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ Detailed rules explaining key parameters and behaviors
|
|||||||
- The count increases when records are accepted into the queue.
|
- The count increases when records are accepted into the queue.
|
||||||
- The count decreases as the worker drains records.
|
- The count decreases as the worker drains records.
|
||||||
- The count is also reset to `0` when queued records are abandoned through clear-close paths such as `close(clear=true)`.
|
- The count is also reset to `0` when queued records are abandoned through clear-close paths such as `close(clear=true)`.
|
||||||
|
- Log attempts against a closed queue do not create new pending backlog.
|
||||||
- This is a point-in-time metric and may change immediately after it is read.
|
- This is a point-in-time metric and may change immediately after it is read.
|
||||||
- Use this helper when a single backlog number is enough and a full `state()` snapshot is unnecessary.
|
- Use this helper when a single backlog number is enough and a full `state()` snapshot is unnecessary.
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,29 @@ async test "shutdown clear closes without worker startup" {
|
|||||||
inspect(logger.dropped_count(), content="1")
|
inspect(logger.dropped_count(), content="1")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async test "closed blocking logger does not add pending count on later log attempts" {
|
||||||
|
let logger = async_logger(
|
||||||
|
@bitlogger.callback_sink(fn(_) {
|
||||||
|
|
||||||
|
}),
|
||||||
|
config=AsyncLoggerConfig::new(
|
||||||
|
max_pending=2,
|
||||||
|
overflow=AsyncOverflowPolicy::Blocking,
|
||||||
|
),
|
||||||
|
min_level=@bitlogger.Level::Info,
|
||||||
|
target="async.closed.blocking",
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info("one")
|
||||||
|
logger.close(clear=true)
|
||||||
|
inspect(logger.pending_count(), content="0")
|
||||||
|
inspect(logger.dropped_count(), content="1")
|
||||||
|
|
||||||
|
logger.info("late")
|
||||||
|
inspect(logger.pending_count(), content="0")
|
||||||
|
inspect(logger.dropped_count(), content="1")
|
||||||
|
}
|
||||||
|
|
||||||
test "async logger config stringify roundtrips stable fields" {
|
test "async logger config stringify roundtrips stable fields" {
|
||||||
let text = stringify_async_logger_config(
|
let text = stringify_async_logger_config(
|
||||||
AsyncLoggerConfig::new(
|
AsyncLoggerConfig::new(
|
||||||
|
|||||||
@@ -254,11 +254,16 @@ pub async fn[S] AsyncLogger::log(
|
|||||||
} else {
|
} else {
|
||||||
match self.overflow {
|
match self.overflow {
|
||||||
AsyncOverflowPolicy::Blocking => {
|
AsyncOverflowPolicy::Blocking => {
|
||||||
self.queue.put(rec) catch {
|
let accepted = (async fn() -> Bool raise {
|
||||||
err if err is AsyncLoggerClosed => ()
|
self.queue.put(rec)
|
||||||
|
true
|
||||||
|
})() catch {
|
||||||
|
err if err is AsyncLoggerClosed => false
|
||||||
err => raise err
|
err => raise err
|
||||||
}
|
}
|
||||||
self.pending_count.val += 1
|
if accepted {
|
||||||
|
self.pending_count.val += 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AsyncOverflowPolicy::DropOldest | AsyncOverflowPolicy::DropNewest => {
|
AsyncOverflowPolicy::DropOldest | AsyncOverflowPolicy::DropNewest => {
|
||||||
self.dropped_count.val += 1
|
self.dropped_count.val += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user