camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Lebreil (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CAMEL-9151) Wrong statistics for subroutes
Date Tue, 22 Sep 2015 08:46:04 GMT

     [ https://issues.apache.org/jira/browse/CAMEL-9151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Vincent Lebreil updated CAMEL-9151:
-----------------------------------
    Description: 
Some statistics seem to be wrong for subroutes.

MetricsStatistics.onExchangeDone method is called several times for a same exchange: first
by the subroute and then by its parent route.

The problem is that context.stop() is called several times so counters is greater than 1 for
the subroute instead of one.

A solution could be to reset the context into the exchange as soon as the stop method has
been called:

{code:title=MetricsRoutePolicy.java|borderStyle=solid}
private static final class MetricsStatistics {
        private final Timer responses;

        private MetricsStatistics(Timer responses) {
            this.responses = responses;
        }

        public void onExchangeBegin(Exchange exchange) {
            Timer.Context context = responses.time();
            exchange.setProperty("MetricsRoutePolicy", context);
        }

        public void onExchangeDone(Exchange exchange) {
            Timer.Context context = exchange.getProperty("MetricsRoutePolicy", Timer.Context.class);
            if (context != null) {
                context.stop();
                // BUGFIX: reset to null so that context.stop() cannot be called
                // more than once.
                exchange.setProperty("MetricsRoutePolicy", null);

            }
        }
    }
{code}


  was:
Some statistics seem to be wrong for subroutes.

MetricsStatistics.onExchangeDone method is called several times for a same exchange: first
by the subroute and then by its parent route.

The problem is that context.stop() is called several times so counters is greater than 1 for
the subroute instead of one.

A solution could be to reset the context into the exchange as soon as the stop method has
been called:

private static final class MetricsStatistics {
        private final Timer responses;

        private MetricsStatistics(Timer responses) {
            this.responses = responses;
        }

        public void onExchangeBegin(Exchange exchange) {
            Timer.Context context = responses.time();
            exchange.setProperty("MetricsRoutePolicy", context);
        }

        public void onExchangeDone(Exchange exchange) {
            Timer.Context context = exchange.getProperty("MetricsRoutePolicy", Timer.Context.class);
            if (context != null) {
                context.stop();
                // BUGFIX: reset to null so that context.stop() cannot be called
                // more than once.
                exchange.setProperty("MetricsRoutePolicy", null);

            }
        }
    }




> Wrong statistics for subroutes
> ------------------------------
>
>                 Key: CAMEL-9151
>                 URL: https://issues.apache.org/jira/browse/CAMEL-9151
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-metrics
>    Affects Versions: 2.15.2
>            Reporter: Vincent Lebreil
>
> Some statistics seem to be wrong for subroutes.
> MetricsStatistics.onExchangeDone method is called several times for a same exchange:
first by the subroute and then by its parent route.
> The problem is that context.stop() is called several times so counters is greater than
1 for the subroute instead of one.
> A solution could be to reset the context into the exchange as soon as the stop method
has been called:
> {code:title=MetricsRoutePolicy.java|borderStyle=solid}
> private static final class MetricsStatistics {
>         private final Timer responses;
>         private MetricsStatistics(Timer responses) {
>             this.responses = responses;
>         }
>         public void onExchangeBegin(Exchange exchange) {
>             Timer.Context context = responses.time();
>             exchange.setProperty("MetricsRoutePolicy", context);
>         }
>         public void onExchangeDone(Exchange exchange) {
>             Timer.Context context = exchange.getProperty("MetricsRoutePolicy", Timer.Context.class);
>             if (context != null) {
>                 context.stop();
>                 // BUGFIX: reset to null so that context.stop() cannot be called
>                 // more than once.
>                 exchange.setProperty("MetricsRoutePolicy", null);
>             }
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message