ramu11 commented on code in PR #30945:
URL: https://github.com/apache/camel/pull/30945#discussion_r4726762474
##########
components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCProducer.java:
##########
@@ -326,22 +321,39 @@ private String currentAlgorithm() {
private PQCMetrics createMetrics() {
CamelContext camelContext = getEndpoint().getCamelContext();
- // Only touch Micrometer if it is actually on the classpath, keeping
it an optional dependency.
- // Use reflection to avoid a static class reference that GraalVM
native image would follow.
- if
(camelContext.getClassResolver().resolveClass("io.micrometer.core.instrument.MeterRegistry")
== null) {
+ ClassLoader contextLoader =
Thread.currentThread().getContextClassLoader();
+ ClassLoader componentLoader =
PQCMetricsProvider.class.getClassLoader();
+
+ PQCMetrics metrics = createMetrics(camelContext, contextLoader);
+ if (metrics != PQCMetrics.NOOP) {
+ return metrics;
+ }
+ if (componentLoader != null && componentLoader != contextLoader) {
+ metrics = createMetrics(camelContext, componentLoader);
+ if (metrics != PQCMetrics.NOOP) {
+ return metrics;
+ }
+ }
+ return PQCMetrics.NOOP;
+ }
+
+ /** Loads optional metrics integrations through the Camel-owned SPI; no
reflective class lookup is used. */
+ private PQCMetrics createMetrics(CamelContext camelContext, ClassLoader
classLoader) {
+ if (classLoader == null) {
return PQCMetrics.NOOP;
}
try {
- Class<?> clazz = camelContext.getClassResolver()
-
.resolveClass("org.apache.camel.component.pqc.metrics.PQCMicrometerMetrics");
- if (clazz == null) {
- return PQCMetrics.NOOP;
+ for (PQCMetricsProvider provider :
ServiceLoader.load(PQCMetricsProvider.class, classLoader)) {
Review Comment:
Addressed in commit `1c3fdb93bd0c`.
I removed the `ServiceLoader`-based metrics provider discovery and changed
it to Camel's `FactoryFinder`, using the
`META-INF/services/org/apache/camel/pqc/metrics/` resource convention.
I also avoided moving Micrometer support into a separate
`camel-pqc-micrometer` module. The Micrometer implementation is now included in
`camel-pqc` and uses an optional `micrometer-core` dependency. This preserves
the existing metrics integration for users who have Micrometer available,
without requiring a separate module or an upgrade migration.
Thanks for raising both the discovery and upgrade-compatibility concerns.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]