Publicise the mbean traits
This way they could be gotten/invoked via the java ManagementFactory / MBeanServer.
I'd like to follow this up by investigating #3038 and I'm pretty sure this won't interfere there but I'm mentioning it here in case I'm wrong 😅
cc @mpilquist
Oh, btw this PR should be targeted to series/3.x. We can't make API changes in series/3.5.x.
Can we merge this with HEAD so we get the CI calming changes?
oh sorry about that! thanks @armanbilge <3
I think I've gotten everything publicised correctly but I still can't trigger it via an mbean proxy because of the hash that gets added to the bean name here https://github.com/typelevel/cats-effect/blob/8e38eda40915c2a0979c4730378b33e04c5fe2c4/core/jvm/src/main/scala/cats/effect/unsafe/IORuntimeCompanionPlatform.scala#L269
(I'm using the fiber snapshot as an example, but I believe all mbeans have a hash added to the name EDIT: for clarity, all cats-effect mbeans. Other mbeans I've looked at don't seem to follow this convention)
With that hash in place I still have to get the mbeans using a query like I did originally.
Maybe I'm just not familiar with mbeans (fact), but it's not clear to me why the hash is necessary? @armanbilge do you know? If it were removed then accessing the bean is a bit nicer:
def readFibersFromRuntimeNoHash: IO[String] = IO {
val fiberObjectName =
new ObjectName("cats.effect.unsafe.metrics:type=LiveFiberSnapshotTrigger")
val server = ManagementFactory.getPlatformMBeanServer
val fiberBean = JMX.newMBeanProxy(
server,
fiberObjectName,
classOf[LiveFiberSnapshotTriggerMBean]
)
fiberBean.liveFiberSnapshot().mkString
}
Or maybe I'm missing a better way to work with the mbeans?
Maybe I'm just not familiar with mbeans (fact), but it's not clear to me why the hash is necessary?
If I had to guess: in case there are two or more IORuntimes in the JVM? I guess the hash helps to make it unique, but it actually doesn't guarantee that. I wonder if instead we can use a global AtomicLong counter. That is guaranteed to be unique, and in the happy path (one global runtime) it will always be 0 which should be nice enough for easy access. WDYT?