Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Gauge registration at micromter-observation api #5477

Closed
JordiMartinezVicent opened this issue Sep 16, 2024 · 3 comments
Closed

Support Gauge registration at micromter-observation api #5477

JordiMartinezVicent opened this issue Sep 16, 2024 · 3 comments
Labels
question A user question, probably better suited for StackOverflow

Comments

@JordiMartinezVicent
Copy link

Please describe the feature request.
Create a generic api at micrometer-observation for registering Gauges

Rationale

We are developing a set of libraries on top of Spring Boot which use micrometer to create metrics and traces. As Spring Boot did, we load metrics and tracing auto-configurations or not depending if metrics and traces are at classpath. Now we are refactoring our libraries to use micrometer-observation generic api to unify both and get rid of these conditionals.

Having said that, we use at several points Gauge metrics, so the suggestion would be to have a generic api at micrometer-observation which would register a gauge. (Although I am not sure if it would have sense for tracing.

@jonatan-ivanov
Copy link
Member

This is an interesting question that we considered since the beginning even before the Observation API was just a proof of concept. Let me put a brain-dump here about the problem space, please bear with me. :)

The initial goal of the Observation API was not only unifying Metrics and Tracing APIs (though I think it can do that pretty well except the Gauge) but rather to give you a set of tools to instrument ("observe") that something happened in your application and runtime you can decide what you want to do with the data: record metrics, spans, logs, send http requests, write to a DB, emit sounds (I'm only halfway-joking), etc. The "something happened" part is crucial here, the Observation API is for events that are either instantaneous (or you don't care about their duration) or not and has a duration (that you care about). You can translate these pretty well to metrics (timer, counter), tracing (span, annotation), and other signals as well (see above) but the Gauge is a bit of an outlier form this perspective because nothing happens there, it is just a value that is changing without your interaction/knowledge and sometimes you look at the value and record it.
For example, you can "observe" things like an error or processing an http request using the Observation API but there is no event to observe for the CPU temperature being 42°C (Gauge).

Also, I feel like Micrometer already has a generic API for gauge-like values, it's the Gauge since Micrometer's Gauge API is independent from the configured metrics backend and I'm not sure gauge-like values have a use-case other than metrics.

That being said, you are not the first one who asked this question, and I came up with a simple proof of concept for such a component: ObservedValue, the problem with it that without having a use-case other than metrics, this is just copying and renaming the MeterBinder interface.

Please let us know if you have a use-case for gauge-like values other than recording metrics, in the meantime, I think these are your options:

  1. Use MeterBinder and Gauge, you can hide/abstract away Gauge registrations and you can also register other data pollers if any (or do some actions when the Gauge is pulled).
  2. You can reuse the code above, and create your own abstraction in your library but again without having another ObservedValueRegistrar, this is just copying and renaming the MeterBinder.
  3. You can also simplify the approach above with a single valueRegistrar(String name, Supplier<Double> valueSupplier, KeyValues lowCardinalityKeyValues) method somewhere that registers the Gauge but this is also another form of the MeterBinder.

What do you think?
Also, please let us know if you have a use-case for gauge-like values other than recording metrics.

@jonatan-ivanov jonatan-ivanov added waiting for feedback We need additional information before we can continue and removed waiting-for-triage labels Sep 16, 2024
@JordiMartinezVicent
Copy link
Author

I was thinking something like "give me the state of the application". But I guess it is the aim of the Gauge itself, and it does not occur to me any other "real world" example that would fit to it a part from metrics.

Thank you for the time spent!

@jonatan-ivanov
Copy link
Member

jonatan-ivanov commented Sep 18, 2024

I feel this might be also connected: #5112

You can use it for things like JvmInfoMetrics, where the value is always constant (1) but the tags are different. Once implemented not just MeterBinder can reuse it to register Meters (Gauges) but for example like Spring Boot's /info endpoint as well that provides the same info but it ~duplicates the implementation.

@jonatan-ivanov jonatan-ivanov closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2024
@jonatan-ivanov jonatan-ivanov added question A user question, probably better suited for StackOverflow and removed waiting for feedback We need additional information before we can continue labels Sep 18, 2024
@jonatan-ivanov jonatan-ivanov changed the title [observation] Support Gauge registration at micromter-observation api Support Gauge registration at micromter-observation api Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A user question, probably better suited for StackOverflow
Projects
None yet
Development

No branches or pull requests

2 participants