Skip to content

Conversation

@andsel
Copy link
Contributor

@andsel andsel commented Sep 11, 2025

Release notes

Implements current batch event count and byte size metrics.

What does this PR do?

Introduce a new gauge metric to collect list of values, used a a couple, the first element count of events in the batch and the second one is the estimated memory occupation of the batch.
This list is later grabbed in the API layer to populate the two current values for event_count and batch_size.

Why is it important/What is the impact to the user?

Exposes the current batch size in terms of events and estimated memory consumption.

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 (and/or docker env variables)
  • I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • [ ]

How to test this PR locally

Start Logstash with pipeline.batch.metrics.sampling_mode set to full running an HTTP input pipeline, load it with wrk and verify that the metric API pipelines.main.batch.event_count.current and pipelines.main.batch.byte_size.current goes down to 0 when wrk is interrupted and gets a value other than 0 when the load wrk resumes.

  1. Create a file named input_sample.txt with some content
  2. Create a script send_file.lua as
wrk.method = "POST"
local f = io.open("input_sample.txt", "r")
wrk.body   = f:read("*all")%
  1. enable the metric in config/logstash.yml:
pipeline.batch.metrics.sampling_mode: full
  1. run Logstash with pipeline:
input {
  http {
    response_headers => {"Content-Type" => "application/json"}
    ecs_compatibility => disabled
  }
}
output {
  sink {}
}
  1. open a shell to verify the metrics on Logstash:
while true; do curl http://localhost:9600/_node/stats | jq .pipelines.main.batch; sleep 1; clear; done
  1. start and stop wrk, checking the metrics:
wrk --threads 4 --connections 12 -d10m -s send_file.lua --latency http://localhost:8080

Related issues

@github-actions
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

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

@mergify
Copy link
Contributor

mergify bot commented Sep 11, 2025

This pull request does not have a backport label. Could you fix it @andsel? 🙏
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.
  • If no backport is necessary, please add the backport-skip label

@andsel andsel force-pushed the feature/current_metric_byte_size_event_count branch from 2e3ea64 to 00a395b Compare September 23, 2025 14:43
@andsel andsel self-assigned this Sep 24, 2025
@andsel andsel changed the title Feature/current metric byte size event count Measure current batch byte size and event count Sep 24, 2025
@andsel andsel marked this pull request as ready for review September 24, 2025 09:26
@elastic-sonarqube
Copy link

@elasticmachine
Copy link
Collaborator

@andsel andsel requested a review from jsvd September 25, 2025 15:19
Copy link
Member

@jsvd jsvd left a comment

Choose a reason for hiding this comment

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

LGTM

When testing I noticed that the branch this is built on has a custom config/logstash.yml with an uncommented sample_mode setting https://github.com/andsel/logstash/blob/feature/current_metric_byte_size_event_count/config/logstash.yml#L57, so be careful in merging to ensure this change doesn't carry to main branch.

@andsel
Copy link
Contributor Author

andsel commented Sep 26, 2025

That flew into the #18000, was fixed in #18204. Thanks for noting :-)

@andsel andsel merged commit fdeb6a0 into elastic:main Sep 26, 2025
12 checks passed
v1v pushed a commit that referenced this pull request Oct 21, 2025
Exposes the current batch size in terms of events and estimated memory consumption.

Introduce a new gauge metric to collect list of values, used a a couple, the first element count of events in the batch and the second one is the estimated memory occupation of the batch.
This list is later grabbed in the API layer to populate the two current values for `event_count` and `batch_size`.

Co-authored-by: João Duarte <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implements current value for batch's byte size and event count average metric

3 participants