james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/7] james-project git commit: JAMES-1950 Add metrics for each mailet execution time
Date Tue, 14 Mar 2017 09:01:42 GMT
JAMES-1950 Add metrics for each mailet execution time

 I chose to use class name as MailetInfo javadoc states it can be used to display author,
copyright, etc... getName is a method of MailetConfig (and thus GenericMailet) but thus we
can not use it as here we can get generic mailets.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/9f94c0a0
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/9f94c0a0
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/9f94c0a0

Branch: refs/heads/master
Commit: 9f94c0a08d744776071b70e394fc461318f544f0
Parents: ae2caed
Author: benwa <btellier@linagora.com>
Authored: Mon Mar 13 16:03:34 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Mar 14 15:59:22 2017 +0700

----------------------------------------------------------------------
 .../impl/camel/CamelCompositeProcessor.java              |  9 ++++++++-
 .../mailetcontainer/impl/camel/CamelMailetProcessor.java | 10 ++++++++--
 .../james/mailetcontainer/impl/camel/CamelProcessor.java | 11 +++++++++--
 .../impl/camel/CamelMailetProcessorTest.java             |  3 ++-
 4 files changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9f94c0a0/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java
index 80c5877..b6c1411 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelCompositeProcessor.java
@@ -30,6 +30,7 @@ import org.apache.james.mailetcontainer.api.MailProcessor;
 import org.apache.james.mailetcontainer.api.MailetLoader;
 import org.apache.james.mailetcontainer.api.MatcherLoader;
 import org.apache.james.mailetcontainer.lib.AbstractStateCompositeProcessor;
+import org.apache.james.metrics.api.MetricFactory;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailetContext;
 
@@ -42,12 +43,18 @@ import org.apache.mailet.MailetContext;
  */
 public class CamelCompositeProcessor extends AbstractStateCompositeProcessor implements CamelContextAware
{
 
+    private final MetricFactory metricFactory;
     private CamelContext camelContext;
     private MailetContext mailetContext;
     private MatcherLoader matcherLoader;
     private MailetLoader mailetLoader;
 
     @Inject
+    public CamelCompositeProcessor(MetricFactory metricFactory) {
+        this.metricFactory = metricFactory;
+    }
+
+    @Inject
     public void setMatcherLoader(MatcherLoader matcherLoader) {
         this.matcherLoader = matcherLoader;
     }
@@ -100,7 +107,7 @@ public class CamelCompositeProcessor extends AbstractStateCompositeProcessor
imp
      * #createMailProcessor(java.lang.String, org.apache.commons.configuration.HierarchicalConfiguration)
      */
     protected MailProcessor createMailProcessor(String name, HierarchicalConfiguration config)
throws Exception {
-        CamelMailetProcessor processor = new CamelMailetProcessor();
+        CamelMailetProcessor processor = new CamelMailetProcessor(metricFactory);
         try {
             processor.setLog(logger);
             processor.setCamelContext(camelContext);

http://git-wip-us.apache.org/repos/asf/james-project/blob/9f94c0a0/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
index 414d184..1593fc4 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
@@ -36,6 +36,7 @@ import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
 import org.apache.james.mailetcontainer.impl.MailetConfigImpl;
 import org.apache.james.mailetcontainer.impl.MatcherMailetPair;
 import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor;
+import org.apache.james.metrics.api.MetricFactory;
 import org.apache.mailet.Mail;
 import org.apache.mailet.Mailet;
 import org.apache.mailet.MailetConfig;
@@ -55,8 +56,13 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor
implement
     private ProducerTemplate producerTemplate;
 
     private final UseLatestAggregationStrategy aggr = new UseLatestAggregationStrategy();
+    private final MetricFactory metricFactory;
     private List<MatcherMailetPair> pairs;
 
+    public CamelMailetProcessor(MetricFactory metricFactory) {
+        this.metricFactory = metricFactory;
+    }
+
     /**
      * @see
      * org.apache.james.mailetcontainer.api.MailProcessor#service(org.apache.mailet.Mail)
@@ -160,7 +166,7 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor
implement
                     onMatchException = ((MailetConfigImpl) mailetConfig).getInitAttribute("onMatchException");
                 }
 
-                CamelProcessor mailetProccessor = new CamelProcessor(mailet, logger, CamelMailetProcessor.this);
+                CamelProcessor mailetProccessor = new CamelProcessor(metricFactory, mailet,
logger, CamelMailetProcessor.this);
                 // Store the matcher to use for splitter in properties
                 processorDef.setProperty(MatcherSplitter.MATCHER_PROPERTY, constant(matcher)).setProperty(MatcherSplitter.ON_MATCH_EXCEPTION_PROPERTY,
constant(onMatchException)).setProperty(MatcherSplitter.MAILETCONTAINER_PROPERTY, constant(CamelMailetProcessor.this))
 
@@ -174,7 +180,7 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor
implement
                         .choice().when(new MailStateNotEquals(state)).process(stateChangedProcessor).process(completeProcessor).stop().end();
             }
 
-            Processor terminatingMailetProcessor = new CamelProcessor(new TerminatingMailet(),
getLogger(), CamelMailetProcessor.this);
+            Processor terminatingMailetProcessor = new CamelProcessor(metricFactory, new
TerminatingMailet(), getLogger(), CamelMailetProcessor.this);
 
             processorDef
             // start choice

http://git-wip-us.apache.org/repos/asf/james-project/blob/9f94c0a0/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
index 4113e6d..0f168ca 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelProcessor.java
@@ -28,6 +28,8 @@ import org.apache.camel.Processor;
 import org.apache.james.mailetcontainer.impl.MailetConfigImpl;
 import org.apache.james.mailetcontainer.impl.ProcessorUtil;
 import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor.MailetProcessorListener;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.api.TimeMetric;
 import org.apache.mailet.Mail;
 import org.apache.mailet.Mailet;
 import org.apache.mailet.MailetConfig;
@@ -39,16 +41,19 @@ import org.slf4j.Logger;
  */
 public class CamelProcessor implements Processor {
 
+    private final MetricFactory metricFactory;
     private final Mailet mailet;
     private final Logger logger;
     private final CamelMailetProcessor processor;
 
     /**
      * Mailet to call on process
-     * 
+     *
+     * @param metricFactory
      * @param mailet
      */
-    public CamelProcessor(Mailet mailet, Logger logger, CamelMailetProcessor processor) {
+    public CamelProcessor(MetricFactory metricFactory, Mailet mailet, Logger logger, CamelMailetProcessor
processor) {
+        this.metricFactory = metricFactory;
         this.mailet = mailet;
         this.logger = logger;
         this.processor = processor;
@@ -60,6 +65,7 @@ public class CamelProcessor implements Processor {
     public void process(Exchange exchange) throws Exception {
         Mail mail = exchange.getIn().getBody(Mail.class);
         long start = System.currentTimeMillis();
+        TimeMetric timeMetric = metricFactory.timer(mailet.getClass().getSimpleName());
         MessagingException ex = null;
         try {
             MailetPipelineLogging.logBeginOfMailetProcess(mailet, mail);
@@ -87,6 +93,7 @@ public class CamelProcessor implements Processor {
             }
 
         } finally {
+            timeMetric.stopAndPublish();
             MailetPipelineLogging.logEndOfMailetProcess(mailet, mail);
             List<MailetProcessorListener> listeners = processor.getListeners();
             long complete = System.currentTimeMillis() - start;

http://git-wip-us.apache.org/repos/asf/james-project/blob/9f94c0a0/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java
b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java
index 8afae28..6622a72 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessorTest.java
@@ -29,6 +29,7 @@ import org.apache.james.mailetcontainer.api.mock.MockMailetLoader;
 import org.apache.james.mailetcontainer.api.mock.MockMatcherLoader;
 import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor;
 import org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessorTest;
+import org.apache.james.metrics.api.NoopMetricFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,7 +39,7 @@ public class CamelMailetProcessorTest extends AbstractStateMailetProcessorTest
{
     protected AbstractStateMailetProcessor createProcessor(HierarchicalConfiguration configuration)
throws Exception {
         CamelMailetProcessor processor = null;
         try {
-            processor = new CamelMailetProcessor();
+            processor = new CamelMailetProcessor(new NoopMetricFactory());
             Logger log = LoggerFactory.getLogger("MockLog");
             // slf4j can't set programmatically any log level. It's just a
             // facade


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message