micrometer icon indicating copy to clipboard operation
micrometer copied to clipboard

OSGi enabled micrometer jars so that they can be deployed as OSGi bundles

Open jingsx opened this issue 2 years ago • 5 comments

Please describe the feature request. support micrometer libraries on osgi based java runtimes.

Rationale currently we are embedding the micrometer dependencies to the service bundles, which is increasing our stack size unnecessarily. additionally we are also repackaging the micrometer dependencies to a wrapper osgi bundles, and it does not always support all the scenario

jingsx avatar Apr 28 '22 12:04 jingsx

Thank you for raising the enhancement request. I think this is the first time we're having OSGI support requested. Is this something you would be able to contribute? I'm not very familiar with OSGI so I do not know the kind of changes we need to make to support it, but I'm open to supporting it as long as it isn't a burden for the majority of our users who seem to not be using OSGI (I assume based on the lack of this request until now).

If you do not have time to contribute this, that is also fine. We would probably wait for votes on this issue before it were prioritized.

shakuzen avatar May 06 '22 09:05 shakuzen

Yes, we can contribute the osgi packageing for micrometer jars. we are currently working on it, we can submit the same change for review.

jingsx avatar May 06 '22 10:05 jingsx

@jingsx Can I have a few clarifying questions? It was 10+ years ago that I built OSGi bundles so I'm not sure what has changed in the specs since then.

Is there anything else you need other than some OSGI-specific metadata in the manifest file? (BundleActivator?) Can shaded dependencies (check the statsd registry) generate problems? Is there a proper Gradle plugin to generate the OSGI-specific metadata?

jonatan-ivanov avatar May 06 '22 23:05 jonatan-ivanov

I raised a PR to address this: https://github.com/micrometer-metrics/micrometer/pull/3457

driessamyn avatar Oct 05 '22 17:10 driessamyn

@jingsx Can I have a few clarifying questions? It was 10+ years ago that I built OSGi bundles so I'm not sure what has changed in the specs since then.

I'm not the original poster of this, but raised a PR with a fix, so will try to answer some of these questions.

Is there anything else you need other than some OSGI-specific metadata in the manifest file? (BundleActivator?)

I don't think so. If Micrometer used ServiceLoader, then there would be an impact, for example, but I have validated the core and prometheus modules to work with just the OSGi metadata. So there isn't any overhead in maintaining the code, as it stands.

Can shaded dependencies (check the statsd registry) generate problems?

I don't think they do. The dependencies still get added to the JAR and are included in the Import-Package by default:

image

Is there a proper Gradle plugin to generate the OSGI-specific metadata?

Yes, the BND Tools include a Gradle plugin.

This is fairly unintrusive, and adding the OSGi metadata for Micrometer doesn't impact the code. I have only validated the Prometheus registry. I suspect not all registries will work in an OSGi framework as all transitive dependencies also need to have OSGi metadata.

driessamyn avatar Oct 10 '22 09:10 driessamyn

@jonatan-ivanov any update on the PR related to this?

I updated the PR with some OSGi tests. Happy to discuss what else is needed before this can be merged.

driessamyn avatar Dec 22 '22 13:12 driessamyn

Thank you for the work on this. Since we don't have much OSGi experience or expertise on the core team, it would be super helpful if we had a few people that were willing to be pinged on any future issues/questions that come up in Micrometer related to OSGi support so we could get your help. What I want to avoid is delivering this feature and then eventually we have to remove it because we can't support it. @driessamyn and @jingsx would you be willing to help with future questions/issues that come up in Micrometer related to OSGi? Anyone else that could help out with this?

shakuzen avatar Mar 01 '23 06:03 shakuzen

ons/issues that come up in Micrometer related to OSGi? Anyone else that could help out with this?

@shakuzen , I'm happy to help in this area where I can.

driessamyn avatar Mar 03 '23 08:03 driessamyn

Thank you for the offer to help @driessamyn and thank you for the pull request that is now merged to provide initial support for OSGi bundles in Micrometer.

Those who needed this, please try out the latest snapshots (available now) and the 1.10.0-M2 milestone that will be released next week to ensure this works for your use case, and if not, please report any issues.

I want to reiterate that we can only offer OSGi support in Micrometer on a best effort basis. If it were possible for this support to be maintained outside of the Micrometer repository without the need to fork Micrometer, we would have opted to do that, because I am still worried it is going to be a challenge to support this going forward. Hopefully things "just work" with the changes made and that is useful to people. If there are issues found and we cannot support this, we may have to remove OSGi support in the future. We will try to keep support as long as it is feasible and minimally intrusive and we can maintain it with our very limited knowledge and expertise on OSGi. Big thank you again to @driessamyn for your patience and diligence on providing the pull request.

shakuzen avatar Mar 09 '23 13:03 shakuzen