-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Unregister meters whose weak reference has been broken #1452
Comments
Thank you for the detail explanation of the use-case you have and the issue you are facing. As a (possibly long-term) workaround, have you tried using the |
Hello @shakuzen
This works as expected, I see (e.g., in Atlas), that Let's say the last value published for
Problem is: all values I see for u now are offset by 10! (10 the last value published by From what I can tell, Micrometer removes If the last value read by |
I just stumbled upon a similar issue (related to #2642). We have Caffeine For cases where the application registers a gauge or counter, I guess it would be possible to always and proactively remove any offending remainings in the How would this even be solved? Would the |
If someone can provide guidance on what the best way of solving this would be, I'd be willing to spend some time on getting this fixed. |
Sorry for the incredibly late response. @mprimi that looks like a bug in our AtlasMeterRegistry (assuming that's what you're using) which should probably be removing from the underlying AtlasRegistry when removed from Micrometer's registry. Would you open a separate issue for that please? |
Only |
Yep, that's true, but even if the backing object is garbage collected, the reference to the actual gauge/function is still kept by Micrometer, which means that a new gauge/function with the same name and set of tags can't be registered.
👍 Do you have any pointers where this "registries could check" part could/would be done? |
Other than in each registry's implementation of the |
Ok 👍 A little bit related but still a side note. In the specific |
Maybe, but we don't do that anywhere currently. As I mentioned in #2719 (comment) that leads to another problem of things effectively resetting that shouldn't reset while an application is running. In practice, it might not be a problem, though. I suppose it doesn't matter for registries that publish step-normalized values, and for registries that report cumulative values, it is expected the metrics backend knows how to handle resets because it will happen when an application restarts. |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
The issue is still valid. |
I'm like to report something that is slightly counter-intuitive. What i am suggesting is either a change of behavior or explicit documentation on the current one.
The behavior:
Keeping a useless object in memory seems not great.
But there's actually an even more subtle consequence (which I find undesirable).
Here's an example use case where this behavior can create counter-intuitive behavior.
I'm publishing a metric tagged with a username to track per-user resource utilization.
The number of active users is small, and I'd like to avoid publishing millions of zeros for all inactive users.
When a user is active, I register a gauge like so:
This gauge has a weak reference to
userMemoryAmount
, which is great.I keep an external strong reference to
userMemoryAmount
and update it.Later, when the user goes away, I will remove the strong reference to
userMemoryAmount
, and eventually this metric will stop publishing for this user, sinceuserMemoryAmount
is GC'd.So far so good. This is the behavior I want. The measured object goes away, the metric (eventually) goes away. 👍
Here's where I see a problem.
The same user comes back 2 days later.
I don't have an AtomicLong
userMemoryAmount
tracking that user, so i create a new one:Same code as above.
What i expect: a new gauge that references my newly created
userMemoryAmount
(the existing meter would also be acceptable, if its reference was still valid).What i get instead: the old gauge with a broken weak reference to the old
userMemoryAmount
. This is effectively garbage that will never collected.--
Maybe this behavior is by design and working exactly as expected, but once again i would like to call out that, to my understanding:
The API and/or documentation could be a bit more explicit about this behavior.
The text was updated successfully, but these errors were encountered: