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

Gauges with unknown tags during compile time #630

Closed
Necropaw opened this issue May 29, 2018 · 4 comments
Closed

Gauges with unknown tags during compile time #630

Necropaw opened this issue May 29, 2018 · 4 comments
Labels
duplicate A duplicate of another issue

Comments

@Necropaw
Copy link

Necropaw commented May 29, 2018

Hi,

I am currently migrating an application from Spring Boot 1.5.x to 2.x and I am stuck on Micrometer with gauges and tags.

The application uses gauges to measure running processes for a team. The value can increase and decrease over time and also the teams are loaded from a database and can change (add & delete), e.g.:

app_gauge_running_processes{team_label="a"} 2.0
app_gauge_running_processes{team_label="b"} 1.0
...
app_gauge_running_processes{team_label="z"} 9.0

Can you point me in the direction on how to achieve this with Micrometer?

Afaik it is possible to register a gauge with tag key/values, if they are known beforehand, but this is not the case here.
It is possible to search for a gauge, but the value can not be changed - only read.

The only solution I currently see is to implement my own registry for gauges, search in this registry by name and tags for an AtomicLong and change the value. This can not be right solution.

@Necropaw Necropaw changed the title Gauge with unknown tags during compile time Gauges with unknown tags during compile time May 29, 2018
@pjfanning
Copy link
Contributor

You can register separate gauges, eg
app_gauge_running_processes with Tag.of("team_label", "a"),
app_gauge_running_processes with Tag.of("team_label", "b"),
etc.

I have an application where I maintain my own map of registered gauges (but there might be a better way to this).

This is in scala but it should easy enough to do in Java too.

private case class MeterKey(name: String, tags: Iterable[Tag])
val map = TrieMap[MeterKey, GaugeWrapper]()

@Necropaw
Copy link
Author

I have an application where I maintain my own map of registered gauges (but there might be a better way to this).

Also using a map, but this is a memory leak waiting to happen. As a map can contain hard and unused references for deleted teams.

As it is, micrometer has no other way than to introduce a memory leak for handling tags in Gauges.

@pjfanning
Copy link
Contributor

@Necropaw you could use soft/weak references in the map (something like a WeakHashMap)

@jkschneider jkschneider added this to the 1.1.0 milestone Jul 17, 2018
@jkschneider
Copy link
Contributor

Trying to roll all the "multi-gauge" issues into one. Closing in favor of #807.

@jkschneider jkschneider added the duplicate A duplicate of another issue label Sep 6, 2018
@jkschneider jkschneider removed this from the 1.1.0-rc.1 milestone Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants