polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [2/3] zest-java git commit: ZEST-190 Refine Metrics API
Date Mon, 07 Nov 2016 12:59:00 GMT
ZEST-190 Refine Metrics API

Simplify metrics naming.
Use “structure path” for UoW metrics and TimingCapture.
@TimingCapture annotation provide a way to override the default name.


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/aff42823
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/aff42823
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/aff42823

Branch: refs/heads/develop
Commit: aff42823e555277d397a38976d1d56d1363a5690
Parents: cd3053e
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Nov 7 11:53:59 2016 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Nov 7 12:02:32 2016 +0100

----------------------------------------------------------------------
 .../apache/zest/api/metrics/MetricNames.java    | 95 ++++++++++++++++++++
 .../zest/api/metrics/MetricsCounterFactory.java |  3 +-
 .../zest/api/metrics/MetricsGaugeFactory.java   |  3 +-
 .../api/metrics/MetricsHealthCheckFactory.java  |  3 +-
 .../api/metrics/MetricsHistogramFactory.java    |  3 +-
 .../zest/api/metrics/MetricsMeterFactory.java   |  3 +-
 .../zest/api/metrics/MetricsTimerFactory.java   |  3 +-
 .../zest/api/metrics/DocumentationSupport.java  | 11 ++-
 .../runtime/unitofwork/UnitOfWorkInstance.java  | 51 +++++------
 .../zest/spi/metrics/NullMetricsFactory.java    | 12 +--
 .../zest/spi/metrics/DefaultMetricsTest.java    | 12 +--
 .../zest/metrics/yammer/YammerHealthCheck.java  |  2 +-
 .../zest/metrics/yammer/YammerMetricsMixin.java | 25 +++---
 .../zest/library/metrics/TimingCapture.java     |  1 +
 .../metrics/TimingCaptureAllConcern.java        | 34 ++++---
 .../library/metrics/TimingCaptureConcern.java   |  7 +-
 .../zest/library/metrics/MetricsTest.java       | 19 ++--
 17 files changed, 191 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/api/src/main/java/org/apache/zest/api/metrics/MetricNames.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricNames.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricNames.java
new file mode 100644
index 0000000..a924d4b
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricNames.java
@@ -0,0 +1,95 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.zest.api.metrics;
+
+import org.apache.zest.api.structure.Module;
+
+import java.lang.reflect.Method;
+import java.util.StringJoiner;
+
+/**
+ * Metric names utilities.
+ */
+public class MetricNames
+{
+    /**
+     * Build a Metric name for the given fragments.
+     *
+     * @param fragments Name fragments
+     * @return Metric name
+     */
+    public static String nameFor( String... fragments )
+    {
+        StringJoiner joiner = new StringJoiner( "." );
+        for( String fragment : fragments )
+        {
+            joiner.add( fragment );
+        }
+        return joiner.toString();
+    }
+
+    /**
+     * Build a Metric name for the given Module, Type and optional fragments.
+     *
+     * @param module Module
+     * @param type Type
+     * @param fragments Name fragments
+     * @return Metric name
+     */
+    public static String nameFor( Module module, Class<?> type, String... fragments
)
+    {
+        StringJoiner joiner = new StringJoiner( "." )
+                .add( module.layer().name() )
+                .add( module.name() )
+                .add( className( type ) );
+        for( String fragment : fragments )
+        {
+            joiner.add( fragment );
+        }
+        return joiner.toString();
+    }
+
+    /**
+     * Build a Metric name for the given Module, Method and optional fragments.
+     *
+     * @param module Module
+     * @param method Method
+     * @param fragments Name fragments
+     * @return Metric name
+     */
+    public static String nameFor( Module module, Method method, String... fragments )
+    {
+        StringJoiner joiner = new StringJoiner( "." )
+                .add( module.layer().name() )
+                .add( module.name() )
+                .add( className( method.getDeclaringClass() ) )
+                .add( method.getName() );
+        for( String fragment : fragments )
+        {
+            joiner.add( fragment );
+        }
+        return joiner.toString();
+    }
+
+    private static String className( Class<?> clazz )
+    {
+        return clazz.getName().substring( clazz.getName().lastIndexOf( '.' ) + 1 ).replace(
'$', '.' );
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounterFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounterFactory.java
b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounterFactory.java
index f373b02..5941c39 100644
--- a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounterFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsCounterFactory.java
@@ -29,10 +29,9 @@ public interface MetricsCounterFactory extends MetricsFactory
      * Create a MetricsCounter instance.
      * If the same arguments are given twice, the same instance must be returned.
      *
-     * @param origin The class that instantiate the metric
      * @param name   A human readable, short name of the metric.
      *
      * @return A Metric instance to be used, OR org.apache.zest.spi.metrics.DefaultMetric.NULL
if not supported.
      */
-    MetricsCounter createCounter( Class<?> origin, String name );
+    MetricsCounter createCounter( String name );
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGaugeFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGaugeFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGaugeFactory.java
index b4948a1..a5213f6 100644
--- a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGaugeFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsGaugeFactory.java
@@ -28,12 +28,11 @@ public interface MetricsGaugeFactory extends MetricsFactory
     /**
      * Register a MetricsGauge with the underlying Metrics system.
      *
-     * @param origin The class where the MetricsGauge is created.
      * @param name   A human readable, short name of the metric.
      * @param gauge  The implementation of the MetricsGauge.
      * @param <T>    Any type holding the MetricsGauge's current value.
      *
      * @return The same MetricsGauge or the DefaultMetric.NULL MetricsGauge instance.
      */
-    <T> MetricsGauge<T> registerGauge( Class<?> origin, String name, MetricsGauge<T>
gauge );
+    <T> MetricsGauge<T> registerGauge( String name, MetricsGauge<T> gauge
);
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheckFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheckFactory.java
b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheckFactory.java
index 1a7bb1e..ccc3bf8 100644
--- a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheckFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHealthCheckFactory.java
@@ -29,12 +29,11 @@ public interface MetricsHealthCheckFactory extends MetricsFactory
      * Create a MetricsHealthCheck instance.
      * If the same arguments are given twice, the same instance must be returned.
      *
-     * @param origin The class that instantiate the metric
      * @param name   A human readable, short name of the metric.
      * @param check  The health check to be performed regularly.
      *
      * @return A MetricsHealthCheck instance to be used, OR org.apache.zest.spi.metrics.DefaultMetric.NULL
if not supported.
      *
      */
-    MetricsHealthCheck registerHealthCheck( Class<?> origin, String name, MetricsHealthCheck
check );
+    MetricsHealthCheck registerHealthCheck( String name, MetricsHealthCheck check );
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogramFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogramFactory.java
b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogramFactory.java
index a322883..44e2c8c 100644
--- a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogramFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsHistogramFactory.java
@@ -29,11 +29,10 @@ public interface MetricsHistogramFactory extends MetricsFactory
      * Create a MetricsHistogram instance.
      * If the same arguments are given twice, the same instance must be returned.
      *
-     * @param origin The class that instantiate the metric
      * @param name   A human readable, short name of the metric.
      *
      * @return A Metric instance to be used, OR org.apache.zest.spi.metrics.DefaultMetric.NULL
if not supported.
      *
      */
-    MetricsHistogram createHistogram( Class<?> origin, String name );
+    MetricsHistogram createHistogram( String name );
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
index ddafbe0..cad8f57 100644
--- a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsMeterFactory.java
@@ -29,10 +29,9 @@ public interface MetricsMeterFactory extends MetricsFactory
      * Create a MetricsMeter instance.
      * If the same arguments are given twice, the same instance must be returned.
      *
-     * @param origin    The class that instantiate the metric
      * @param name      A human readable, short name of the metric.
      *
      * @return A Metric instance to be used, OR org.apache.zest.spi.metrics.DefaultMetric.NULL
if not supported.
      */
-    MetricsMeter createMeter( Class<?> origin, String name );
+    MetricsMeter createMeter( String name );
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java
index 3c015b2..3139a19 100644
--- a/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java
+++ b/core/api/src/main/java/org/apache/zest/api/metrics/MetricsTimerFactory.java
@@ -29,11 +29,10 @@ public interface MetricsTimerFactory extends MetricsFactory
      * Create a MetricsTimer instance.
      * If the same arguments are given twice, the same instance must be returned.
      *
-     * @param origin   The class that instantiate the metric
      * @param name     A human readable, short name of the metric.
      *
      * @return A Metric instance to be used, OR org.apache.zest.spi.metrics.DefaultMetric.NULL
if not supported.
      *
      */
-    MetricsTimer createTimer( Class<?> origin, String name );
+    MetricsTimer createTimer( String name );
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
----------------------------------------------------------------------
diff --git a/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
b/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
index ad71b76..0a224d7 100644
--- a/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
+++ b/core/api/src/test/java/org/apache/zest/api/metrics/DocumentationSupport.java
@@ -39,7 +39,7 @@ public class DocumentationSupport
         // END SNIPPET: gauge
         // START SNIPPET: gauge
         MetricsGaugeFactory gaugeFactory = provider.createFactory( MetricsGaugeFactory.class
);
-        MetricsGauge<Integer> gauge = gaugeFactory.registerGauge( getClass(), "Sample
Gauge", new MetricsGauge<Integer>()
+        MetricsGauge<Integer> gauge = gaugeFactory.registerGauge( "Sample Gauge", new
MetricsGauge<Integer>()
         {
             @Override
             public Integer value()
@@ -51,28 +51,27 @@ public class DocumentationSupport
 
         // START SNIPPET: counter
         MetricsCounterFactory counterFactory = provider.createFactory( MetricsCounterFactory.class
);
-        MetricsCounter counter = counterFactory.createCounter( getClass(), "Sample Counter"
);
+        MetricsCounter counter = counterFactory.createCounter( "Sample Counter" );
         // END SNIPPET: counter
 
         // START SNIPPET: histogram
         MetricsHistogramFactory histoFactory = provider.createFactory( MetricsHistogramFactory.class
);
-        MetricsHistogram histogram = histoFactory.createHistogram( getClass(), "Sample Histogram"
);
+        MetricsHistogram histogram = histoFactory.createHistogram( "Sample Histogram" );
         // END SNIPPET: histogram
 
         // START SNIPPET: meter
         MetricsMeterFactory meterFactory = provider.createFactory( MetricsMeterFactory.class
);
-        MetricsMeter meter = meterFactory.createMeter( getClass(), "Sample Meter" );
+        MetricsMeter meter = meterFactory.createMeter( "Sample Meter" );
         // END SNIPPET: meter
 
         // START SNIPPET: timer
         MetricsTimerFactory timerFactory = provider.createFactory( MetricsTimerFactory.class
);
-        MetricsTimer timer = timerFactory.createTimer( getClass(), "Sample Timer" );
+        MetricsTimer timer = timerFactory.createTimer( "Sample Timer" );
         // END SNIPPET: timer
 
         // START SNIPPET: healthcheck
         MetricsHealthCheckFactory healthFactory = provider.createFactory( MetricsHealthCheckFactory.class
);
         MetricsHealthCheck healthCheck = healthFactory.registerHealthCheck(
-            getClass(),
             "Sample Healthcheck",
             new MetricsHealthCheck()
             {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
index 4dca0fd..cf329b2 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/unitofwork/UnitOfWorkInstance.java
@@ -31,6 +31,7 @@ import org.apache.zest.api.common.MetaInfo;
 import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.entity.EntityDescriptor;
 import org.apache.zest.api.entity.EntityReference;
+import org.apache.zest.api.metrics.MetricNames;
 import org.apache.zest.api.metrics.MetricsCounter;
 import org.apache.zest.api.metrics.MetricsCounterFactory;
 import org.apache.zest.api.metrics.MetricsProvider;
@@ -56,7 +57,6 @@ import org.apache.zest.spi.entitystore.EntityNotFoundException;
 import org.apache.zest.spi.entitystore.EntityStore;
 import org.apache.zest.spi.entitystore.EntityStoreUnitOfWork;
 import org.apache.zest.spi.entitystore.StateCommitter;
-import org.apache.zest.spi.metrics.DefaultMetric;
 import org.apache.zest.spi.module.ModuleSpi;
 
 import static org.apache.zest.api.unitofwork.UnitOfWorkCallback.UnitOfWorkStatus.COMPLETED;
@@ -88,7 +88,9 @@ public final class UnitOfWorkInstance
     private boolean open;
     private boolean paused;
 
-    private MetricsTimer.Context metricsTimer;
+    private MetricsCounter metricsCounter;
+    private MetricsTimer metricsTimer;
+    private MetricsTimer.Context metricsTimerContext;
     private MetaInfo metaInfo;
     private List<UnitOfWorkCallback> callbacks;
 
@@ -473,45 +475,36 @@ public final class UnitOfWorkInstance
         instanceCache.remove( entityReference );
     }
 
-    private void incrementCount()
+    private void startCapture()
     {
-        MetricsCounter counter = getCounter();
-        counter.increment();
+        getMetricsCounter().increment();
+        metricsTimerContext = getMetricsTimer().start();
     }
 
-    private void decrementCount()
+    private void endCapture()
     {
-        MetricsCounter counter = getCounter();
-        counter.decrement();
+        getMetricsCounter().decrement();
+        metricsTimerContext.stop();
+        metricsTimerContext = null;
     }
 
-    private MetricsCounter getCounter()
+    private MetricsCounter getMetricsCounter()
     {
-        if( metrics != null )
+        if( metricsCounter == null )
         {
             MetricsCounterFactory metricsFactory = metrics.createFactory( MetricsCounterFactory.class
);
-            return metricsFactory.createCounter( getClass(), "UnitOfWork Counter" );
+            metricsCounter = metricsFactory.createCounter( MetricNames.nameFor( module, UnitOfWork.class,
"counter" ) );
         }
-        return new DefaultMetric();
-    }
-
-    private void endCapture()
-    {
-        decrementCount();
-        metricsTimer.stop();
+        return metricsCounter;
     }
 
-    private void startCapture()
-    {
-        incrementCount();
-        startTimer( metrics );
-    }
-
-    private void startTimer( MetricsProvider metrics )
+    private MetricsTimer getMetricsTimer()
     {
-        MetricsTimerFactory metricsFactory = metrics.createFactory( MetricsTimerFactory.class
);
-        String name = "UnitOfWork Timer";
-        MetricsTimer timer = metricsFactory.createTimer( getClass(), name );
-        metricsTimer = timer.start();
+        if( metricsTimer == null )
+        {
+            MetricsTimerFactory metricsFactory = metrics.createFactory( MetricsTimerFactory.class
);
+            metricsTimer = metricsFactory.createTimer( MetricNames.nameFor( module, UnitOfWork.class,
"timer" ) );
+        }
+        return metricsTimer;
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java b/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java
index 20a0c8d..bb74775 100644
--- a/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java
+++ b/core/spi/src/main/java/org/apache/zest/spi/metrics/NullMetricsFactory.java
@@ -43,7 +43,7 @@ public final class NullMetricsFactory
     public static class NullCounterFactory implements MetricsCounterFactory
     {
         @Override
-        public MetricsCounter createCounter( Class<?> origin, String name )
+        public MetricsCounter createCounter( String name )
         {
             return DefaultMetric.NULL;
         }
@@ -59,7 +59,7 @@ public final class NullMetricsFactory
     {
         @Override
         @SuppressWarnings( "unchecked" )
-        public <T> MetricsGauge<T> registerGauge( Class<?> origin, String
name, MetricsGauge<T> gauge )
+        public <T> MetricsGauge<T> registerGauge( String name, MetricsGauge<T>
gauge )
         {
             return DefaultMetric.NULL;
         }
@@ -74,7 +74,7 @@ public final class NullMetricsFactory
     public static class NullHealthCheckFactory implements MetricsHealthCheckFactory
     {
         @Override
-        public MetricsHealthCheck registerHealthCheck( Class<?> origin, String name,
MetricsHealthCheck check )
+        public MetricsHealthCheck registerHealthCheck( String name, MetricsHealthCheck check
)
         {
             return DefaultMetric.NULL;
         }
@@ -89,7 +89,7 @@ public final class NullMetricsFactory
     public static class NullHistogramFactory implements MetricsHistogramFactory
     {
         @Override
-        public MetricsHistogram createHistogram( Class<?> origin, String name )
+        public MetricsHistogram createHistogram( String name )
         {
             return DefaultMetric.NULL;
         }
@@ -104,7 +104,7 @@ public final class NullMetricsFactory
     public static class NullMeterFactory implements MetricsMeterFactory
     {
         @Override
-        public MetricsMeter createMeter( Class<?> origin, String name )
+        public MetricsMeter createMeter( String name )
         {
 
             return DefaultMetric.NULL;
@@ -120,7 +120,7 @@ public final class NullMetricsFactory
     public static class NullTimerFactory implements MetricsTimerFactory
     {
         @Override
-        public MetricsTimer createTimer( Class<?> origin, String name )
+        public MetricsTimer createTimer( String name )
         {
             return DefaultMetric.NULL;
         }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java
----------------------------------------------------------------------
diff --git a/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java b/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java
index 284c23a..66afa37 100644
--- a/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java
+++ b/core/spi/src/test/java/org/apache/zest/spi/metrics/DefaultMetricsTest.java
@@ -47,7 +47,7 @@ public class DefaultMetricsTest
     {
         MetricsProvider underTest = new MetricsProviderAdapter();
         MetricsCounterFactory factory = underTest.createFactory( MetricsCounterFactory.class
);
-        MetricsCounter test = factory.createCounter( getClass(), "test" );
+        MetricsCounter test = factory.createCounter( "test" );
         test.increment();
         test.decrement();
     }
@@ -57,7 +57,7 @@ public class DefaultMetricsTest
     {
         MetricsProvider underTest = new MetricsProviderAdapter();
         MetricsGaugeFactory factory = underTest.createFactory( MetricsGaugeFactory.class
);
-        MetricsGauge<Instant> test = factory.registerGauge( getClass(), "test", new
MetricsGauge<Instant>()
+        MetricsGauge<Instant> test = factory.registerGauge( "test", new MetricsGauge<Instant>()
         {
             @Override
             public Instant value()
@@ -74,7 +74,7 @@ public class DefaultMetricsTest
     {
         MetricsProvider underTest = new MetricsProviderAdapter();
         MetricsHealthCheckFactory factory = underTest.createFactory( MetricsHealthCheckFactory.class
);
-        MetricsHealthCheck test = factory.registerHealthCheck( getClass(), "test", new MetricsHealthCheck()
+        MetricsHealthCheck test = factory.registerHealthCheck( "test", new MetricsHealthCheck()
         {
             @Override
             public Result check()
@@ -91,7 +91,7 @@ public class DefaultMetricsTest
     {
         MetricsProvider underTest = new MetricsProviderAdapter();
         MetricsHistogramFactory factory = underTest.createFactory( MetricsHistogramFactory.class
);
-        MetricsHistogram test = factory.createHistogram( getClass(), "test" );
+        MetricsHistogram test = factory.createHistogram( "test" );
         test.update( 5L );
         test.update( 5L );
         test.update( 5L );
@@ -102,7 +102,7 @@ public class DefaultMetricsTest
     {
         MetricsProvider underTest = new MetricsProviderAdapter();
         MetricsMeterFactory factory = underTest.createFactory( MetricsMeterFactory.class
);
-        MetricsMeter test = factory.createMeter( getClass(), "test" );
+        MetricsMeter test = factory.createMeter( "test" );
         test.mark();
         test.mark();
         test.mark();
@@ -113,7 +113,7 @@ public class DefaultMetricsTest
     {
         MetricsProvider underTest = new MetricsProviderAdapter();
         MetricsTimerFactory factory = underTest.createFactory( MetricsTimerFactory.class
);
-        MetricsTimer test = factory.createTimer( getClass(), "test" );
+        MetricsTimer test = factory.createTimer( "test" );
         test.start().stop();
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerHealthCheck.java
----------------------------------------------------------------------
diff --git a/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerHealthCheck.java
b/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerHealthCheck.java
index 76439d1..7c272af 100644
--- a/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerHealthCheck.java
+++ b/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerHealthCheck.java
@@ -29,7 +29,7 @@ public class YammerHealthCheck
 {
     private MetricsHealthCheck check;
 
-    public YammerHealthCheck( Class<?> origin, String name, final MetricsHealthCheck
check )
+    public YammerHealthCheck( String name, final MetricsHealthCheck check )
     {
         this.check = check;
         HealthChecks.register( new HealthCheck( name )

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
----------------------------------------------------------------------
diff --git a/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
b/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
index be92066..302a443 100644
--- a/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
+++ b/extensions/metrics-yammer/src/main/java/org/apache/zest/metrics/yammer/YammerMetricsMixin.java
@@ -23,6 +23,7 @@ package org.apache.zest.metrics.yammer;
 import com.yammer.metrics.Metrics;
 import com.yammer.metrics.core.Counter;
 import com.yammer.metrics.core.Gauge;
+import com.yammer.metrics.core.MetricName;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Stream;
 import org.apache.zest.api.injection.scope.Structure;
@@ -54,9 +55,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
         return new MetricsTimerFactory()
         {
             @Override
-            public MetricsTimer createTimer( Class<?> origin, String name )
+            public MetricsTimer createTimer( String name )
             {
-                return new YammerTimer( Metrics.newTimer( origin, name, app.name(), TimeUnit.MILLISECONDS,
TimeUnit.SECONDS ) );
+                return new YammerTimer( Metrics.newTimer( new MetricName( "", "", name ),
TimeUnit.MILLISECONDS, TimeUnit.SECONDS ) );
             }
 
             @Override
@@ -73,9 +74,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
         return new MetricsMeterFactory()
         {
             @Override
-            public MetricsMeter createMeter( Class<?> origin, String name )
+            public MetricsMeter createMeter( String name )
             {
-                return new YammerMeter( Metrics.newMeter( origin, name, app.name(), TimeUnit.MILLISECONDS
) );
+                return new YammerMeter( Metrics.newMeter( new MetricName( "" , "", name ),
"", TimeUnit.MILLISECONDS ) );
             }
 
             @Override
@@ -92,9 +93,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
         return new MetricsHistogramFactory()
         {
             @Override
-            public MetricsHistogram createHistogram( Class<?> origin, String name )
+            public MetricsHistogram createHistogram( String name )
             {
-                return new YammerHistogram( Metrics.newHistogram( origin, name, app.name()
) );
+                return new YammerHistogram( Metrics.newHistogram( new MetricName( "", "",
name ) ) );
             }
 
             @Override
@@ -111,9 +112,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
         return new MetricsHealthCheckFactory()
         {
             @Override
-            public MetricsHealthCheck registerHealthCheck( Class<?> origin, String
name, MetricsHealthCheck check )
+            public MetricsHealthCheck registerHealthCheck( String name, MetricsHealthCheck
check )
             {
-                return new YammerHealthCheck( origin, name, check );
+                return new YammerHealthCheck( name, check );
             }
 
             @Override
@@ -130,9 +131,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
         return new MetricsGaugeFactory()
         {
             @Override
-            public <T> MetricsGauge<T> registerGauge( Class<?> origin,
String name, final MetricsGauge<T> gauge )
+            public <T> MetricsGauge<T> registerGauge( String name, final MetricsGauge<T>
gauge )
             {
-                Gauge<T> yammer = Metrics.newGauge( origin, name, app.name(), new Gauge<T>()
+                Gauge<T> yammer = Metrics.newGauge( new MetricName( "", "", name ),
new Gauge<T>()
                 {
 
                     @Override
@@ -158,9 +159,9 @@ public class YammerMetricsMixin extends MetricsProviderAdapter
         return new MetricsCounterFactory()
         {
             @Override
-            public MetricsCounter createCounter( Class<?> origin, String name )
+            public MetricsCounter createCounter( String name )
             {
-                Counter counter = Metrics.newCounter( origin, name, app.name() );
+                Counter counter = Metrics.newCounter( new MetricName( "", "", name ) );
                 return new YammerCounter( counter );
             }
 

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCapture.java
----------------------------------------------------------------------
diff --git a/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCapture.java
b/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCapture.java
index f1dbaa0..8e34f43 100644
--- a/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCapture.java
+++ b/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCapture.java
@@ -33,4 +33,5 @@ import org.apache.zest.api.injection.InjectionScope;
 @InjectionScope
 public @interface TimingCapture
 {
+    String value() default "";
 }

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
----------------------------------------------------------------------
diff --git a/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
b/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
index 015f1d8..dcb4cdb 100644
--- a/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
+++ b/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureAllConcern.java
@@ -26,34 +26,44 @@ import org.apache.zest.api.common.Optional;
 import org.apache.zest.api.concern.ConcernOf;
 import org.apache.zest.api.injection.scope.Invocation;
 import org.apache.zest.api.injection.scope.Service;
+import org.apache.zest.api.injection.scope.Structure;
+import org.apache.zest.api.metrics.MetricNames;
 import org.apache.zest.api.metrics.MetricsProvider;
 import org.apache.zest.api.metrics.MetricsTimer;
 import org.apache.zest.api.metrics.MetricsTimerFactory;
+import org.apache.zest.api.structure.Module;
 
 public class TimingCaptureAllConcern extends ConcernOf<InvocationHandler>
     implements InvocationHandler
 {
-    private MetricsTimer timer;
+    private final MetricsTimer timer;
 
-    public TimingCaptureAllConcern( @Service @Optional MetricsProvider metrics,
+    public TimingCaptureAllConcern( @Structure Module module,
+                                    @Service @Optional MetricsProvider metrics,
                                     @Invocation Method method
     )
     {
-        if( metrics != null )
+        if( metrics == null )
+        {
+            timer = null;
+        }
+        else
         {
             MetricsTimerFactory factory = metrics.createFactory( MetricsTimerFactory.class
);
-            boolean annotated = method.getAnnotation( TimingCapture.class ) != null;
-            String captureNme = getMethodName( method ) + "() ["  +( annotated ? "@" : ""
) + "TimingCapture" + "]";
-            Class<?> declaringClass = method.getDeclaringClass();
-            timer = factory.createTimer( declaringClass, captureNme );
+            TimingCapture capture = method.getAnnotation( TimingCapture.class );
+            String timerName;
+            if( capture == null || "".equals( capture.value() ) )
+            {
+                timerName = MetricNames.nameFor( module, method );
+            }
+            else
+            {
+                timerName = capture.value();
+            }
+            timer = factory.createTimer( timerName );
         }
     }
 
-    private String getMethodName( Method method )
-    {
-        return method.getName();
-    }
-
     @Override
     public Object invoke( Object proxy, Method method, Object[] args )
         throws Throwable

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureConcern.java
----------------------------------------------------------------------
diff --git a/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureConcern.java
b/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureConcern.java
index 546b057..423cbe5 100644
--- a/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureConcern.java
+++ b/libraries/metrics/src/main/java/org/apache/zest/library/metrics/TimingCaptureConcern.java
@@ -25,17 +25,20 @@ import org.apache.zest.api.common.AppliesTo;
 import org.apache.zest.api.common.Optional;
 import org.apache.zest.api.injection.scope.Invocation;
 import org.apache.zest.api.injection.scope.Service;
+import org.apache.zest.api.injection.scope.Structure;
 import org.apache.zest.api.metrics.MetricsProvider;
+import org.apache.zest.api.structure.Module;
 
 @AppliesTo( TimingCapture.class )
 public class TimingCaptureConcern extends TimingCaptureAllConcern
 {
 
-    public TimingCaptureConcern( @Service @Optional MetricsProvider metrics,
+    public TimingCaptureConcern( @Structure Module module,
+                                 @Service @Optional MetricsProvider metrics,
                                  @Invocation Method method
     )
     {
-        super( metrics, method );
+        super( module, metrics, method );
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/zest-java/blob/aff42823/libraries/metrics/src/test/java/org/apache/zest/library/metrics/MetricsTest.java
----------------------------------------------------------------------
diff --git a/libraries/metrics/src/test/java/org/apache/zest/library/metrics/MetricsTest.java
b/libraries/metrics/src/test/java/org/apache/zest/library/metrics/MetricsTest.java
index 5f36d06..1aa22bd 100644
--- a/libraries/metrics/src/test/java/org/apache/zest/library/metrics/MetricsTest.java
+++ b/libraries/metrics/src/test/java/org/apache/zest/library/metrics/MetricsTest.java
@@ -87,6 +87,7 @@ public class MetricsTest extends AbstractZestTest
         Country underTest = transientBuilderFactory.newTransient( Country1.class );
         String result = runTest( underTest );
         result = result.replace( "\r", "" );
+        System.out.println( result );
         assertTrue( lastLine( result, 1 ).contains( "=====================" ) );
         System.out.println( "---END TEST---" );
     }
@@ -97,9 +98,9 @@ public class MetricsTest extends AbstractZestTest
         Country underTest = transientBuilderFactory.newTransient( Country2.class );
         String result = runTest( underTest );
         result = result.replace( "\r", "" );
-        assertThat( lastLine( result, 34 ), equalTo( "org.apache.zest.library.metrics.Country.SomeApplication:"
) );
-        assertThat( lastLine( result, 33 ).trim(), equalTo( "name() [TimingCapture]:" ) );
-        assertThat( lastLine( result, 16 ).trim(), equalTo( "updateName() [TimingCapture]:"
) );
+        System.out.println( result );
+        assertThat( lastLine( result, 33 ).trim(), equalTo( "Layer 1.Module 1.MetricsTest.Country.name:"
) );
+        assertThat( lastLine( result, 16 ).trim(), equalTo( "Layer 1.Module 1.MetricsTest.Country.updateName:"
) );
         assertTrue( lastLine( result, 5 ).contains( "75% <=" ) );
         assertTrue( lastLine( result, 4 ).contains( "95% <=" ) );
         assertTrue( lastLine( result, 3 ).contains( "98% <=" ) );
@@ -114,8 +115,8 @@ public class MetricsTest extends AbstractZestTest
         Country underTest = transientBuilderFactory.newTransient( Country3.class );
         String result = runTest( underTest );
         result = result.replace( "\r", "" );
-        assertThat( lastLine( result, 17 ), equalTo( "org.apache.zest.library.metrics.Country.SomeApplication:"
) );
-        assertThat( lastLine( result, 16 ).trim(), equalTo( "updateName() [TimingCapture]:"
) );
+        System.out.println( result );
+        assertThat( lastLine( result, 16 ).trim(), equalTo( "Country3.updateName:" ) );
         assertTrue( lastLine( result, 5 ).contains( "75% <=" ) );
         assertTrue( lastLine( result, 4 ).contains( "95% <=" ) );
         assertTrue( lastLine( result, 3 ).contains( "98% <=" ) );
@@ -132,7 +133,6 @@ public class MetricsTest extends AbstractZestTest
 
     private String runTest( Country underTest )
     {
-
         for( int i = 0; i < 1000000; i++ )
         {
             underTest.updateName( "Name" + i );
@@ -153,13 +153,11 @@ public class MetricsTest extends AbstractZestTest
     @Mixins( Country1Mixin.class )
     public interface Country1 extends Country
     {
-
     }
 
     public static abstract class Country1Mixin
         implements Country1
     {
-
         @Override
         public void updateName( String newName )
         {
@@ -175,7 +173,6 @@ public class MetricsTest extends AbstractZestTest
     public static abstract class Country2Mixin
         implements Country2
     {
-
         @Override
         public void updateName( String newName )
         {
@@ -187,13 +184,15 @@ public class MetricsTest extends AbstractZestTest
     @Concerns( TimingCaptureConcern.class )
     public interface Country3 extends Country
     {
+        @TimingCapture( "Country3.updateName" )
+        @Override
+        void updateName(String newName);
     }
 
     public static abstract class Country3Mixin
         implements Country3
     {
         @Override
-        @TimingCapture
         public void updateName( String newName )
         {
             name().set( newName );


Mime
View raw message