Skip to content

azure-eventhub v2: fix processingTime input metric#49864

Merged
zmoog merged 4 commits intoelastic:mainfrom
zmoog:fix-processing-time-metric
Apr 9, 2026
Merged

azure-eventhub v2: fix processingTime input metric#49864
zmoog merged 4 commits intoelastic:mainfrom
zmoog:fix-processing-time-metric

Conversation

@zmoog
Copy link
Copy Markdown
Contributor

@zmoog zmoog commented Apr 1, 2026

Proposed commit message

Move the processingTime metric update outside the loop in processReceivedEvents so it is recorded once per batch instead of once per event.

Before this change, processingStartTime was set once before the loop but processingTime.Update() was called on every iteration. Since time.Since(processingStartTime) grows with each iteration, the histogram received N cumulative samples (~T, ~2T, ~3T, ...) instead of a single sample with the total batch processing time. This inflated the histogram sample count and skewed percentiles.

Revives #40547 with an added regression test.

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
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

Run the new unit test:

go test ./x-pack/filebeat/input/azureeventhub/ -run TestProcessReceivedEventsUpdatesProcessingTimeOnce -v

The test sends 3 events through processReceivedEvents and asserts that processingTime is updated exactly once (after the loop), not 3 times (once per event).

Related issues

🤖 Generated with Claude Code

Move the processingTime metric update outside the loop in
processReceivedEvents so it is recorded once per batch instead of
once per event.

Previously, because processingStartTime was set before the loop and
never reset, each iteration recorded a cumulative duration:
~T, ~2T, ~3T, etc. This inflated the histogram sample count and
skewed percentiles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zmoog zmoog requested a review from a team as a code owner April 1, 2026 20:14
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 284e82c4-727b-404c-953f-4e8d4c380220

📥 Commits

Reviewing files that changed from the base of the PR and between e4d1bf5 and da1a488.

📒 Files selected for processing (1)
  • x-pack/filebeat/input/azureeventhub/v2_input_test.go

📝 Walkthrough

Walkthrough

The update moves the processingTime metric update from inside the per-event processing loop to run once after all events in a received batch are processed, changing the metric from per-event to per-batch updates. A unit test was added to assert that processing time is recorded exactly once per batch while processed message counts reflect all events. A changelog fragment documenting the bug fix for the azureeventhub input processing time metric was also added.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Comment @coderabbitai help to get the list of available commands and usage tips.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 1, 2026

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @zmoog? 🙏.
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.

Copy link
Copy Markdown
Contributor

@constanca-m constanca-m left a comment

Choose a reason for hiding this comment

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

Good find

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zmoog zmoog added the Team:obs-ds-hosted-services Label for the Observability Hosted Services team label Apr 9, 2026
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Apr 9, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services)

@zmoog zmoog added needs_team Indicates that the issue/PR needs a Team:* label bugfix labels Apr 9, 2026
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Apr 9, 2026
@zmoog zmoog added input:azure-eventhub backport-active-all Automated backport with mergify to all the active branches labels Apr 9, 2026
@zmoog zmoog merged commit 19da895 into elastic:main Apr 9, 2026
44 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

@Mergifyio backport 8.19 9.3 9.4

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 9, 2026

backport 8.19 9.3 9.4

✅ Backports have been created

Details

mergify bot pushed a commit that referenced this pull request Apr 9, 2026
* azure-eventhub v2: fix processingTime input metric

Move the processingTime metric update outside the loop in
processReceivedEvents so it is recorded once per batch instead of
once per event.

Previously, because processingStartTime was set before the loop and
never reset, each iteration recorded a cumulative duration:
~T, ~2T, ~3T, etc. This inflated the histogram sample count and
skewed percentiles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Update changelog

* Fix forbidigo lint: replace logp.NewLogger with logp.L() in tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Switch to logptest

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
(cherry picked from commit 19da895)
mergify bot pushed a commit that referenced this pull request Apr 9, 2026
* azure-eventhub v2: fix processingTime input metric

Move the processingTime metric update outside the loop in
processReceivedEvents so it is recorded once per batch instead of
once per event.

Previously, because processingStartTime was set before the loop and
never reset, each iteration recorded a cumulative duration:
~T, ~2T, ~3T, etc. This inflated the histogram sample count and
skewed percentiles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Update changelog

* Fix forbidigo lint: replace logp.NewLogger with logp.L() in tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Switch to logptest

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
(cherry picked from commit 19da895)
mergify bot pushed a commit that referenced this pull request Apr 9, 2026
* azure-eventhub v2: fix processingTime input metric

Move the processingTime metric update outside the loop in
processReceivedEvents so it is recorded once per batch instead of
once per event.

Previously, because processingStartTime was set before the loop and
never reset, each iteration recorded a cumulative duration:
~T, ~2T, ~3T, etc. This inflated the histogram sample count and
skewed percentiles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Update changelog

* Fix forbidigo lint: replace logp.NewLogger with logp.L() in tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Switch to logptest

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
(cherry picked from commit 19da895)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-all Automated backport with mergify to all the active branches bugfix input:azure-eventhub Team:obs-ds-hosted-services Label for the Observability Hosted Services team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants