Skip to content

libbeat: report queue filled.pct as 0 when the queue has no finite limit - #54652

Open
0xABCD01 wants to merge 1 commit into
elastic:mainfrom
0xABCD01:fix/54639-diskqueue-filled-pct-zero-max
Open

0xABCD01 wants to merge 1 commit into
elastic:mainfrom
0xABCD01:fix/54639-diskqueue-filled-pct-zero-max

Conversation

@0xABCD01

Copy link
Copy Markdown

Proposed commit message

The disk queue treats max_size: 0 as unlimited: it reports MaxBytes(0) to the queue observer and never sets a maximum event count. queueObserver.updateFilledPct() in libbeat/publisher/queue/monitoring.go guarded the byte division with maxBytes > 0 but then divided by the event maximum unconditionally, so queue.filled.pct became +Inf while events were queued and NaN when the queue was empty. The non-finite value made the monitoring reporter fail with "json: unsupported value: +Inf" and broke the /stats endpoint, as reported in #54639.

Fix: only compute the percentage when a finite byte or event limit exists. When the queue is unbounded, report 0. The filled.pct gauge is initialized to 0, and an unbounded queue can never fill up. The finite-limit paths are unchanged.

Tests: libbeat/publisher/queue/monitoring_test.go is new (the package previously had no test files). Its two unlimited-queue cases fail on the old code with exactly +Inf and NaN, and pass with the fix. A third case pins the finite byte and event percentages (0.25 and 0.5) so the existing behavior cannot drift. go test ./libbeat/publisher/queue/... passes (queue, diskqueue, memqueue, slabqueue).

A changelog fragment (kind: bug-fix, component libbeat) is included in this PR.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (no documentation describes this metric's behavior for unlimited queues; the fix restores the documented /stats output)
  • I have made corresponding change to the default configuration files (no configuration change; max_size: 0 keeps its existing meaning of unlimited)
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability. (Unit tests only; stress testing is not relevant to this observer calculation.)
  • I have added an entry in ./changelog/fragments using the changelog tool.

Disruptive User Impact

None. The only change is the value of queue.filled.pct for queues configured without a finite limit, where it previously held +Inf or NaN and broke monitoring output.

How to test this PR locally

go test ./libbeat/publisher/queue/...

To reproduce the original failure, run the two unlimited-queue tests in libbeat/publisher/queue/monitoring_test.go against the code without the monitoring.go change: they fail with +Inf and NaN. End to end: run Filebeat with a disk queue configured with max_size: 0, publish events, and request /stats; before the fix the monitoring reporter logs "json: unsupported value: +Inf", after the fix queue.filled.pct reports 0.

Related issues

Use cases

Users running Filebeat with an unlimited disk queue (max_size: 0, a valid configuration) get a working /stats endpoint and monitoring output again; queue.filled.pct reports 0 instead of a non-finite value.

Logs

New tests against the old code:

--- FAIL: TestQueueObserverFilledPctUnlimitedQueue — filled.pct must not be infinite, got +Inf
--- FAIL: TestQueueObserverFilledPctUnlimitedEmptyQueue — got NaN
--- PASS: TestQueueObserverFilledPctFiniteLimits

With the fix, all three tests pass and go test ./libbeat/publisher/queue/... is green across queue, diskqueue, memqueue, and slabqueue.

@0xABCD01
0xABCD01 requested a review from a team as a code owner November 12, 2026 09:42
@0xABCD01
0xABCD01 requested a review from fbac November 12, 2026 09:42
@botelastic botelastic Bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 12, 2026
@cla-checker-service

cla-checker-service Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

❌ Author of the following commits did not sign a Contributor Agreement:
4704000

Please, read and sign the above mentioned agreement if you want to contribute to this project

@botelastic

botelastic Bot commented Nov 12, 2026

Copy link
Copy Markdown

This pull request doesn't have a Team:<team> label.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@mergify

mergify Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @0xABCD01? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@mergify

mergify Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

@cmacknz
cmacknz requested a review from leehinman November 12, 2026 21:53

@leehinman leehinman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit on the changelog, otherwise everything looks good.


component: libbeat

# issue: https://github.com/elastic/beats/issues/54639

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the right issue, can you uncomment?

The disk queue treats max_size: 0 as unlimited: it reports MaxBytes(0) and never sets a maximum event count. updateFilledPct divided by the zero maximum anyway, so queue.filled.pct became +Inf while events were queued and NaN when the queue was empty. The non-finite value made the monitoring reporter fail with "json: unsupported value: +Inf" and broke the /stats endpoint.

Only compute the percentage when a finite byte or event limit exists, and report 0 when the queue is unbounded, since it can never fill up.

Assisted-By: Muse
@0xABCD01
0xABCD01 force-pushed the fix/54639-diskqueue-filled-pct-zero-max branch from 17f125b to 4704000 Compare November 14, 2026 07:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs_team Indicates that the issue/PR needs a Team:* label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filebeat disk queue with max_size: 0 causes monitoring metrics and /stats to fail

2 participants