[
https://issues.apache.org/jira/browse/CAMEL-26415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18134812#comment-18134812
]
Pasquale Congiusti commented on CAMEL-26415:
--------------------------------------------
While releasing the fix, here a possible workaround. The user should override
the behavior that is failing by entirely skipping the execution of the low
performance code:
{code:java}
public class NoLastTimestampExchangeEventNotifier extends
MicrometerExchangeEventNotifier {
@Override
protected void handleDoneEvent(ExchangeEvent doneEvent) {
// Reproduce the timer logic from the parent (setLastTimeExchange() is
private,
// so we cannot just skip it — we must reimplement the method without
it)
String name = getNamingStrategy().getName(doneEvent.getExchange(),
doneEvent.getExchange().getFromEndpoint());
Tags tags = getNamingStrategy().getTags(doneEvent,
doneEvent.getExchange().getFromEndpoint());
Timer.Sample sample = (Timer.Sample)
doneEvent.getExchange().removeProperty("eventTimer:" + name);
if (sample != null) {
Timer timer = getMeterRegistry().find(name).tags(tags).timer();
if (timer == null) {
timer = Timer.builder(name).tags(tags)
.description("Time taken for exchange processing")
.register(getMeterRegistry());
}
sample.stop(timer);
}
// setLastTimeExchange() intentionally omitted
}
} {code}
With that code in place, it should be then configured in the application
depending on the specific runtime:
Springboot:
{code:java}
@Configuration
public class CamelMetricsConfig {
@Bean
public MicrometerExchangeEventNotifier exchangeEventNotifier(MeterRegistry
registry) {
NoLastTimestampExchangeEventNotifier notifier = new
NoLastTimestampExchangeEventNotifier();
notifier.setMeterRegistry(registry);
return notifier;
}
} {code}
Quarkus:
{code:java}
@ApplicationScoped
public class CamelMetricsConfig {
@Inject
MeterRegistry registry;
@Produces
@ApplicationScoped
public MicrometerExchangeEventNotifier exchangeEventNotifier() {
NoLastTimestampExchangeEventNotifier notifier = new
NoLastTimestampExchangeEventNotifier();
notifier.setMeterRegistry(registry);
return notifier;
}
} {code}
Main:
{code:java}
public class MyApp {
public static void main(String[] args) throws Exception {
Main main = new Main();
// Register the notifier before the context starts
main.configure().withRoutesIncludedPattern("routes/*.java");
main.getCamelContext().getManagementStrategy()
.addEventNotifier(new NoLastTimestampExchangeEventNotifier());
main.run(args);
}
} {code}
I haven't tested, so, please, do the needed due diligence by verifying that the
workaround can really fix the problem.
> [camel-micrometer] Reduce the time to lookup camel_exchanges_last_timestamp
> ---------------------------------------------------------------------------
>
> Key: CAMEL-26415
> URL: https://issues.apache.org/jira/browse/CAMEL-26415
> Project: Camel
> Issue Type: Improvement
> Affects Versions: 4.14.0, 4.18.0, 4.22.0
> Reporter: Pasquale Congiusti
> Assignee: Pasquale Congiusti
> Priority: Major
> Fix For: 4.18.6, 4.22.3, 4.24.0
>
>
> In CAMEL-22153 we introduced a camel_exchanges_last_timestamp metric in order
> to keep track when an application is idle. However this may not perform well
> in case of high amount of traffic as, the way it is developed, it make a full
> scan to look it up at each exchange done event.
> We should provide a better implementation performance wise and introduce a
> parameter in order to enable/disable the setting of this metric.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)