-
Notifications
You must be signed in to change notification settings - Fork 350
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
Add Camel Quarkus with MicroProfile Metrics and Prometheus Example #1506
Conversation
Custom metrics declared using the MP Metrics annotations are not picked-up. I can speculate the classes are not registered for reflection. @jamesnetherton @lburgazzoli what would be the best approach to fix this? |
Do you have an example integration? IIRC there's no need to register anything for reflection, the Quarkus metrics extension would (or should) handle that if necessary. |
@jamesnetherton the two following metrics from the example included in this PR are not picked-up:
It's possible to run the example with:
It's likely I miss something obvious 😃! |
I tested outside of camel-k in a standalone Quarkus unit test. It seems to be a problem with injecting the meters into the gauge producer method. I got:
I'm not sure whether injecting the As a hacky workaround, this worked for me: @Produces
@ApplicationScoped
@Metric(name = "success-ratio")
Gauge<Double> successRatio(MetricRegistry metricRegistry) {
Meter success = MicroProfileMetricsHelper.findMetric(metricRegistry, "success", Meter.class);
Meter generated = MicroProfileMetricsHelper.findMetric(metricRegistry, "generated", Meter.class);
return () -> success.getOneMinuteRate() / generated.getOneMinuteRate();
} I can try to dig into it a bit more on the camel-quarkus side to see if I can make things work as you intended. |
You're right, using @Produces
@ApplicationScoped
@Metric(name = "success-ratio")
// Register a custom gauge that's the ratio of the 'success' meter on the 'generated' meter
Gauge<Double> successRatio(@Metric(name = "success") Meter success, @Metric(name = "generated") Meter generated) {
return () -> success.getOneMinuteRate() / generated.getOneMinuteRate();
} Otherwise, I wonder whether if it'd be possible to compile with Does the second metric show up in your test: https://github.com/apache/camel-k/pull/1506/files#diff-46af9059a84ff792cd6260dde1b5d7d2R30? |
Yes the second metric is showing up for me but it's always reporting as '0'. |
Hum, for some reasons I can't seem to have these two metrics when I deploy the integration with Camel K :( The metrics from the Camel MP Metrics component do show up. |
camel-k does not do anything cdi related so I think there should be a way to put the metric to the camel registry, maybe with @BindToRegistry, and them having the metrics component do the registration |
My understanding is that metrics are CDI beans, so if they do not show up, it means they are not scanned as such by Quarkus. From a user standpoint, I would find it surprising to have to bind the metrics to the Camel registry. Plus it seems the example kind of work outside Camel K. |
yep but remember camel k compiles the routes at runtime, if you bring them as external dependency it should work out of the box as they can be detected at build time |
Right. It's clear why it doesn't work then. I wonder whether the bean classes could be declared in such way that they are used during the Quarkus build, and packaged as an extra layer of the integration image... |
I think we need to keep a clear separation between integrations and the ‘runtimes’ as an example java routes are not supported when compiling native code thus I think the runtime should not leak too much into any code that should be stored as part of the CR but we can explore some option. |
OK it makes sense. I'll probably revisit the example then. Let's close this in the meantime. |
I've tried relying on Jitpack to externalise the custom metrics in a separate JAR : https://github.com/astefanutti/camel-k-example-metrics. Unfortunately, it seems the MP annotations are not taken into account. I guess these have to be scanned from source at build time, instead of bringing them as dependencies... |
yep, we probably need to automatically add external dependencies to the list quarkus needs to index |
Right, let me try https://quarkus.io/guides/cdi-reference#how-to-generate-a-jandex-index... |
Requires #1490.
Release Note