[ 
https://issues.apache.org/jira/browse/CAMEL-15457?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17183322#comment-17183322
 ] 

Espen Andreassen commented on CAMEL-15457:
------------------------------------------

Hi! I see you implemented a fix and resolved the issue, thank you for the 
prompt effort! Unfortionatly, the fix is somewhat incompatible with prometheus 
it seems:
{code:java}
Prometheus requires that all meters with the same name have the same set of tag 
keys. There is already an existing meter named 'CamelExchangesInflight' 
containing tag keys [camelContext, serviceName]. The meter you are attempting 
to register has keys [camelContext, routeId, serviceName].
{code}
 

My suggestion is to add/move the check you introduced in the 
MicrometerExchangeEventNotifierNamingStrategy to the method 
handleExchangeEvent() in MicrometerExchangeEventNotifier. That way we don't 
create the inflight metric at all in cases where no fromRouteId() can be 
extracted, which isn't really usefull in my opinion any way. Could be an idea 
to check for the precense of fromEndpoint as well, as this can also potentially 
return null. Something like this:


{code:java}
    private void handleExchangeEvent(ExchangeEvent exchangeEvent) {
        Exchange exchange = exchangeEvent.getExchange();
        if (exchange.getFromRouteId() != null && exchange.getFromEndpoint() != 
null) {
            String name = namingStrategy.getInflightExchangesName(exchange, 
exchange.getFromEndpoint());
            Tags tags = namingStrategy.getInflightExchangesTags(exchangeEvent, 
exchange.getFromEndpoint());
            Gauge.builder(name, () -> 
getInflightExchangesInRoute(exchangeEvent))
                .tags(tags)
                .register(getMeterRegistry());
        }
    }
{code}

> camel-micrometer: NullPointer exception triggered by 
> MicrometerExchangeEventNotifier
> ------------------------------------------------------------------------------------
>
>                 Key: CAMEL-15457
>                 URL: https://issues.apache.org/jira/browse/CAMEL-15457
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-micrometer
>    Affects Versions: 3.5.0
>            Reporter: Espen Andreassen
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 3.5.0
>
>
> A recent [comit|[https://github.com/apache/camel/pull/3976]] causes 
> NullPointer exceptions in some circumstances, though they are caught and 
> logged as "WARN".
> Output from the test testCamelRouteEvents() in 
> MicrometerExchangeEventNotifierTest in master branch:
> {code:java}
> 11:44:32.741 [main] WARN org.apache.camel.support.EventHelper - Error 
> notifying event ID-devbox-1598261669122-0-1 exchange 
> Exchange[ID-devbox-1598261669122-0-1] sending to: direct://in. This exception 
> will be ignored.11:44:32.741 [main] WARN org.apache.camel.support.EventHelper 
> - Error notifying event ID-devbox-1598261669122-0-1 exchange 
> Exchange[ID-devbox-1598261669122-0-1] sending to: direct://in. This exception 
> will be ignored.java.lang.NullPointerException: null at 
> java.util.Objects.requireNonNull(Objects.java:221) ~[?:?] at 
> io.micrometer.core.instrument.ImmutableTag.<init>(ImmutableTag.java:35) 
> ~[micrometer-core-1.5.4.jar:1.5.4] at 
> io.micrometer.core.instrument.Tag.of(Tag.java:29) 
> ~[micrometer-core-1.5.4.jar:1.5.4] at 
> io.micrometer.core.instrument.Tags.of(Tags.java:254) 
> ~[micrometer-core-1.5.4.jar:1.5.4] at 
> org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategy.getInflightExchangesTags(MicrometerExchangeEventNotifierNamingStrategy.java:58)
>  ~[classes/:?] at 
> org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier.handleExchangeEvent(MicrometerExchangeEventNotifier.java:80)
>  ~[classes/:?] at 
> org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier.notify(MicrometerExchangeEventNotifier.java:65)
>  ~[classes/:?] at 
> org.apache.camel.support.EventHelper.doNotifyEvent(EventHelper.java:1236) 
> ~[classes/:?] at 
> org.apache.camel.support.EventHelper.notifyExchangeSending(EventHelper.java:700)
>  ~[classes/:?]
> {code}
> The problem is that the MicrometerExchangeEventNotifier tries to build/update 
> a metric on inflight exchanges in a route based on an ExchangeEvent with no 
> associated fromRoute/fromRouteId. Events such as "ExchangeSendingEvent", as 
> is created in the test, is an example of such an ExchangeEvent.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to