Repository navigation
Closing async instrument removes it from registry - #148411
mateuszrzeszutek merged 8 commits into
Conversation
This allows the users of the async instruments to close them and stop them from recording measurements when the underlying conditions change (e.g. master-specific metrics can be stopped when a new master is elected). This way, the async instruments can be GC'd, and won't block the measured object from being GC'd as well.
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
…ent-removes-it-from-the-registry
| public void close() { | ||
| // deregister this instrument first and close the underlying one second: this avoids the setProvider() method being called in the | ||
| // meantime and creating a new OTel instrument that'd leak out | ||
| deregisterFunc.accept(this); |
There was a problem hiding this comment.
Nit: close() in the four adapters has no closed guard, so a double-close runs deregisterFunc getInstrument().close() twice. This is benign today because these calls here are idempotent, but a closed flag in AbstractInstrument would future-proof that idempotency. Perhaps I'm over-thinking this though - I'll leave it up to your discretion.
There was a problem hiding this comment.
I've thought about this, but ultimately decided not to do that -- as you're saying, the current close() logic is idempotent, the probability that someone calls close() more than once is somewhat small, and it's simpler to keep it as it is (and keep the wrapper over OTel reasonably thin). We can always add it later, if/when there's something that'll require that.
JVerwolf
left a comment
There was a problem hiding this comment.
Overall this looks good to me. I've left a few comments/thoughts, but they can be addressed at your discretion.
|
Hi @mateuszrzeszutek, I've created a changelog YAML for you. |
🔍 Preview links for changed docs⏳ Building and deploying preview... View progress This comment will be updated with preview links when the build is complete. |
ℹ️ Important: Docs version tagging👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version. We use applies_to tags to mark version-specific features and changes. Expand for a quick overviewWhen to use applies_to tags:✅ At the page level to indicate which products/deployments the content applies to (mandatory) What NOT to do:❌ Don't remove or replace information that applies to an older version 🤔 Need help?
|
* Closing async instrument removes it from registry This allows the users of the async instruments to close them and stop them from recording measurements when the underlying conditions change (e.g. master-specific metrics can be stopped when a new master is elected). This way, the async instruments can be GC'd, and won't block the measured object from being GC'd as well. * Apply code review comments * Extract common async logic to a base class * Update docs/changelog/148411.yaml
This allows the users of the async instruments to close them and stop them from recording measurements when the underlying conditions change (e.g. master-specific metrics can be stopped when a new master is elected). This way, the async instruments can be GC'd, and won't block the measured object from being GC'd as well.