Skip to content

metrics: add support for user-defined metrics#18218

Merged
yaauie merged 2 commits intoelastic:mainfrom
yaauie:metrics-user-defined
Sep 29, 2025
Merged

metrics: add support for user-defined metrics#18218
yaauie merged 2 commits intoelastic:mainfrom
yaauie:metrics-user-defined

Conversation

@yaauie
Copy link
Member

@yaauie yaauie commented Sep 25, 2025

Release notes

[rn: skip]

What does this PR do?

Provides a way for registering non-standard metrics, without needing to wire them through publicly.

It does so by introducing an API UserMetric<VALUE_TYPE> marked as Logstash-internal, a companion UserMetric.Factory<USER_METRIC> to encapsulate the logic for its type and a null implementation, and introducing NamespacedMetric#register(String metric, UserMetric.Factory<USER_METRIC> userMetricFactory).

Together, these methods and the wiring through to the metric collector allow anything with an api.NamespacedMetric to provide its own metric implementation.

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

This is necessary ground-work for #18107 which will add ratio and relative-spend metrics from within the Logstash code-base.

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

Related issues

Use cases

Screenshots

Logs

@yaauie yaauie requested a review from andsel September 25, 2025 20:11
@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 25, 2025

This pull request does not have a backport label. Could you fix it @yaauie? 🙏
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
@yaauie yaauie force-pushed the metrics-user-defined branch from 1014806 to b151f4c Compare September 25, 2025 21:06
@yaauie yaauie mentioned this pull request Sep 26, 2025
4 tasks
Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

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

LGTM, left a suggestion to make more explicit the happy path when returning the metric in fromRubyBase.

…erMetric.java

Co-authored-by: Andrea Selva <selva.andre@gmail.com>
@elasticmachine
Copy link

💚 Build Succeeded

History

@yaauie yaauie merged commit 75eca84 into elastic:main Sep 29, 2025
12 checks passed
v1v pushed a commit that referenced this pull request Oct 21, 2025
* metrics: add support for user-defined metrics

* Update logstash-core/src/main/java/org/logstash/instrument/metrics/UserMetric.java

Co-authored-by: Andrea Selva <selva.andre@gmail.com>

---------

Co-authored-by: Andrea Selva <selva.andre@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants