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

Metrics not collected after ExecutorService recreation #5367

Merged
merged 8 commits into from
Aug 28, 2024

Conversation

ajax-surovskyi-y
Copy link
Contributor

@shakuzen
Copy link
Member

shakuzen commented Aug 9, 2024

Thank you for the pull request. Could you take a look at the test failures?

@ajax-surovskyi-y
Copy link
Contributor Author

Thank you for the pull request. Could you take a look at the test failures?

Tests were fixed and PR is ready to review. Thank you

@ajax-surovskyi-y
Copy link
Contributor Author

@shakuzen kind reminder. Could you take a look this PR?

Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

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

ExecutorServiceMetrics and TimedExecutorService can be used together on the same ExecutorService (e.g. through one of the monitor method on ExecutorServiceMetrics) or separately through the available constructor(s) on each. It looks like right now the metrics will only be deregistered if the ExecutorService is wrapped with monitor. If ExecutorServiceMetrics are bound to an ExecutorService without wrapping and it is shutdown, there is no way to unregister the metrics still. Maybe we can leave this as existing behavior, but it did stand out to me as seeming a bit inconsistent. We could make ExecutorServiceMetrics Closeable and handle unregistering its metrics through that, but it would be up to users to call that close method when shutting down the executor. Thoughts?

@ajax-surovskyi-y
Copy link
Contributor Author

You're right about slight inconsistency. What threw me off was the comment above the class: "An {@link java.util.concurrent.ExecutorService} that is timed. This class is for internal use." But since it's public, users might have already relied on it. I would prefer not to require users to close ExecutorServiceMetrics, especially since it wouldn't work in my case where I pass the ExecutorService to the Akka framework and it handles the shutdown itself.

@shakuzen
Copy link
Member

Thanks for reminding me that TimedExecutorService is intended to be an internal class. Given that, the current PR makes more sense. It's still a little inconsistent because ExecutorServiceMetrics is not internal and it is valid to instrument an executor with the metrics it provides without wanting to time executions. I think for now we can wait until we get feedback from users that they want to unregister metrics in that case also before handling it.

@@ -61,6 +64,8 @@ public class ExecutorServiceMetrics implements MeterBinder {

private static final String DESCRIPTION_POOL_SIZE = "The current number of threads in the pool";

private final Set<Meter.Id> registeredMeterIds = ConcurrentHashMap.newKeySet();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to use the Concurrent variant here but it also shouldn't matter much if we do.

@shakuzen shakuzen merged commit 7777c8e into micrometer-metrics:main Aug 28, 2024
6 checks passed
shakuzen added a commit that referenced this pull request Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants