You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:18:48 UTC

[sling-org-apache-sling-commons-metrics] branch master created (now 8626905)

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git.


      at 8626905  SLING-7167 Adjust READMEs

This branch includes the following new commits:

     new 510579b  SLING-4080 - API to capture/measure application-level metrics Moving to trunk from sandbox
     new 988cec0  SLING-4080 - API to capture/measure application-level metrics
     new bb6b412  SLING-4080 - API to capture/measure application-level metrics
     new 8ffd002  SLING-4080 - API to capture/measure application-level metrics
     new b83aa3a  SLING-4080 - API to capture/measure application-level metrics
     new 428182f  SLING-4080 - API to capture/measure application-level metrics
     new 8a5ced0  SLING-4080 - API to capture/measure application-level metrics
     new 2ae0fe2  SLING-4080 - API to capture/measure application-level metrics
     new a290a59  SLING-4080 - API to capture/measure application-level metrics
     new 288c006  SLING-4080 - API to capture/measure application-level metrics
     new 319a7c8  SLING-4080 - API to capture/measure application-level metrics
     new 43662e4  SLING-4080 - API to capture/measure application-level metrics
     new 32d29af  [maven-release-plugin] prepare release org.apache.sling.commons.metrics-0.0.2
     new 2038b09  [maven-release-plugin] prepare for next development iteration
     new 7d5b2d9  SLING-4080 - API to capture/measure application-level metrics
     new 4e1f36b  [maven-release-plugin] prepare release org.apache.sling.commons.metrics-1.0.0
     new 437036c  [maven-release-plugin] prepare for next development iteration
     new 59756f4  SLING-5424 - MBeanServer reference in MetricServiceImpl should be made optional
     new 6bb3b69  SLING-5693 - Add support for exporting MetricRegistry data as JSON
     new 303e368  SLING-5899 - "Guages" Typo in Sling metrics console
     new 620ebee  Update to parent pom 29
     new b945e66  SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans
     new b9fd0ba  SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans
     new dab0074  SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans
     new 0600f8f  SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans
     new 5fd7b2c  SLING-5966 - Add Gauge support to metrics
     new fc92934  SLING-6297 - Switch to standard OSGi annotation in Metrics
     new 2d27194  [maven-release-plugin] prepare release org.apache.sling.commons.metrics-1.2.0
     new eb73752  [maven-release-plugin] prepare for next development iteration
     new 195cf16  SLING-6527 : Remove usage of org.json from metrics module
     new 31cc54d  SLING-6596 - typo: guage -> gauge
     new e414f2b  SLING-6596 - fix typo introduced by the typo fixing
     new 2e2aeb6  use Sling Parent 30
     new ddc272d  SLING-6702 - rename the existing MetricsServiceFactory
     new feb9e87  SLING-6702 - rename the existing MetricsServiceFactory
     new fae352f  SLING-6702 - MetricsServiceFactory + tests. Test are a bit slow for now, starting a full Sling Launchpad should not be needed
     new 8241898  [maven-release-plugin] prepare release org.apache.sling.commons.metrics-1.2.2
     new 9e801d6  [maven-release-plugin] prepare for next development iteration
     new 280f1bf  SLING-7028 - remove assumption that histograms are durations
     new 52bb7c2  SLING-7031 - configurable component to write subset of metrics to log file on a recurring basis.
     new 49825c0  SLING-7062 - Commons metrics inventory closes zip
     new 667dcb8  SLING-7047 - Update Dropwizard Metrics bundles to 3.2 to eliminate sun.misc dependency.
     new 0796346  SLING-7047 - Update Dropwizard Metrics bundles to 3.2 to eliminate sun.misc dependency.
     new 8626905  SLING-7167 Adjust READMEs

The 44 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-org-apache-sling-commons-metrics] 21/44: Update to parent pom 29

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 620ebeeade033d8464312382823cc5ef71089e98
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Oct 21 06:15:56 2016 +0000

    Update to parent pom 29
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1765929 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7b9fef1..8ca2ac8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
   <parent>
     <groupId>org.apache.sling</groupId>
     <artifactId>sling</artifactId>
-    <version>26</version>
+    <version>29</version>
   </parent>
 
   <artifactId>org.apache.sling.commons.metrics</artifactId>
@@ -85,7 +85,7 @@
     </dependency>
     <dependency>
       <groupId>javax.servlet</groupId>
-      <artifactId>servlet-api</artifactId>
+      <artifactId>javax.servlet-api</artifactId>
       <optional>true</optional>
     </dependency>
     <dependency>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 05/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit b83aa3ac0782321ea7df76e59ad4bb1ece118fb8
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 05:09:41 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Update javadocs
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723461 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/commons/metrics/Counter.java   |  3 +++
 src/main/java/org/apache/sling/commons/metrics/Histogram.java |  3 +++
 src/main/java/org/apache/sling/commons/metrics/Meter.java     |  3 +++
 .../java/org/apache/sling/commons/metrics/MetricsService.java | 11 +++++++++++
 src/main/java/org/apache/sling/commons/metrics/Timer.java     |  3 +++
 .../java/org/apache/sling/commons/metrics/package-info.java   |  2 +-
 6 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/Counter.java b/src/main/java/org/apache/sling/commons/metrics/Counter.java
index a4b317a..9f4f062 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Counter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Counter.java
@@ -21,6 +21,9 @@ package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
+/**
+ * An incrementing and decrementing counter metric.
+ */
 @ProviderType
 public interface Counter extends Counting, Metric{
     /**
diff --git a/src/main/java/org/apache/sling/commons/metrics/Histogram.java b/src/main/java/org/apache/sling/commons/metrics/Histogram.java
index 3d1e082..7f87cdc 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Histogram.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Histogram.java
@@ -21,6 +21,9 @@ package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
+/**
+ * A metric which calculates the distribution of a value.
+ */
 @ProviderType
 public interface Histogram extends Counting, Metric {
     /**
diff --git a/src/main/java/org/apache/sling/commons/metrics/Meter.java b/src/main/java/org/apache/sling/commons/metrics/Meter.java
index e239c54..3fef3f8 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Meter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Meter.java
@@ -21,6 +21,9 @@ package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
+/**
+ * A meter metric which measures mean throughput
+ */
 @ProviderType
 public interface Meter extends Counting, Metric{
     /**
diff --git a/src/main/java/org/apache/sling/commons/metrics/MetricsService.java b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
index 8d2c04f..7848861 100644
--- a/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
+++ b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
@@ -21,8 +21,15 @@ package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
+/**
+ * The {@code MetricsService} enables creation of various types of {@code Metric}.
+ */
 @ProviderType
 public interface MetricsService {
+    /**
+     * Dummy variant of MetricsService which does not
+     * collect any metric
+     */
     MetricsService NOOP = new MetricsService() {
         @Override
         public Timer timer(String name) {
@@ -47,6 +54,7 @@ public interface MetricsService {
 
     /**
      * Creates a new {@link Timer} and registers it under the given name.
+     * If a timer with same name exists then same instance is returned
      *
      * @param name the name of the metric
      * @return a new {@link Timer}
@@ -55,6 +63,7 @@ public interface MetricsService {
 
     /**
      * Creates a new {@link Histogram} and registers it under the given name.
+     * If a histogram with same name exists then same instance is returned.
      *
      * @param name the name of the metric
      * @return a new {@link Histogram}
@@ -63,6 +72,7 @@ public interface MetricsService {
 
     /**
      * Creates a new {@link Counter} and registers it under the given name.
+     * If a counter with same name exists then same instance is returned
      *
      * @param name the name of the metric
      * @return a new {@link Counter}
@@ -71,6 +81,7 @@ public interface MetricsService {
 
     /**
      * Creates a new {@link Meter} and registers it under the given name.
+     * If a meter with same name exists then same instance is returned
      *
      * @param name the name of the metric
      * @return a new {@link Meter}
diff --git a/src/main/java/org/apache/sling/commons/metrics/Timer.java b/src/main/java/org/apache/sling/commons/metrics/Timer.java
index a142953..8de1707 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Timer.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Timer.java
@@ -24,6 +24,9 @@ import java.util.concurrent.TimeUnit;
 
 import aQute.bnd.annotation.ProviderType;
 
+/**
+ * A timer metric which aggregates timing durations and provides duration statistics.
+ */
 @ProviderType
 public interface Timer extends Counting, Metric{
     /**
diff --git a/src/main/java/org/apache/sling/commons/metrics/package-info.java b/src/main/java/org/apache/sling/commons/metrics/package-info.java
index 1180f06..aa5623b 100644
--- a/src/main/java/org/apache/sling/commons/metrics/package-info.java
+++ b/src/main/java/org/apache/sling/commons/metrics/package-info.java
@@ -18,7 +18,7 @@
  */
 
 /**
- * Provides configuration support for the Logback based logging in Sling
+ * Provides an API to generate and collect metrics in various forms
  *
  * @version 1.0
  */

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 16/44: [maven-release-plugin] prepare release org.apache.sling.commons.metrics-1.0.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 4e1f36b3ce13e18c4a8799c9a583177331871237
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Tue Jan 12 05:03:50 2016 +0000

    [maven-release-plugin] prepare release org.apache.sling.commons.metrics-1.0.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1724153 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4ed2cfb..3e038d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
 
   <artifactId>org.apache.sling.commons.metrics</artifactId>
   <packaging>bundle</packaging>
-  <version>0.0.3-SNAPSHOT</version>
+  <version>1.0.0</version>
 
   <name>Apache Sling Metrics</name>
   <description>
@@ -40,9 +40,9 @@
   </description>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.0.0</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.0.0</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.commons.metrics-1.0.0</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 35/44: SLING-6702 - rename the existing MetricsServiceFactory

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit feb9e871561fbafe66f2be13c8b07e094eafbc4e
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Mar 23 14:14:49 2017 +0000

    SLING-6702 - rename the existing MetricsServiceFactory
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1788252 13f79535-47bb-0310-9956-ffa450edef68
---
 ...ryTest.java => InternalMetricsServiceFactoryTest.java} | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactoryTest.java
similarity index 95%
rename from src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java
rename to src/test/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactoryTest.java
index f6d635b..2d3ee4e 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactoryTest.java
@@ -19,26 +19,19 @@
 
 package org.apache.sling.commons.metrics.internal;
 
-import java.util.Collections;
-
-import javax.management.ObjectName;
-
 import com.codahale.metrics.MetricRegistry;
+import javax.management.ObjectName;
 import org.apache.sling.commons.metrics.MetricsService;
 import org.apache.sling.testing.mock.osgi.MockBundle;
-import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
-import org.junit.After;
-import org.junit.Before;
+import static org.junit.Assert.*;
 import org.junit.Rule;
 import org.junit.Test;
+import static org.mockito.Mockito.mock;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceRegistration;
 
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-
-public class MetricsServiceFactoryTest {
+public class InternalMetricsServiceFactoryTest {
     @Rule
     public final OsgiContext context = new OsgiContext();
     private MetricsServiceImpl serviceImpl = new MetricsServiceImpl();

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 14/44: [maven-release-plugin] prepare for next development iteration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 2038b0968b2b2fa777041319100ca70dc2244d2d
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 14:03:43 2016 +0000

    [maven-release-plugin] prepare for next development iteration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723550 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index a031a78..4ed2cfb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
 
   <artifactId>org.apache.sling.commons.metrics</artifactId>
   <packaging>bundle</packaging>
-  <version>0.0.2</version>
+  <version>0.0.3-SNAPSHOT</version>
 
   <name>Apache Sling Metrics</name>
   <description>
@@ -40,9 +40,9 @@
   </description>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-0.0.2</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-0.0.2</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.commons.metrics-0.0.2</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 06/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 428182fc571441ab660d872f49d049b937f2b2f6
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 06:50:41 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Update path in scm section
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723469 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 2d18405..281b84f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,14 +35,12 @@
   <name>Apache Sling Metrics</name>
   <description>
     Integrates Metric library http://metrics.dropwizard.io/ with Sling
-
-    Refer to http://sling.apache.org/documentation/bundles/log-tracers.html
   </description>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/metrics</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/metrics</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/metrics</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 44/44: SLING-7167 Adjust READMEs

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 862690543bce444ea40f245f534118bdd75a09ff
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Tue Oct 3 09:49:41 2017 +0000

    SLING-7167 Adjust READMEs
    
    add uniform header linking to Sling project
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1810819 13f79535-47bb-0310-9956-ffa450edef68
---
 README.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index b1d19ca..ed89323 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
 # Apache Sling Metrics
 
+This module is part of the [Apache Sling](https://sling.apache.org) project.
+
 Refer to [Sling Metrics][1]
 
-[1]: https://sling.apache.org/documentation/bundles/metrics.html
\ No newline at end of file
+[1]: https://sling.apache.org/documentation/bundles/metrics.html

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 37/44: [maven-release-plugin] prepare release org.apache.sling.commons.metrics-1.2.2

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 8241898c7ae20a139f903cf25c713f63b163b206
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Fri Jun 2 20:57:03 2017 +0000

    [maven-release-plugin] prepare release org.apache.sling.commons.metrics-1.2.2
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1797443 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index fe07ab1..4da9663 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
 
     <artifactId>org.apache.sling.commons.metrics</artifactId>
     <packaging>bundle</packaging>
-    <version>1.2.1-SNAPSHOT</version>
+    <version>1.2.2</version>
 
     <name>Apache Sling Metrics</name>
     <description>
@@ -42,9 +42,9 @@
     </properties>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.2.2</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.2.2</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.commons.metrics-1.2.2</url>
     </scm>
 
     <build>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 23/44: SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit b9fd0bac0ae988daa8292999a01507700aa1626d
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Nov 17 05:08:27 2016 +0000

    SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans
    
    Switch to ServiceFactory for MetricService and use Bundle to determine JMX domain name for metrics created from using bundle.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1770119 13f79535-47bb-0310-9956-ffa450edef68
---
 .../metrics/internal/BundleMetricsMapper.java      | 102 +++++++++++++++++++++
 .../metrics/internal/MetricsServiceFactory.java    | 102 +++++++++++++++++++++
 .../metrics/internal/MetricsServiceImpl.java       |  23 +++--
 .../metrics/internal/BundleMetricsMapperTest.java  |  77 ++++++++++++++++
 .../internal/MetricsServiceFactoryTest.java        | 100 ++++++++++++++++++++
 5 files changed, 394 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java b/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
new file mode 100644
index 0000000..9a74a1e
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
@@ -0,0 +1,102 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.management.ObjectName;
+
+import com.codahale.metrics.DefaultObjectNameFactory;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.ObjectNameFactory;
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class BundleMetricsMapper implements ObjectNameFactory{
+    public static final String HEADER_DOMAIN_NAME = "Sling-Metrics-Domain";
+    public static final String DEFAULT_DOMAIN_NAME = "org.apache.sling";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private final ConcurrentMap<String, Bundle> metricToBundleMapping = new ConcurrentHashMap<>();
+    private final MetricRegistry registry;
+    private final ObjectNameFactory defaultFactory = new DefaultObjectNameFactory();
+
+    BundleMetricsMapper(MetricRegistry registry) {
+        this.registry = registry;
+    }
+
+    public void addMapping(String name, Bundle bundle) {
+        metricToBundleMapping.putIfAbsent(name, bundle);
+    }
+
+    public void unregister(Set<String> registeredNames) {
+        for (String name : registeredNames){
+            registry.remove(name);
+            metricToBundleMapping.remove(name);
+        }
+        log.debug("Removed metrics for {}", registeredNames);
+    }
+
+    @Override
+    public ObjectName createName(String type, String domain, String name) {
+        String mappedDomainName = safeDomainName(getDomainName(name));
+        if (mappedDomainName == null) {
+            mappedDomainName = domain;
+        }
+        return defaultFactory.createName(type, mappedDomainName, name);
+    }
+
+    private String getDomainName(String name) {
+        Bundle bundle = metricToBundleMapping.get(name);
+        return getDomainName(bundle);
+    }
+
+    private String getDomainName(Bundle bundle) {
+        if (bundle == null){
+            return null;
+        }
+
+        String domainNameHeader = bundle.getHeaders().get(HEADER_DOMAIN_NAME);
+        if (domainNameHeader != null){
+            return domainNameHeader;
+        }
+
+        //Fallback to symbolic name
+        return bundle.getSymbolicName();
+    }
+
+    static String safeDomainName(String name){
+        if (name == null){
+            return null;
+        }
+
+        name = name.trim();
+
+        //Taken from javax.management.ObjectName.isDomain()
+        //Following are special chars in domain name
+        name = name.replace(':', '_');
+        name = name.replace('*', '_');
+        name = name.replace('?', '_');
+        name = name.replace('\n', '_');
+        return name;
+    }
+}
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactory.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactory.java
new file mode 100644
index 0000000..b9d8bb6
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactory.java
@@ -0,0 +1,102 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.sling.commons.metrics.Counter;
+import org.apache.sling.commons.metrics.Histogram;
+import org.apache.sling.commons.metrics.Meter;
+import org.apache.sling.commons.metrics.MetricsService;
+import org.apache.sling.commons.metrics.Timer;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+class MetricsServiceFactory implements ServiceFactory<MetricsService> {
+    private final MetricsService delegate;
+    private final BundleMetricsMapper metricsMapper;
+
+    public MetricsServiceFactory(MetricsService delegate, BundleMetricsMapper metricsMapper) {
+        this.delegate = delegate;
+        this.metricsMapper = metricsMapper;
+    }
+
+    @Override
+    public MetricsService getService(Bundle bundle, ServiceRegistration<MetricsService> registration) {
+        return new BundleMetricService(bundle);
+    }
+
+    @Override
+    public void ungetService(Bundle bundle, ServiceRegistration<MetricsService> registration, MetricsService service) {
+        if (service instanceof BundleMetricService){
+            ((BundleMetricService) service).unregister();
+        }
+    }
+
+    private class BundleMetricService implements MetricsService {
+        private final Bundle bundle;
+        private Set<String> registeredNames = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
+
+        public BundleMetricService(Bundle bundle) {
+            this.bundle = bundle;
+        }
+
+        @Override
+        public Timer timer(String name) {
+            addMapping(name);
+            return delegate.timer(name);
+        }
+
+        @Override
+        public Histogram histogram(String name) {
+            addMapping(name);
+            return delegate.histogram(name);
+        }
+
+        @Override
+        public Counter counter(String name) {
+            addMapping(name);
+            return delegate.counter(name);
+        }
+
+        @Override
+        public Meter meter(String name) {
+            addMapping(name);
+            return delegate.meter(name);
+        }
+
+        @Override
+        public <A> A adaptTo(Class<A> type) {
+            return delegate.adaptTo(type);
+        }
+
+        void unregister(){
+            metricsMapper.unregister(registeredNames);
+        }
+
+        private void addMapping(String name) {
+            metricsMapper.addMapping(name, bundle);
+            registeredNames.add(name);
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
index d2f2728..03efcee 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
@@ -50,9 +50,10 @@ import org.osgi.framework.ServiceRegistration;
 
 @Component
 public class MetricsServiceImpl implements MetricsService {
-    private final List<ServiceRegistration> regs = new ArrayList<ServiceRegistration>();
-    private final ConcurrentMap<String, Metric> metrics = new ConcurrentHashMap<String, Metric>();
+    private final List<ServiceRegistration> regs = new ArrayList<>();
+    private final ConcurrentMap<String, Metric> metrics = new ConcurrentHashMap<>();
     private final MetricRegistry registry = new MetricRegistry();
+    private final BundleMetricsMapper metricsMapper = new BundleMetricsMapper(registry);
 
     @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
     private MBeanServer server;
@@ -63,12 +64,13 @@ public class MetricsServiceImpl implements MetricsService {
     private void activate(BundleContext context, Map<String, Object> config) {
         enableJMXReporter();
 
-        final Dictionary<String, String> svcProps = new Hashtable<String, String>();
+        final Dictionary<String, String> svcProps = new Hashtable<>();
         svcProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics Service");
         svcProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
-        regs.add(context.registerService(MetricsService.class.getName(), this, svcProps));
+        regs.add(context.registerService(MetricsService.class.getName(),
+                new MetricsServiceFactory(this, metricsMapper), svcProps));
 
-        final Dictionary<String, String> regProps = new Hashtable<String, String>();
+        final Dictionary<String, String> regProps = new Hashtable<>();
         regProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics Registry");
         regProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
         regProps.put("name", "sling");
@@ -118,6 +120,10 @@ public class MetricsServiceImpl implements MetricsService {
         return null;
     }
 
+    MetricRegistry getRegistry() {
+        return registry;
+    }
+
     @SuppressWarnings("unchecked")
     private <T extends Metric> T getOrAdd(String name, MetricBuilder<T> builder) {
         final Metric metric = metrics.get(name);
@@ -202,16 +208,13 @@ public class MetricsServiceImpl implements MetricsService {
     }
 
     private void enableJMXReporter() {
-        //TODO Domain name should be based on calling bundle
-        //For that we can register ServiceFactory and make use of calling
-        //bundle symbolic name to determine the mapping
-
         if (server == null){
             server = ManagementFactory.getPlatformMBeanServer();
         }
 
         reporter = JmxReporter.forRegistry(registry)
-                .inDomain("org.apache.sling")
+                .inDomain(BundleMetricsMapper.DEFAULT_DOMAIN_NAME)
+                .createsObjectNamesWith(metricsMapper)
                 .registerWith(server)
                 .build();
         reporter.start();
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java
new file mode 100644
index 0000000..d34357a
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import javax.management.ObjectName;
+
+import com.codahale.metrics.MetricRegistry;
+import com.google.common.collect.ImmutableMap;
+import org.apache.sling.testing.mock.osgi.MockBundle;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class BundleMetricsMapperTest {
+    @Rule
+    public final OsgiContext context = new OsgiContext();
+    private MetricRegistry registry = new MetricRegistry();
+
+    private BundleMetricsMapper mapper = new BundleMetricsMapper(registry);
+
+    @Test
+    public void defaultDomainName() throws Exception{
+        ObjectName name = mapper.createName("counter", "foo", "bar");
+        assertEquals("foo", name.getDomain());
+    }
+
+    @Test
+    public void mappedName_SymbolicName() throws Exception{
+        MockBundle bundle = new MockBundle(context.bundleContext());
+        bundle.setSymbolicName("com.example");
+
+        mapper.addMapping("bar", bundle);
+
+        ObjectName name = mapper.createName("counter", "foo", "bar");
+        assertEquals("com.example", name.getDomain());
+    }
+
+    @Test
+    public void mappedName_Header() throws Exception{
+        MockBundle bundle = new MockBundle(context.bundleContext());
+        bundle.setSymbolicName("com.example");
+        bundle.setHeaders(ImmutableMap.of(BundleMetricsMapper.HEADER_DOMAIN_NAME, "com.test"));
+
+        mapper.addMapping("bar", bundle);
+
+        ObjectName name = mapper.createName("counter", "foo", "bar");
+        assertEquals("com.test", name.getDomain());
+    }
+
+    @Test
+    public void safeDomainName() throws Exception{
+        assertEquals("com.foo", BundleMetricsMapper.safeDomainName("com.foo"));
+        assertEquals("com_foo", BundleMetricsMapper.safeDomainName("com:foo"));
+        assertEquals("com_foo", BundleMetricsMapper.safeDomainName("com?foo"));
+        assertEquals("com_foo", BundleMetricsMapper.safeDomainName("com*foo"));
+    }
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java
new file mode 100644
index 0000000..71d7fe4
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import java.util.Collections;
+
+import javax.management.ObjectName;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.sling.commons.metrics.MetricsService;
+import org.apache.sling.testing.mock.osgi.MockBundle;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceRegistration;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
+public class MetricsServiceFactoryTest {
+    @Rule
+    public final OsgiContext context = new OsgiContext();
+    private MetricsServiceImpl serviceImpl = new MetricsServiceImpl();
+    private MetricRegistry registry = serviceImpl.getRegistry();
+    private BundleMetricsMapper mapper = new BundleMetricsMapper(registry);
+    private MetricsServiceFactory srvFactory = new MetricsServiceFactory(serviceImpl, mapper);
+    private ServiceRegistration<MetricsService> reg = mock(ServiceRegistration.class);
+
+    @Test
+    public void basicWorking() throws Exception{
+        MetricsService service = srvFactory.getService(cb("foo"), reg);
+        service.meter("m1");
+        service.timer("t1");
+        service.histogram("h1");
+        service.counter("c1");
+        assertTrue(registry.getMeters().containsKey("m1"));
+        assertTrue(registry.getTimers().containsKey("t1"));
+        assertTrue(registry.getHistograms().containsKey("h1"));
+        assertTrue(registry.getCounters().containsKey("c1"));
+
+        ObjectName name = mapper.createName("meter", "com.foo", "m1");
+
+        //Domain name should be bundle symbolic name
+        assertEquals("foo", name.getDomain());
+    }
+
+    @Test
+    public void unRegistration() throws Exception{
+        Bundle foo = cb("foo");
+        Bundle bar = cb("bar");
+        MetricsService srv1 = srvFactory.getService(foo, reg);
+        MetricsService srv2 = srvFactory.getService(bar, reg);
+
+        srv1.meter("m1");
+        srv1.counter("c1");
+
+        srv2.meter("m2");
+        assertTrue(registry.getMeters().containsKey("m1"));
+        assertTrue(registry.getMeters().containsKey("m2"));
+        assertTrue(registry.getCounters().containsKey("c1"));
+
+        srvFactory.ungetService(foo, reg, srv1);
+
+        //Metrics from 'foo' bundle i.e. m1 and c1 must be removed
+        assertFalse(registry.getMeters().containsKey("m1"));
+        assertFalse(registry.getCounters().containsKey("c1"));
+
+        //Metrics from 'bar' bundle should be present
+        assertTrue(registry.getMeters().containsKey("m2"));
+    }
+
+    private Bundle cb(String name){
+        MockBundle bundle = new MockBundle(context.bundleContext());
+        bundle.setSymbolicName(name);
+        return bundle;
+    }
+
+
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 28/44: [maven-release-plugin] prepare release org.apache.sling.commons.metrics-1.2.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 2d27194d94d8e4f8780e1722d9f42b0b4034daa4
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Nov 28 09:31:33 2016 +0000

    [maven-release-plugin] prepare release org.apache.sling.commons.metrics-1.2.0
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1771692 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 31cfea9..3275dd5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
 
   <artifactId>org.apache.sling.commons.metrics</artifactId>
   <packaging>bundle</packaging>
-  <version>1.0.1-SNAPSHOT</version>
+  <version>1.2.0</version>
 
   <name>Apache Sling Metrics</name>
   <description>
@@ -40,9 +40,9 @@
   </description>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.2.0</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.2.0</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.commons.metrics-1.2.0</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 29/44: [maven-release-plugin] prepare for next development iteration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit eb73752aa4cb4a12b911d50d8a391c06bf9d2649
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Nov 28 09:31:51 2016 +0000

    [maven-release-plugin] prepare for next development iteration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1771694 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 3275dd5..d395d4c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
 
   <artifactId>org.apache.sling.commons.metrics</artifactId>
   <packaging>bundle</packaging>
-  <version>1.2.0</version>
+  <version>1.2.1-SNAPSHOT</version>
 
   <name>Apache Sling Metrics</name>
   <description>
@@ -40,9 +40,9 @@
   </description>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.2.0</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.2.0</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.commons.metrics-1.2.0</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 42/44: SLING-7047 - Update Dropwizard Metrics bundles to 3.2 to eliminate sun.misc dependency.

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 667dcb8c9d09e2456f583415442031b841d52e63
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Aug 21 05:49:56 2017 +0000

    SLING-7047 - Update Dropwizard Metrics bundles to 3.2 to eliminate sun.misc dependency.
    
    Added a Import-Package with version range which include 3.1 so that
    commons metrics can be used in setups having older version
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1805602 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index d7791af..d7f4a98 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,6 +58,10 @@
                         <Bundle-DocURL>
                             https://sling.apache.org/documentation/bundles/metrics.html
                         </Bundle-DocURL>
+                        <Import-Package>
+                            com.codahale.metrics*;version="[3.1, 4)",
+                            *
+                        </Import-Package>
                         <DynamicImport-Package>
                             javax.servlet,
                             javax.servlet.http;version="[2.3,3)",
@@ -127,7 +131,7 @@
         <dependency>
             <groupId>io.dropwizard.metrics</groupId>
             <artifactId>metrics-core</artifactId>
-            <version>3.1.0</version>
+            <version>3.2.3</version>
         </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 30/44: SLING-6527 : Remove usage of org.json from metrics module

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 195cf163bb635744e141f2ab8b6f0341a3ad9c2c
Author: cziegeler <cz...@unknown>
AuthorDate: Mon Feb 20 08:24:46 2017 +0000

    SLING-6527 : Remove usage of org.json from metrics module
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1783721 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 271 ++++++++++-----------
 .../commons/metrics/internal/JSONReporter.java     |  19 +-
 .../commons/metrics/internal/JSONReporterTest.java |  46 ++--
 3 files changed, 170 insertions(+), 166 deletions(-)

diff --git a/pom.xml b/pom.xml
index d395d4c..7937633 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,148 +18,147 @@
   under the License.
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
 
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>29</version>
+    </parent>
 
-  <modelVersion>4.0.0</modelVersion>
+    <artifactId>org.apache.sling.commons.metrics</artifactId>
+    <packaging>bundle</packaging>
+    <version>1.2.1-SNAPSHOT</version>
 
-  <parent>
-    <groupId>org.apache.sling</groupId>
-    <artifactId>sling</artifactId>
-    <version>29</version>
-  </parent>
+    <name>Apache Sling Metrics</name>
+    <description>
+        Integrates Metric library with Sling. Refer to
+        https://sling.apache.org/documentation/bundles/metrics.html
+        for details
+    </description>
 
-  <artifactId>org.apache.sling.commons.metrics</artifactId>
-  <packaging>bundle</packaging>
-  <version>1.2.1-SNAPSHOT</version>
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
+    </scm>
 
-  <name>Apache Sling Metrics</name>
-  <description>
-    Integrates Metric library with Sling. Refer to
-    https://sling.apache.org/documentation/bundles/metrics.html
-    for details
-  </description>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-DocURL>
+                            https://sling.apache.org/documentation/bundles/metrics.html
+                        </Bundle-DocURL>
+                        <DynamicImport-Package>
+                            javax.servlet,
+                            javax.servlet.http;version="[2.3,3)",
+                            org.apache.commons.io.output;version="[2.4.0,3)",
+                            org.apache.felix.inventory;version="[1.0.0,2)"
+                        </DynamicImport-Package>
+                        <Embed-Dependency>
+                             org.apache.felix.utils;inline=org/apache/felix/utils/json/JSONWriter**
+                        </Embed-Dependency>
+                    </instructions>
+                    <!-- Export SCR metadata to classpath to have them available in unit tests -->
+                    <exportScr>true</exportScr>
+                </configuration>
+                <executions>
+                    <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
+                    <execution>
+                        <id>scr-metadata</id>
+                        <goals>
+                            <goal>manifest</goal>
+                        </goals>
+                        <configuration>
+                            <supportIncrementalBuild>true</supportIncrementalBuild>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 
-  <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
-  </scm>
+    <dependencies>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.dropwizard.metrics</groupId>
+            <artifactId>metrics-core</artifactId>
+            <version>3.1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>javax.servlet-api</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+        </dependency>
 
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.inventory</artifactId>
+            <version>1.0.2</version>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.2</version>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.utils</artifactId>
+            <version>1.9.0</version>
+            <optional>true</optional>
+        </dependency>
 
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <extensions>true</extensions>
-        <configuration>
-          <instructions>
-            <Bundle-DocURL>
-              https://sling.apache.org/documentation/bundles/metrics.html
-            </Bundle-DocURL>
-            <DynamicImport-Package>
-              javax.servlet,
-              javax.servlet.http;version="[2.3,3)",
-              org.apache.commons.io.output;version="[2.4.0,3)",
-              org.apache.felix.inventory;version="[1.0.0,2)"
-            </DynamicImport-Package>
-          </instructions>
-          <!-- Export SCR metadata to classpath to have them available in unit tests -->
-          <exportScr>true</exportScr>
-        </configuration>
-        <executions>
-          <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
-          <execution>
-            <id>scr-metadata</id>
-            <goals>
-              <goal>manifest</goal>
-            </goals>
-            <configuration>
-              <supportIncrementalBuild>true</supportIncrementalBuild>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>io.dropwizard.metrics</groupId>
-      <artifactId>metrics-core</artifactId>
-      <version>3.1.0</version>
-    </dependency>
-    <dependency>
-      <groupId>javax.servlet</groupId>
-      <artifactId>javax.servlet-api</artifactId>
-      <optional>true</optional>
-    </dependency>
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>osgi.core</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>osgi.cmpn</artifactId>
-    </dependency>
-
-    <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.apache.felix.inventory</artifactId>
-      <version>1.0.2</version>
-      <optional>true</optional>
-    </dependency>
-    <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
-      <version>2.2</version>
-      <optional>true</optional>
-    </dependency>
-    <dependency>
-      <groupId>org.json</groupId>
-      <artifactId>json</artifactId>
-      <version>20090211</version>
-      <optional>true</optional>
-    </dependency>
-
-    <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-all</artifactId>
-      <version>1.3</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.sling</groupId>
-      <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-      <version>2.1.0</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.mockito</groupId>
-      <artifactId>mockito-core</artifactId>
-      <version>1.10.19</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-simple</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>net.sourceforge.htmlunit</groupId>
-      <artifactId>htmlunit</artifactId>
-      <version>2.12</version>
-      <scope>test</scope>
-    </dependency>
-
-  </dependencies>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-all</artifactId>
+            <version>1.3</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
+            <version>2.1.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>1.10.19</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>net.sourceforge.htmlunit</groupId>
+            <artifactId>htmlunit</artifactId>
+            <version>2.12</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
index 9c631f7..8e630d0 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
@@ -20,6 +20,7 @@
 package org.apache.sling.commons.metrics.internal;
 
 import java.io.Closeable;
+import java.io.IOException;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.util.Locale;
@@ -27,6 +28,8 @@ import java.util.Map;
 import java.util.SortedMap;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.felix.utils.json.JSONWriter;
+
 import com.codahale.metrics.ConsoleReporter;
 import com.codahale.metrics.Counter;
 import com.codahale.metrics.Gauge;
@@ -37,8 +40,6 @@ import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.Reporter;
 import com.codahale.metrics.Snapshot;
 import com.codahale.metrics.Timer;
-import org.json.JSONException;
-import org.json.JSONWriter;
 
 class JSONReporter implements Reporter, Closeable {
 
@@ -147,7 +148,7 @@ class JSONReporter implements Reporter, Closeable {
                     registry.getHistograms(filter),
                     registry.getMeters(filter),
                     registry.getTimers(filter));
-        } catch (JSONException e) {
+        } catch (IOException e) {
             throw new RuntimeException(e);
         }
     }
@@ -159,7 +160,7 @@ class JSONReporter implements Reporter, Closeable {
 
     private void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters,
                         SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters,
-                        SortedMap<String, Timer> timers) throws JSONException {
+                        SortedMap<String, Timer> timers) throws IOException {
         json.object();
         if (!gauges.isEmpty()) {
             json.key("guages").object();
@@ -205,7 +206,7 @@ class JSONReporter implements Reporter, Closeable {
 
     }
 
-    private void printTimer(Map.Entry<String, Timer> e) throws JSONException {
+    private void printTimer(Map.Entry<String, Timer> e) throws IOException {
         json.key(e.getKey()).object();
         Timer timer = e.getValue();
         Snapshot snapshot = timer.getSnapshot();
@@ -233,7 +234,7 @@ class JSONReporter implements Reporter, Closeable {
         json.endObject();
     }
 
-    private void printMeter(Map.Entry<String, Meter> e) throws JSONException {
+    private void printMeter(Map.Entry<String, Meter> e) throws IOException {
         json.key(e.getKey()).object();
         Meter meter = e.getValue();
         json.key("count").value(e.getValue().getCount());
@@ -245,7 +246,7 @@ class JSONReporter implements Reporter, Closeable {
         json.endObject();
     }
 
-    private void printHistogram(Map.Entry<String, Histogram> e) throws JSONException {
+    private void printHistogram(Map.Entry<String, Histogram> e) throws IOException {
         json.key(e.getKey()).object();
         json.key("count").value(e.getValue().getCount());
 
@@ -264,13 +265,13 @@ class JSONReporter implements Reporter, Closeable {
         json.endObject();
     }
 
-    private void printCounter(Map.Entry<String, Counter> e) throws JSONException {
+    private void printCounter(Map.Entry<String, Counter> e) throws IOException {
         json.key(e.getKey()).object();
         json.key("count").value(e.getValue().getCount());
         json.endObject();
     }
 
-    private void printGauge(Map.Entry<String, Gauge> e) throws JSONException {
+    private void printGauge(Map.Entry<String, Gauge> e) throws IOException {
         json.key(e.getKey()).object();
         Object v = e.getValue().getValue();
         json.key("value").value(jsonSafeValue(v));
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
index 1f13872..49a6b46 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
@@ -19,21 +19,24 @@
 
 package org.apache.sling.commons.metrics.internal;
 
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
 import java.io.PrintStream;
 import java.io.StringWriter;
+import java.util.Map;
 
-import com.codahale.metrics.Gauge;
-import com.codahale.metrics.JvmAttributeGaugeSet;
-import com.codahale.metrics.MetricRegistry;
 import org.apache.commons.io.output.WriterOutputStream;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.apache.felix.utils.json.JSONParser;
 import org.junit.Test;
 
-import static org.junit.Assert.assertTrue;
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.JvmAttributeGaugeSet;
+import com.codahale.metrics.MetricRegistry;
 
 public class JSONReporterTest {
 
+    @SuppressWarnings("unchecked")
     @Test
     public void jsonOutput() throws Exception {
         MetricRegistry registry = new MetricRegistry();
@@ -43,21 +46,22 @@ public class JSONReporterTest {
         registry.counter("test4").inc(9);
         registry.registerAll(new JvmAttributeGaugeSet());
 
-        JSONObject json = getJSON(registry);
+        Map<String, Object> json = getJSON(registry);
 
-        assertTrue(json.has("meters"));
-        assertTrue(json.has("guages"));
-        assertTrue(json.has("timers"));
-        assertTrue(json.has("counters"));
-        assertTrue(json.has("histograms"));
-        assertTrue(json.has("meters"));
+        assertTrue(json.containsKey("meters"));
+        assertTrue(json.containsKey("guages"));
+        assertTrue(json.containsKey("timers"));
+        assertTrue(json.containsKey("counters"));
+        assertTrue(json.containsKey("histograms"));
+        assertTrue(json.containsKey("meters"));
 
-        assertTrue(json.getJSONObject("meters").has("test1"));
-        assertTrue(json.getJSONObject("timers").has("test2"));
-        assertTrue(json.getJSONObject("counters").has("test4"));
-        assertTrue(json.getJSONObject("histograms").has("test3"));
+        assertTrue(((Map<String, Object>)json.get("meters")).containsKey("test1"));
+        assertTrue(((Map<String, Object>)json.get("timers")).containsKey("test2"));
+        assertTrue(((Map<String, Object>)json.get("counters")).containsKey("test4"));
+        assertTrue(((Map<String, Object>)json.get("histograms")).containsKey("test3"));
     }
 
+    @SuppressWarnings("unchecked")
     @Test
     public void nan_value() throws Exception{
         MetricRegistry registry = new MetricRegistry();
@@ -70,18 +74,18 @@ public class JSONReporterTest {
         });
 
 
-        JSONObject json = getJSON(registry);
-        assertTrue(json.getJSONObject("guages").has("test"));
+        Map<String, Object> json = getJSON(registry);
+        assertTrue(((Map<String, Object>)json.get("guages")).containsKey("test"));
     }
 
-    private static JSONObject getJSON(MetricRegistry registry) throws JSONException {
+    private static Map<String, Object> getJSON(MetricRegistry registry) throws IOException {
         StringWriter sw = new StringWriter();
         JSONReporter reporter = JSONReporter.forRegistry(registry)
                 .outputTo(new PrintStream(new WriterOutputStream(sw)))
                 .build();
         reporter.report();
         reporter.close();
-        return new JSONObject(sw.toString());
+        return new JSONParser(sw.toString()).getParsed();
     }
 
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 09/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit a290a59aacfc9999e3bd210fb7b4130936edb529
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 09:38:17 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Add doc link url
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723497 13f79535-47bb-0310-9956-ffa450edef68
---
 README.md | 5 +++++
 pom.xml   | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b1d19ca
--- /dev/null
+++ b/README.md
@@ -0,0 +1,5 @@
+# Apache Sling Metrics
+
+Refer to [Sling Metrics][1]
+
+[1]: https://sling.apache.org/documentation/bundles/metrics.html
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index aec2637..641d996 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,9 @@
 
   <name>Apache Sling Metrics</name>
   <description>
-    Integrates Metric library http://metrics.dropwizard.io/ with Sling
+    Integrates Metric library with Sling. Refer to
+    https://sling.apache.org/documentation/bundles/metrics.html
+    for details
   </description>
 
   <scm>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 13/44: [maven-release-plugin] prepare release org.apache.sling.commons.metrics-0.0.2

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 32d29af054fbc83a1d77e880376de2639a72d71b
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 14:03:25 2016 +0000

    [maven-release-plugin] prepare release org.apache.sling.commons.metrics-0.0.2
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723547 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4302243..a031a78 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
 
   <artifactId>org.apache.sling.commons.metrics</artifactId>
   <packaging>bundle</packaging>
-  <version>0.0.1-SNAPSHOT</version>
+  <version>0.0.2</version>
 
   <name>Apache Sling Metrics</name>
   <description>
@@ -40,9 +40,9 @@
   </description>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-0.0.2</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-0.0.2</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.commons.metrics-0.0.2</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 41/44: SLING-7062 - Commons metrics inventory closes zip

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 49825c09eef5242c9d6ffa3f65004c229a66af48
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Aug 21 05:05:02 2017 +0000

    SLING-7062 - Commons metrics inventory closes zip
    
    Instead of closing just flush the internal writer
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1805597 13f79535-47bb-0310-9956-ffa450edef68
---
 .../commons/metrics/internal/JSONReporter.java     |  2 +-
 .../internal/MetricWebConsolePluginTest.java       | 39 +++++++++++++++++++++-
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
index d501fb2..1b24b3e 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
@@ -155,7 +155,7 @@ class JSONReporter implements Reporter, Closeable {
 
     @Override
     public void close(){
-        pw.close();
+        pw.flush();
     }
 
     private void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters,
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
index 6b73d91..8f0c3ce 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
@@ -21,6 +21,7 @@ package org.apache.sling.commons.metrics.internal;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.io.Writer;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -37,6 +38,7 @@ import com.gargoylesoftware.htmlunit.html.HTMLParser;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import com.gargoylesoftware.htmlunit.html.HtmlTable;
 import org.apache.felix.inventory.Format;
+import org.apache.felix.utils.json.JSONParser;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.Rule;
@@ -49,6 +51,9 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 public class MetricWebConsolePluginTest {
@@ -111,11 +116,30 @@ public class MetricWebConsolePluginTest {
         activatePlugin();
 
         StringWriter sw = new StringWriter();
-        plugin.print(new PrintWriter(sw), Format.TEXT, false);
+        PrintWriter pw = spy(new PrintWriter(sw));
+        plugin.print(pw, Format.TEXT, false);
 
         String out = sw.toString();
         assertThat(out, containsString("foo:test1"));
         assertThat(out, containsString("Meters"));
+        verify(pw, never()).close();
+    }
+
+    @Test
+    public void inventory_json() throws Exception{
+        MetricRegistry reg1 = new MetricRegistry();
+        reg1.meter("test1").mark(5);
+        context.registerService(MetricRegistry.class, reg1, regProps("foo"));
+
+        activatePlugin();
+
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = spy(new PrintWriter(sw));
+        plugin.print(pw, Format.JSON, false);
+
+        Map<String, Object> json = new JSONParser(sw.toString()).getParsed();
+        assertTrue(json.containsKey("meters"));
+        verify(pw, never()).close();
     }
 
     @Test
@@ -160,4 +184,17 @@ public class MetricWebConsolePluginTest {
     private void activatePlugin() {
         MockOsgi.activate(plugin, context.bundleContext(), Collections.<String, Object>emptyMap());
     }
+
+    private static class CloseRecordingWriter extends PrintWriter {
+
+
+        public CloseRecordingWriter(Writer out) {
+            super(out);
+        }
+
+        @Override
+        public void close() {
+            super.close();
+        }
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 26/44: SLING-5966 - Add Gauge support to metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 5fd7b2c8f5fb74083d431743620886e969113888
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Nov 17 06:06:36 2016 +0000

    SLING-5966 - Add Gauge support to metrics
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1770122 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/commons/metrics/Gauge.java    |  54 ++++++++++
 .../commons/metrics/internal/GaugeManager.java     | 119 +++++++++++++++++++++
 .../metrics/internal/MetricsServiceImpl.java       |   5 +
 .../apache/sling/commons/metrics/package-info.java |   2 +-
 .../metrics/internal/MetricServiceTest.java        |  31 ++++++
 5 files changed, 210 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/Gauge.java b/src/main/java/org/apache/sling/commons/metrics/Gauge.java
new file mode 100644
index 0000000..ac723a6
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/metrics/Gauge.java
@@ -0,0 +1,54 @@
+/*
+ * 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.sling.commons.metrics;
+
+import aQute.bnd.annotation.ConsumerType;
+
+/**
+ * A gauge metric is an instantaneous reading of a particular value. To instrument a queue's depth,
+ * for example:<br>
+ * <pre><code>
+ * final Queue&lt;String&gt; queue = new ConcurrentLinkedQueue&lt;String&gt;();
+ * final Gauge&lt;Integer&gt; queueDepth = new Gauge&lt;Integer&gt;() {
+ *     public Integer getValue() {
+ *         return queue.size();
+ *     }
+ * };
+ * </code></pre>
+ *
+ * <p> A Gauge instance should be registered with OSGi ServiceRegistry with {@code Gauge#NAME} set
+ * to Gauge name. Then the Gauge instance would be registered with MetricService via whiteboard
+ * pattern
+ *
+ * @param <T> the type of the metric's value
+ */
+@ConsumerType
+public interface Gauge<T> {
+    /**
+     * Service property name which determines the name of the Gauge
+     */
+    String NAME = "name";
+    /**
+     * Returns the metric's current value.
+     *
+     * @return the metric's current value
+     */
+    T getValue();
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/GaugeManager.java b/src/main/java/org/apache/sling/commons/metrics/internal/GaugeManager.java
new file mode 100644
index 0000000..bc48066
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/GaugeManager.java
@@ -0,0 +1,119 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import java.io.Closeable;
+import java.util.Collections;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.sling.commons.metrics.Gauge;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class GaugeManager implements ServiceTrackerCustomizer<Gauge, GaugeManager.GaugeImpl>, Closeable {
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private final MetricRegistry registry;
+    private final BundleMetricsMapper mapper;
+    private final BundleContext bundleContext;
+    private ServiceTracker<Gauge, GaugeImpl> tracker;
+
+    public GaugeManager(BundleContext context, MetricRegistry registry, BundleMetricsMapper mapper) {
+        this.registry = registry;
+        this.mapper = mapper;
+        this.bundleContext = context;
+        this.tracker = new ServiceTracker<>(context, Gauge.class, this);
+        tracker.open();
+    }
+
+    //~-------------------------------------< ServiceTrackerCustomizer >
+
+    @Override
+    public GaugeImpl addingService(ServiceReference<Gauge> reference) {
+        String name = (String) reference.getProperty(Gauge.NAME);
+        if (name == null){
+            log.warn("A {} service is registered without [{}] property. This Gauge would not be " +
+                    "registered with MetricsRegistry", reference, Gauge.NAME);
+            return null;
+        }
+
+        Gauge gauge = bundleContext.getService(reference);
+        GaugeImpl gaugeImpl = new GaugeImpl(name, gauge);
+        register(reference, gaugeImpl);
+        return gaugeImpl;
+    }
+
+    @Override
+    public void modifiedService(ServiceReference<Gauge> reference, GaugeImpl service) {
+        String name = (String) reference.getProperty(Gauge.NAME);
+        if (name == null){
+            return;
+        }
+
+        if (!name.equals(service.name)){
+            unregister(service);
+            service.name = name;
+            register(reference, service);
+        }
+    }
+
+    @Override
+    public void removedService(ServiceReference<Gauge> reference, GaugeImpl service) {
+        unregister(service);
+    }
+
+    //~------------------------------------< Closeable >
+
+    @Override
+    public void close() {
+        tracker.close();
+    }
+
+    //~-------------------------------------< Internal >
+
+    private void unregister(GaugeImpl service) {
+        mapper.unregister(Collections.singleton(service.name));
+    }
+
+    private void register(ServiceReference<Gauge> reference, GaugeImpl gaugeImpl) {
+        mapper.addMapping(gaugeImpl.name, reference.getBundle());
+        registry.register(gaugeImpl.name, gaugeImpl);
+    }
+
+    //~--------------------------------------< GaugeImpl >
+
+    public static class GaugeImpl implements com.codahale.metrics.Gauge {
+        String name;
+        final Gauge gauge;
+
+        public GaugeImpl(String name, Gauge gauge) {
+            this.name = name;
+            this.gauge = gauge;
+        }
+
+        @Override
+        public Object getValue() {
+            return gauge.getValue();
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
index 03efcee..1bc6514 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
@@ -54,6 +54,7 @@ public class MetricsServiceImpl implements MetricsService {
     private final ConcurrentMap<String, Metric> metrics = new ConcurrentHashMap<>();
     private final MetricRegistry registry = new MetricRegistry();
     private final BundleMetricsMapper metricsMapper = new BundleMetricsMapper(registry);
+    private GaugeManager gaugeManager;
 
     @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
     private MBeanServer server;
@@ -64,6 +65,8 @@ public class MetricsServiceImpl implements MetricsService {
     private void activate(BundleContext context, Map<String, Object> config) {
         enableJMXReporter();
 
+        gaugeManager = new GaugeManager(context, registry, metricsMapper);
+
         final Dictionary<String, String> svcProps = new Hashtable<>();
         svcProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics Service");
         svcProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
@@ -84,6 +87,8 @@ public class MetricsServiceImpl implements MetricsService {
         }
         regs.clear();
 
+        gaugeManager.close();
+
         metrics.clear();
 
         if (reporter != null) {
diff --git a/src/main/java/org/apache/sling/commons/metrics/package-info.java b/src/main/java/org/apache/sling/commons/metrics/package-info.java
index aa5623b..5b24541 100644
--- a/src/main/java/org/apache/sling/commons/metrics/package-info.java
+++ b/src/main/java/org/apache/sling/commons/metrics/package-info.java
@@ -22,7 +22,7 @@
  *
  * @version 1.0
  */
-@Version("1.0")
+@Version("1.1.0")
 @Export(optional = "provide:=true")
 package org.apache.sling.commons.metrics;
 
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
index 72a8e02..a8af34a 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
@@ -31,20 +31,25 @@ import javax.management.QueryExp;
 import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.MetricRegistry;
 import org.apache.sling.commons.metrics.Counter;
+import org.apache.sling.commons.metrics.Gauge;
 import org.apache.sling.commons.metrics.Histogram;
 import org.apache.sling.commons.metrics.Meter;
 import org.apache.sling.commons.metrics.MetricsService;
 import org.apache.sling.commons.metrics.Timer;
+import org.apache.sling.testing.mock.osgi.MapUtil;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
+import org.osgi.framework.ServiceRegistration;
 
 import static org.apache.sling.commons.metrics.internal.BundleMetricsMapper.JMX_TYPE_METRICS;
 import static org.hamcrest.Matchers.empty;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
@@ -145,6 +150,19 @@ public class MetricServiceTest {
 
     }
 
+    @Test
+    public void gaugeRegistration() throws Exception{
+        activate();
+        ServiceRegistration<Gauge> reg = context.bundleContext().registerService(Gauge.class, new TestGauge(42),
+                MapUtil.toDictionary(Gauge.NAME, "foo"));
+
+        assertTrue(getRegistry().getGauges().containsKey("foo"));
+        assertEquals(42, getRegistry().getGauges().get("foo").getValue());
+
+        reg.unregister();
+        assertFalse(getRegistry().getGauges().containsKey("foo"));
+    }
+
     private MetricRegistry getRegistry(){
         return context.getService(MetricRegistry.class);
     }
@@ -153,4 +171,17 @@ public class MetricServiceTest {
         MockOsgi.activate(service, context.bundleContext(), Collections.<String, Object>emptyMap());
     }
 
+    private static class TestGauge implements Gauge {
+        int value;
+
+        public TestGauge(int value){
+            this.value = value;
+        }
+
+        @Override
+        public Object getValue() {
+            return value;
+        }
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 08/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 2ae0fe29129d675483af9afb30b6e70e7770abfb
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 09:38:00 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Updated testcase
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723496 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/commons/metrics/internal/MetricServiceTest.java   | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
index 9dff1e9..7f1dec8 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
@@ -109,6 +109,13 @@ public class MetricServiceTest {
         assertSame(histo, service.histogram("test"));
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void sameNameDifferentTypeMetric() throws Exception{
+        activate();
+        service.histogram("test");
+        service.timer("test");
+    }
+
     private MetricRegistry getRegistry(){
         return context.getService(MetricRegistry.class);
     }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 07/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 8a5ced0953599441352adbe25d849941643618d2
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 06:50:56 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Add testcase for webconsole plugin
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723470 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |  11 ++
 .../metrics/internal/MetricWebConsolePlugin.java   |  12 +-
 .../internal/MetricWebConsolePluginTest.java       | 163 +++++++++++++++++++++
 3 files changed, 180 insertions(+), 6 deletions(-)

diff --git a/pom.xml b/pom.xml
index 281b84f..aec2637 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,6 +103,11 @@
     </dependency>
 
     <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-all</artifactId>
+      <version>1.3</version>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>
@@ -123,6 +128,12 @@
       <artifactId>slf4j-simple</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>net.sourceforge.htmlunit</groupId>
+      <artifactId>htmlunit</artifactId>
+      <version>2.12</version>
+      <scope>test</scope>
+    </dependency>
 
   </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index 8796168..f5261c5 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -169,7 +169,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
         pw.println("<br>");
         pw.println("<div class='table'>");
         pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Meters</div>");
-        pw.println("<table class='nicetable'>");
+        pw.println("<table class='nicetable' id='data-meters'>");
         pw.println("<thead>");
         pw.println("<tr>");
         pw.println("<th class='header'>Name</th>");
@@ -217,7 +217,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
         pw.println("<br>");
         pw.println("<div class='table'>");
         pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Timers</div>");
-        pw.println("<table class='nicetable'>");
+        pw.println("<table class='nicetable' id='data-timers'>");
         pw.println("<thead>");
         pw.println("<tr>");
         pw.println("<th class='header'>Name</th>");
@@ -295,7 +295,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
         pw.println("<br>");
         pw.println("<div class='table'>");
         pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Histograms</div>");
-        pw.println("<table class='nicetable'>");
+        pw.println("<table class='nicetable' id='data-histograms'>");
         pw.println("<thead>");
         pw.println("<tr>");
         pw.println("<th class='header'>Name</th>");
@@ -357,7 +357,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
         pw.println("<br>");
         pw.println("<div class='table'>");
         pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Counters</div>");
-        pw.println("<table class='nicetable'>");
+        pw.println("<table class='nicetable' id='data-counters'>");
         pw.println("<thead>");
         pw.println("<tr>");
         pw.println("<th class='header'>Name</th>");
@@ -393,7 +393,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
         pw.println("<br>");
         pw.println("<div class='table'>");
         pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Guages</div>");
-        pw.println("<table class='nicetable'>");
+        pw.println("<table class='nicetable' id='data-guages'>");
         pw.println("<thead>");
         pw.println("<tr>");
         pw.println("<th class='header'>Name</th>");
@@ -424,7 +424,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
 
     //~----------------------------------------------< internal >
 
-    private MetricRegistry getConsolidatedRegistry() {
+    MetricRegistry getConsolidatedRegistry() {
         MetricRegistry registry = new MetricRegistry();
         for (Map.Entry<ServiceReference, MetricRegistry> registryEntry : registries.entrySet()){
             String metricRegistryName = (String) registryEntry.getKey().getProperty(METRIC_REGISTRY_NAME);
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
new file mode 100644
index 0000000..296c9e6
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.codahale.metrics.JvmAttributeGaugeSet;
+import com.codahale.metrics.MetricRegistry;
+import com.gargoylesoftware.htmlunit.StringWebResponse;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.WebResponse;
+import com.gargoylesoftware.htmlunit.html.HTMLParser;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlTable;
+import org.apache.felix.inventory.Format;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class MetricWebConsolePluginTest {
+    @Rule
+    public final OsgiContext context = new OsgiContext();
+
+    private MetricWebConsolePlugin plugin = new MetricWebConsolePlugin();
+
+    private static Map<String, Object> regProps(String name) {
+        Map<String, Object> props = new HashMap<String, Object>();
+        props.put("name", name);
+        return props;
+    }
+
+    @Test
+    public void consolidatedRegistry() throws Exception {
+        MetricRegistry reg1 = new MetricRegistry();
+        reg1.meter("test1");
+        context.registerService(MetricRegistry.class, reg1, regProps("foo"));
+
+        activatePlugin();
+
+        MetricRegistry consolidated = plugin.getConsolidatedRegistry();
+
+        //Check name decoration
+        assertEquals(1, consolidated.getMetrics().size());
+        assertTrue(consolidated.getMeters().containsKey("foo:test1"));
+
+        MetricRegistry reg2 = new MetricRegistry();
+        reg2.meter("test2");
+        context.registerService(MetricRegistry.class, reg2);
+
+        //Metric Registry without name would not be decorated
+        consolidated = plugin.getConsolidatedRegistry();
+        assertEquals(2, consolidated.getMetrics().size());
+        assertTrue(consolidated.getMeters().containsKey("test2"));
+
+        //Duplicate metric in other registry should not fail. Warning log
+        //should be generated
+        MetricRegistry reg3 = new MetricRegistry();
+        reg3.meter("test2");
+        context.registerService(MetricRegistry.class, reg3);
+        consolidated = plugin.getConsolidatedRegistry();
+        assertEquals(2, consolidated.getMetrics().size());
+
+        MetricRegistry reg4 = new MetricRegistry();
+        reg4.meter("test1");
+        context.registerService(MetricRegistry.class, reg4, regProps("bar"));
+        consolidated = plugin.getConsolidatedRegistry();
+        assertTrue(consolidated.getMeters().containsKey("foo:test1"));
+        assertTrue(consolidated.getMeters().containsKey("bar:test1"));
+    }
+
+    @Test
+    public void inventory_text() throws Exception {
+        MetricRegistry reg1 = new MetricRegistry();
+        reg1.meter("test1").mark(5);
+        context.registerService(MetricRegistry.class, reg1, regProps("foo"));
+
+        activatePlugin();
+
+        StringWriter sw = new StringWriter();
+        plugin.print(new PrintWriter(sw), Format.TEXT, false);
+
+        String out = sw.toString();
+        assertThat(out, containsString("foo:test1"));
+        assertThat(out, containsString("Meters"));
+    }
+
+    @Test
+    public void webConsolePlugin() throws Exception {
+        MetricRegistry reg1 = new MetricRegistry();
+        reg1.meter("test1").mark(5);
+        reg1.timer("test2").time().close();
+        reg1.histogram("test3").update(743);
+        reg1.counter("test4").inc(9);
+        reg1.registerAll(new JvmAttributeGaugeSet());
+        context.registerService(MetricRegistry.class, reg1, regProps("foo"));
+
+        activatePlugin();
+
+        StringWriter sw = new StringWriter();
+
+        HttpServletResponse response = mock(HttpServletResponse.class);
+        when(response.getWriter()).thenReturn(new PrintWriter(sw));
+
+        plugin.doGet(mock(HttpServletRequest.class), response);
+
+        WebClient client = new WebClient();
+        WebResponse resp = new StringWebResponse(sw.toString(), WebClient.URL_ABOUT_BLANK);
+        HtmlPage page = HTMLParser.parseHtml(resp, client.getCurrentWindow());
+
+        assertTable("data-meters", page);
+        assertTable("data-counters", page);
+        assertTable("data-timers", page);
+        assertTable("data-histograms", page);
+        assertTable("data-guages", page);
+    }
+
+    private void assertTable(String name, HtmlPage page) {
+        HtmlTable table = page.getHtmlElementById(name);
+        assertNotNull(table);
+
+        //1 for header and 1 for actual metric row
+        assertThat(table.getRowCount(), greaterThanOrEqualTo(2));
+
+    }
+
+    private void activatePlugin() {
+        MockOsgi.activate(plugin, context.bundleContext(), Collections.<String, Object>emptyMap());
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 15/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 7d5b2d95f8c01d619aec91daedeeafa621c2d357
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Fri Jan 8 12:35:50 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Change the method names as per suggestion by Oliver Lietz!
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723718 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/commons/metrics/Counter.java  |  8 ++++----
 .../java/org/apache/sling/commons/metrics/NoopMetric.java    |  8 ++++----
 .../apache/sling/commons/metrics/internal/CounterImpl.java   |  8 ++++----
 .../sling/commons/metrics/internal/MetricWrapperTest.java    | 12 ++++++------
 4 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/Counter.java b/src/main/java/org/apache/sling/commons/metrics/Counter.java
index 9f4f062..8269d5b 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Counter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Counter.java
@@ -29,24 +29,24 @@ public interface Counter extends Counting, Metric{
     /**
      * Increment the counter by one.
      */
-    void inc();
+    void increment();
 
     /**
      * Decrement the counter by one.
      */
-    void dec();
+    void decrement();
 
     /**
      * Increment the counter by {@code n}.
      *
      * @param n the amount by which the counter will be increased
      */
-    void inc(long n);
+    void increment(long n);
 
     /**
      * Decrement the counter by {@code n}.
      *
      * @param n the amount by which the counter will be decreased
      */
-    void dec(long n);
+    void decrement(long n);
 }
diff --git a/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java b/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
index ed7a25b..e2aaac4 100644
--- a/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
+++ b/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
@@ -30,22 +30,22 @@ enum NoopMetric implements Counter, Histogram, Timer, Meter{
     }
 
     @Override
-    public void inc() {
+    public void increment() {
 
     }
 
     @Override
-    public void dec() {
+    public void decrement() {
 
     }
 
     @Override
-    public void inc(long n) {
+    public void increment(long n) {
 
     }
 
     @Override
-    public void dec(long n) {
+    public void decrement(long n) {
 
     }
 
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
index f929410..bda240e 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
@@ -30,22 +30,22 @@ final class CounterImpl implements Counter {
     }
 
     @Override
-    public void inc() {
+    public void increment() {
         counter.inc();
     }
 
     @Override
-    public void dec() {
+    public void decrement() {
         counter.dec();
     }
 
     @Override
-    public void inc(long n) {
+    public void increment(long n) {
         counter.inc(n);
     }
 
     @Override
-    public void dec(long n) {
+    public void decrement(long n) {
         counter.dec(n);
     }
 
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
index 5489b31..3e58123 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
@@ -40,24 +40,24 @@ public class MetricWrapperTest {
         Counter counter = registry.counter("test");
         CounterImpl counterStats = new CounterImpl(counter);
 
-        counterStats.inc();
+        counterStats.increment();
         assertEquals(1, counterStats.getCount());
         assertEquals(1, counter.getCount());
         assertEquals(1, counterStats.getCount());
 
-        counterStats.inc();
-        counterStats.inc();
+        counterStats.increment();
+        counterStats.increment();
         assertEquals(3, counterStats.getCount());
 
-        counterStats.dec();
+        counterStats.decrement();
         assertEquals(2, counterStats.getCount());
         assertEquals(2, counter.getCount());
 
-        counterStats.inc(7);
+        counterStats.increment(7);
         assertEquals(9, counterStats.getCount());
         assertEquals(9, counter.getCount());
 
-        counterStats.dec(5);
+        counterStats.decrement(5);
         assertEquals(4, counterStats.getCount());
         assertEquals(4, counter.getCount());
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 24/44: SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit dab007438844003c68e2ea80c15bbf4dd797127c
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Nov 17 05:08:41 2016 +0000

    SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans
    
    Specify type for JMX ObjectNames created for Metrics
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1770120 13f79535-47bb-0310-9956-ffa450edef68
---
 .../metrics/internal/BundleMetricsMapper.java      | 31 ++++----
 .../sling/commons/metrics/internal/JmxUtil.java    | 89 ++++++++++++++++++++++
 .../metrics/internal/BundleMetricsMapperTest.java  |  7 --
 .../commons/metrics/internal/JmxUtilTest.java      | 51 +++++++++++++
 .../metrics/internal/MetricServiceTest.java        |  3 +-
 5 files changed, 156 insertions(+), 25 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java b/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
index 9a74a1e..8bdbd45 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
@@ -19,10 +19,12 @@
 
 package org.apache.sling.commons.metrics.internal;
 
+import java.util.Hashtable;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import com.codahale.metrics.DefaultObjectNameFactory;
@@ -35,6 +37,7 @@ import org.slf4j.LoggerFactory;
 class BundleMetricsMapper implements ObjectNameFactory{
     public static final String HEADER_DOMAIN_NAME = "Sling-Metrics-Domain";
     public static final String DEFAULT_DOMAIN_NAME = "org.apache.sling";
+    static final String JMX_TYPE_METRICS = "Metrics";
     private final Logger log = LoggerFactory.getLogger(getClass());
     private final ConcurrentMap<String, Bundle> metricToBundleMapping = new ConcurrentHashMap<>();
     private final MetricRegistry registry;
@@ -58,11 +61,20 @@ class BundleMetricsMapper implements ObjectNameFactory{
 
     @Override
     public ObjectName createName(String type, String domain, String name) {
-        String mappedDomainName = safeDomainName(getDomainName(name));
+        String mappedDomainName = JmxUtil.safeDomainName(getDomainName(name));
         if (mappedDomainName == null) {
             mappedDomainName = domain;
         }
-        return defaultFactory.createName(type, mappedDomainName, name);
+
+        Hashtable<String, String> table = new Hashtable<String, String>();
+        table.put("type", JMX_TYPE_METRICS);
+        table.put("name", JmxUtil.quoteValueIfRequired(name));
+        try {
+            return new ObjectName(mappedDomainName, table);
+        } catch (MalformedObjectNameException e) {
+            log.warn("Unable to register {} {}", type, name, e);
+            throw new RuntimeException(e);
+        }
     }
 
     private String getDomainName(String name) {
@@ -84,19 +96,4 @@ class BundleMetricsMapper implements ObjectNameFactory{
         return bundle.getSymbolicName();
     }
 
-    static String safeDomainName(String name){
-        if (name == null){
-            return null;
-        }
-
-        name = name.trim();
-
-        //Taken from javax.management.ObjectName.isDomain()
-        //Following are special chars in domain name
-        name = name.replace(':', '_');
-        name = name.replace('*', '_');
-        name = name.replace('?', '_');
-        name = name.replace('\n', '_');
-        return name;
-    }
 }
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/JmxUtil.java b/src/main/java/org/apache/sling/commons/metrics/internal/JmxUtil.java
new file mode 100644
index 0000000..9938631
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/JmxUtil.java
@@ -0,0 +1,89 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+/**
+ * Utility methods related to JMX
+ */
+final class JmxUtil {
+
+    /**
+     * Checks if the passed value string can be used as is as part of
+     * JMX {@link javax.management.ObjectName} If it cannot be used then
+     * it would return a quoted string which is then safe to be used
+     * as part of ObjectName.
+     *
+     * <p>This is meant to avoid unnecessary quoting of value</p>
+     *
+     * @param unquotedValue to quote if required
+     * @return passed value or quoted value if required
+     */
+    public static String quoteValueIfRequired(String unquotedValue) {
+        String result;
+        String quotedValue = ObjectName.quote(unquotedValue);
+
+        //Check if some chars are escaped or not. In that case
+        //length of quoted string (excluding quotes) would differ
+        if (quotedValue.substring(1, quotedValue.length() - 1).equals(unquotedValue)) {
+            ObjectName on = null;
+            try {
+                //Quoting logic in ObjectName does not escape ',', '='
+                //etc. So try now by constructing ObjectName. If that
+                //passes then value can be used as safely
+
+                //Also we cannot just rely on ObjectName as it treats
+                //*, ? as pattern chars and which should ideally be escaped
+                on = new ObjectName("dummy", "dummy", unquotedValue);
+            } catch (MalformedObjectNameException ignore) {
+                //ignore
+            }
+
+            if (on != null){
+                result = unquotedValue;
+            } else {
+                result = quotedValue;
+            }
+        } else {
+            //Some escaping done. So do quote
+            result = quotedValue;
+        }
+        return result;
+    }
+
+
+    public static String safeDomainName(String name){
+        if (name == null){
+            return null;
+        }
+
+        name = name.trim();
+
+        //Taken from javax.management.ObjectName.isDomain()
+        //Following are special chars in domain name
+        name = name.replace(':', '_');
+        name = name.replace('*', '_');
+        name = name.replace('?', '_');
+        name = name.replace('\n', '_');
+        return name;
+    }
+}
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java
index d34357a..ae08a05 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapperTest.java
@@ -66,12 +66,5 @@ public class BundleMetricsMapperTest {
         assertEquals("com.test", name.getDomain());
     }
 
-    @Test
-    public void safeDomainName() throws Exception{
-        assertEquals("com.foo", BundleMetricsMapper.safeDomainName("com.foo"));
-        assertEquals("com_foo", BundleMetricsMapper.safeDomainName("com:foo"));
-        assertEquals("com_foo", BundleMetricsMapper.safeDomainName("com?foo"));
-        assertEquals("com_foo", BundleMetricsMapper.safeDomainName("com*foo"));
-    }
 
 }
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/JmxUtilTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/JmxUtilTest.java
new file mode 100644
index 0000000..9db25c7
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/JmxUtilTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class JmxUtilTest {
+
+    @Test
+    public void quotation() throws Exception{
+        assertEquals("text", JmxUtil.quoteValueIfRequired("text"));
+        TestCase.assertEquals("", JmxUtil.quoteValueIfRequired(""));
+        assertTrue(JmxUtil.quoteValueIfRequired("text*with?chars").startsWith("\""));
+    }
+
+    @Test
+    public void quoteAndComma() throws Exception{
+        assertTrue(JmxUtil.quoteValueIfRequired("text,withComma").startsWith("\""));
+        assertTrue(JmxUtil.quoteValueIfRequired("text=withEqual").startsWith("\""));
+    }
+
+    @Test
+    public void safeDomainName() throws Exception{
+        assertEquals("com.foo", JmxUtil.safeDomainName("com.foo"));
+        assertEquals("com_foo", JmxUtil.safeDomainName("com:foo"));
+        assertEquals("com_foo", JmxUtil.safeDomainName("com?foo"));
+        assertEquals("com_foo", JmxUtil.safeDomainName("com*foo"));
+    }
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
index ca76690..72a8e02 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
@@ -41,6 +41,7 @@ import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
 
+import static org.apache.sling.commons.metrics.internal.BundleMetricsMapper.JMX_TYPE_METRICS;
 import static org.hamcrest.Matchers.empty;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.not;
@@ -134,7 +135,7 @@ public class MetricServiceTest {
         Meter meter = service.meter("test");
         assertNotNull(meter);
         QueryExp q = Query.isInstanceOf(Query.value(JmxReporter.JmxMeterMBean.class.getName()));
-        Set<ObjectName> names = server.queryNames(new ObjectName("org.apache.sling:name=*"), q);
+        Set<ObjectName> names = server.queryNames(new ObjectName("org.apache.sling:name=*,type="+ JMX_TYPE_METRICS), q);
         assertThat(names, is(not(empty())));
 
         MockOsgi.deactivate(service, context.bundleContext());

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 25/44: SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 0600f8fc9cb693e3aa0cf6a252fc8228e89271ad
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Nov 17 05:11:17 2016 +0000

    SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans
    
    Remove unused instance
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1770121 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/commons/metrics/internal/BundleMetricsMapper.java    | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java b/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
index 8bdbd45..a4ec010 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/BundleMetricsMapper.java
@@ -27,7 +27,6 @@ import java.util.concurrent.ConcurrentMap;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
-import com.codahale.metrics.DefaultObjectNameFactory;
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.ObjectNameFactory;
 import org.osgi.framework.Bundle;
@@ -41,7 +40,6 @@ class BundleMetricsMapper implements ObjectNameFactory{
     private final Logger log = LoggerFactory.getLogger(getClass());
     private final ConcurrentMap<String, Bundle> metricToBundleMapping = new ConcurrentHashMap<>();
     private final MetricRegistry registry;
-    private final ObjectNameFactory defaultFactory = new DefaultObjectNameFactory();
 
     BundleMetricsMapper(MetricRegistry registry) {
         this.registry = registry;
@@ -66,7 +64,7 @@ class BundleMetricsMapper implements ObjectNameFactory{
             mappedDomainName = domain;
         }
 
-        Hashtable<String, String> table = new Hashtable<String, String>();
+        Hashtable<String, String> table = new Hashtable<>();
         table.put("type", JMX_TYPE_METRICS);
         table.put("name", JmxUtil.quoteValueIfRequired(name));
         try {

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 43/44: SLING-7047 - Update Dropwizard Metrics bundles to 3.2 to eliminate sun.misc dependency.

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 079634600e33ca6d6c7fdea71ec8f4d658ffd5b3
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Mon Aug 21 10:15:38 2017 +0000

    SLING-7047 - Update Dropwizard Metrics bundles to 3.2 to eliminate sun.misc dependency.
    
    Remove the explicit import statement
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1805618 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index d7f4a98..029da8a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,10 +58,6 @@
                         <Bundle-DocURL>
                             https://sling.apache.org/documentation/bundles/metrics.html
                         </Bundle-DocURL>
-                        <Import-Package>
-                            com.codahale.metrics*;version="[3.1, 4)",
-                            *
-                        </Import-Package>
                         <DynamicImport-Package>
                             javax.servlet,
                             javax.servlet.http;version="[2.3,3)",

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 22/44: SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit b945e6633d8cd06027399674c7faf55b0b911d0f
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Nov 17 05:08:12 2016 +0000

    SLING-5443 - Review the naming conventions used by JMXReporter to register the Metric MBeans
    
    Update the osgi-mock version to make use of ServiceFactory support
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1770118 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                                        | 10 +++++-----
 .../sling/commons/metrics/internal/MetricServiceTest.java      |  6 +++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/pom.xml b/pom.xml
index 8ca2ac8..3a45b75 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,14 +90,14 @@
     </dependency>
     <dependency>
       <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.core</artifactId>
-      <version>4.3.1</version>
+      <artifactId>osgi.core</artifactId>
+      <version>6.0.0</version>
       <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.compendium</artifactId>
-      <version>4.3.1</version>
+      <artifactId>osgi.cmpn</artifactId>
+      <version>6.0.0</version>
       <scope>provided</scope>
     </dependency>
 
@@ -134,7 +134,7 @@
     <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
-      <version>1.3.0</version>
+      <version>2.1.0</version>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
index 5885426..ca76690 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
@@ -58,7 +58,7 @@ public class MetricServiceTest {
 
     @After
     public void deactivate(){
-        MockOsgi.deactivate(service);
+        MockOsgi.deactivate(service, context.bundleContext());
     }
 
     @Test
@@ -70,7 +70,7 @@ public class MetricServiceTest {
 
         assertNotNull(service.adaptTo(MetricRegistry.class));
 
-        MockOsgi.deactivate(service);
+        MockOsgi.deactivate(service, context.bundleContext());
 
         assertNull(context.getService(MetricRegistry.class));
         assertNull(context.getService(MetricsService.class));
@@ -137,7 +137,7 @@ public class MetricServiceTest {
         Set<ObjectName> names = server.queryNames(new ObjectName("org.apache.sling:name=*"), q);
         assertThat(names, is(not(empty())));
 
-        MockOsgi.deactivate(service);
+        MockOsgi.deactivate(service, context.bundleContext());
 
         names = server.queryNames(new ObjectName("org.apache.sling:name=*"), q);
         assertThat(names, is(empty()));

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 04/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 8ffd002dea23b378d5c83a87d6bceeeb1a0bbb78
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 05:09:22 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Use enum variant for singleton access
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723460 13f79535-47bb-0310-9956-ffa450edef68
---
 src/main/java/org/apache/sling/commons/metrics/NoopMetric.java | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java b/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
index f1595ff..ed7a25b 100644
--- a/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
+++ b/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
@@ -21,8 +21,9 @@ package org.apache.sling.commons.metrics;
 
 import java.util.concurrent.TimeUnit;
 
-final class NoopMetric implements Counter, Histogram, Timer, Meter{
-    public static final NoopMetric INSTANCE = new NoopMetric();
+enum NoopMetric implements Counter, Histogram, Timer, Meter{
+    INSTANCE;
+
     @Override
     public long getCount() {
         return 0;
@@ -78,8 +79,8 @@ final class NoopMetric implements Counter, Histogram, Timer, Meter{
         return null;
     }
 
-    private static final class NoopContext implements Context {
-        public static final NoopContext INSTANCE = new NoopContext();
+    private enum NoopContext implements Context {
+        INSTANCE;
 
         @Override
         public long stop() {

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 17/44: [maven-release-plugin] prepare for next development iteration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 437036c6d94dc2da48255a4b2e1d0b75692121ae
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Tue Jan 12 05:04:08 2016 +0000

    [maven-release-plugin] prepare for next development iteration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1724155 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 3e038d8..c76858f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
 
   <artifactId>org.apache.sling.commons.metrics</artifactId>
   <packaging>bundle</packaging>
-  <version>1.0.0</version>
+  <version>1.0.1-SNAPSHOT</version>
 
   <name>Apache Sling Metrics</name>
   <description>
@@ -40,9 +40,9 @@
   </description>
 
   <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.0.0</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.0.0</developerConnection>
-    <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.commons.metrics-1.0.0</url>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
   </scm>
 
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 12/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 43662e4ff1412f5183a32d9712f1a7639f861b9d
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 11:31:58 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Allow adapting MetricService to MetricRegistry
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723518 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/commons/metrics/MetricsService.java | 16 ++++++++++++++++
 .../commons/metrics/internal/MetricsServiceImpl.java     |  9 +++++++++
 .../commons/metrics/internal/MetricServiceTest.java      |  2 ++
 3 files changed, 27 insertions(+)

diff --git a/src/main/java/org/apache/sling/commons/metrics/MetricsService.java b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
index 7848861..56e87e6 100644
--- a/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
+++ b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
@@ -50,6 +50,11 @@ public interface MetricsService {
         public Meter meter(String name) {
             return NoopMetric.INSTANCE;
         }
+
+        @Override
+        public <A> A adaptTo(Class<A> type) {
+            return null;
+        }
     };
 
     /**
@@ -87,4 +92,15 @@ public interface MetricsService {
      * @return a new {@link Meter}
      */
     Meter meter(String name);
+
+    /**
+     * Adapts the service to the specified type. This can be used to
+     * get instance to underlying {@code MetricRegistry}
+     *
+     * @param <A> The type to which this metric is to be adapted.
+     * @param type Class object for the type to which this metric is to be adapted.
+     * @return The object, of the specified type, to which this metric has been adapted
+     * or null if this metric cannot be adapted to the specified type.
+     */
+    <A> A adaptTo(Class<A> type);
 }
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
index 729d555..a0e0520 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
@@ -115,6 +115,15 @@ public class MetricsServiceImpl implements MetricsService {
     }
 
     @SuppressWarnings("unchecked")
+    @Override
+    public <A> A adaptTo(Class<A> type) {
+        if (type == MetricRegistry.class){
+            return (A) registry;
+        }
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
     private <T extends Metric> T getOrAdd(String name, MetricBuilder<T> builder) {
         final Metric metric = metrics.get(name);
         if (builder.isInstance(metric)) {
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
index 7f1dec8..a028abf 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
@@ -59,6 +59,8 @@ public class MetricServiceTest {
         assertNotNull(context.getService(MetricRegistry.class));
         assertNotNull(context.getService(MetricsService.class));
 
+        assertNotNull(service.adaptTo(MetricRegistry.class));
+
         MockOsgi.deactivate(service);
 
         assertNull(context.getService(MetricRegistry.class));

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 11/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 319a7c8d68b9b48403dff5c95fa54098ab353193
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 10:26:05 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Use proper version ranges for import
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723507 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4e6a5f0..4302243 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,9 +59,9 @@
             </Bundle-DocURL>
             <DynamicImport-Package>
               javax.servlet,
-              javax.servlet.http;version=2.3,
-              org.apache.commons.io.output;version=2.4.0,
-              org.apache.felix.inventory;version=1.0
+              javax.servlet.http;version="[2.3,3)",
+              org.apache.commons.io.output;version="[2.4.0,3)",
+              org.apache.felix.inventory;version="[1.0.0,2)"
             </DynamicImport-Package>
           </instructions>
         </configuration>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 34/44: SLING-6702 - rename the existing MetricsServiceFactory

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit ddc272d0684b6eee4ffaf5f76c788566489c4b46
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Mar 23 14:01:20 2017 +0000

    SLING-6702 - rename the existing MetricsServiceFactory
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1788246 13f79535-47bb-0310-9956-ffa450edef68
---
 ...{MetricsServiceFactory.java => InternalMetricsServiceFactory.java} | 4 ++--
 .../org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java | 2 +-
 .../sling/commons/metrics/internal/MetricsServiceFactoryTest.java     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactory.java b/src/main/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactory.java
similarity index 94%
rename from src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactory.java
rename to src/main/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactory.java
index b9d8bb6..c3f7fff 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactory.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/InternalMetricsServiceFactory.java
@@ -32,11 +32,11 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
 
-class MetricsServiceFactory implements ServiceFactory<MetricsService> {
+class InternalMetricsServiceFactory implements ServiceFactory<MetricsService> {
     private final MetricsService delegate;
     private final BundleMetricsMapper metricsMapper;
 
-    public MetricsServiceFactory(MetricsService delegate, BundleMetricsMapper metricsMapper) {
+    public InternalMetricsServiceFactory(MetricsService delegate, BundleMetricsMapper metricsMapper) {
         this.delegate = delegate;
         this.metricsMapper = metricsMapper;
     }
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
index cec64bb..5d57ab9 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
@@ -71,7 +71,7 @@ public class MetricsServiceImpl implements MetricsService {
         svcProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics Service");
         svcProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
         regs.add(context.registerService(MetricsService.class.getName(),
-                new MetricsServiceFactory(this, metricsMapper), svcProps));
+                new InternalMetricsServiceFactory(this, metricsMapper), svcProps));
 
         final Dictionary<String, String> regProps = new Hashtable<>();
         regProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics Registry");
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java
index 71d7fe4..f6d635b 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricsServiceFactoryTest.java
@@ -44,7 +44,7 @@ public class MetricsServiceFactoryTest {
     private MetricsServiceImpl serviceImpl = new MetricsServiceImpl();
     private MetricRegistry registry = serviceImpl.getRegistry();
     private BundleMetricsMapper mapper = new BundleMetricsMapper(registry);
-    private MetricsServiceFactory srvFactory = new MetricsServiceFactory(serviceImpl, mapper);
+    private InternalMetricsServiceFactory srvFactory = new InternalMetricsServiceFactory(serviceImpl, mapper);
     private ServiceRegistration<MetricsService> reg = mock(ServiceRegistration.class);
 
     @Test

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 19/44: SLING-5693 - Add support for exporting MetricRegistry data as JSON

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 6bb3b6907c6228470fcb7e2dbda346835b978374
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Tue Apr 26 06:25:04 2016 +0000

    SLING-5693 - Add support for exporting MetricRegistry data as JSON
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1740952 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |   6 +
 .../commons/metrics/internal/JSONReporter.java     | 298 +++++++++++++++++++++
 .../metrics/internal/MetricWebConsolePlugin.java   |   9 +-
 .../commons/metrics/internal/JSONReporterTest.java |  87 ++++++
 4 files changed, 399 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index c76858f..7b9fef1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,6 +113,12 @@
       <version>2.2</version>
       <optional>true</optional>
     </dependency>
+    <dependency>
+      <groupId>org.json</groupId>
+      <artifactId>json</artifactId>
+      <version>20090211</version>
+      <optional>true</optional>
+    </dependency>
 
     <dependency>
       <groupId>org.hamcrest</groupId>
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
new file mode 100644
index 0000000..9c631f7
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
@@ -0,0 +1,298 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import java.io.Closeable;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.util.Locale;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.concurrent.TimeUnit;
+
+import com.codahale.metrics.ConsoleReporter;
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricFilter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Reporter;
+import com.codahale.metrics.Snapshot;
+import com.codahale.metrics.Timer;
+import org.json.JSONException;
+import org.json.JSONWriter;
+
+class JSONReporter implements Reporter, Closeable {
+
+    public static JSONReporter.Builder forRegistry(MetricRegistry registry) {
+        return new JSONReporter.Builder(registry);
+    }
+
+    public static class Builder {
+        private final MetricRegistry registry;
+        private PrintStream output;
+        private MetricFilter filter;
+        private TimeUnit rateUnit;
+        private TimeUnit durationUnit;
+
+        private Builder(MetricRegistry registry) {
+            this.registry = registry;
+            this.output = System.out;
+            this.filter = MetricFilter.ALL;
+            this.rateUnit = TimeUnit.SECONDS;
+            this.durationUnit = TimeUnit.MILLISECONDS;
+        }
+
+        /**
+         * Write to the given {@link PrintStream}.
+         *
+         * @param output a {@link PrintStream} instance.
+         * @return {@code this}
+         */
+        public Builder outputTo(PrintStream output) {
+            this.output = output;
+            return this;
+        }
+
+        /**
+         * Convert rates to the given time unit.
+         *
+         * @param rateUnit a unit of time
+         * @return {@code this}
+         */
+        public Builder convertRatesTo(TimeUnit rateUnit) {
+            this.rateUnit = rateUnit;
+            return this;
+        }
+
+        /**
+         * Convert durations to the given time unit.
+         *
+         * @param durationUnit a unit of time
+         * @return {@code this}
+         */
+        public Builder convertDurationsTo(TimeUnit durationUnit) {
+            this.durationUnit = durationUnit;
+            return this;
+        }
+
+        /**
+         * Only report metrics which match the given filter.
+         *
+         * @param filter a {@link MetricFilter}
+         * @return {@code this}
+         */
+        public Builder filter(MetricFilter filter) {
+            this.filter = filter;
+            return this;
+        }
+
+        /**
+         * Builds a {@link ConsoleReporter} with the given properties.
+         *
+         * @return a {@link ConsoleReporter}
+         */
+        public JSONReporter build() {
+            return new JSONReporter(registry,
+                    output,
+                    rateUnit,
+                    durationUnit,
+                    filter);
+        }
+    }
+
+    private final MetricRegistry registry;
+    private final MetricFilter filter;
+    private final double durationFactor;
+    private final String durationUnit;
+    private final double rateFactor;
+    private final String rateUnit;
+    private final JSONWriter json;
+    private final PrintWriter pw;
+
+    private JSONReporter(MetricRegistry registry,
+                         PrintStream output, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter){
+        this.registry = registry;
+        this.filter = filter;
+        this.pw = new PrintWriter(output);
+        this.json = new JSONWriter(pw);
+        this.rateFactor = rateUnit.toSeconds(1);
+        this.rateUnit = calculateRateUnit(rateUnit);
+        this.durationFactor = 1.0 / durationUnit.toNanos(1);
+        this.durationUnit = durationUnit.toString().toLowerCase(Locale.US);
+    }
+
+    public void report() {
+        try {
+            report(registry.getGauges(filter),
+                    registry.getCounters(filter),
+                    registry.getHistograms(filter),
+                    registry.getMeters(filter),
+                    registry.getTimers(filter));
+        } catch (JSONException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public void close(){
+        pw.close();
+    }
+
+    private void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters,
+                        SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters,
+                        SortedMap<String, Timer> timers) throws JSONException {
+        json.object();
+        if (!gauges.isEmpty()) {
+            json.key("guages").object();
+            for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
+                printGauge(entry);
+            }
+            json.endObject();
+        }
+
+        if (!counters.isEmpty()) {
+            json.key("counters").object();
+            for (Map.Entry<String, Counter> entry : counters.entrySet()) {
+                printCounter(entry);
+            }
+            json.endObject();
+        }
+
+        if (!histograms.isEmpty()) {
+            json.key("histograms").object();
+            for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
+                printHistogram(entry);
+            }
+            json.endObject();
+        }
+
+        if (!meters.isEmpty()) {
+            json.key("meters").object();
+            for (Map.Entry<String, Meter> entry : meters.entrySet()) {
+                printMeter(entry);
+            }
+            json.endObject();
+        }
+
+        if (!timers.isEmpty()) {
+            json.key("timers").object();
+            for (Map.Entry<String, Timer> entry : timers.entrySet()) {
+                printTimer(entry);
+            }
+            json.endObject();
+        }
+
+        json.endObject();
+
+    }
+
+    private void printTimer(Map.Entry<String, Timer> e) throws JSONException {
+        json.key(e.getKey()).object();
+        Timer timer = e.getValue();
+        Snapshot snapshot = timer.getSnapshot();
+
+        json.key("count").value(timer.getCount());
+        json.key("max").value(snapshot.getMax() * durationFactor);
+        json.key("mean").value(snapshot.getMean() * durationFactor);
+        json.key("min").value(snapshot.getMin() * durationFactor);
+
+        json.key("p50").value(snapshot.getMedian() * durationFactor);
+        json.key("p75").value(snapshot.get75thPercentile() * durationFactor);
+        json.key("p95").value(snapshot.get95thPercentile() * durationFactor);
+        json.key("p98").value(snapshot.get98thPercentile() * durationFactor);
+        json.key("p99").value(snapshot.get99thPercentile() * durationFactor);
+        json.key("p999").value(snapshot.get999thPercentile() * durationFactor);
+
+        json.key("stddev").value(snapshot.getStdDev() * durationFactor);
+        json.key("m1_rate").value(timer.getOneMinuteRate() * rateFactor);
+        json.key("m5_rate").value(timer.getFiveMinuteRate() * rateFactor);
+        json.key("m15_rate").value(timer.getFifteenMinuteRate() * rateFactor);
+        json.key("mean_rate").value(timer.getMeanRate() * rateFactor);
+        json.key("duration_units").value(durationUnit);
+        json.key("rate_units").value(rateUnit);
+
+        json.endObject();
+    }
+
+    private void printMeter(Map.Entry<String, Meter> e) throws JSONException {
+        json.key(e.getKey()).object();
+        Meter meter = e.getValue();
+        json.key("count").value(e.getValue().getCount());
+        json.key("m1_rate").value(meter.getOneMinuteRate() * rateFactor);
+        json.key("m5_rate").value(meter.getFiveMinuteRate() * rateFactor);
+        json.key("m15_rate").value(meter.getFifteenMinuteRate() * rateFactor);
+        json.key("mean_rate").value(meter.getMeanRate() * rateFactor);
+        json.key("units").value(rateUnit);
+        json.endObject();
+    }
+
+    private void printHistogram(Map.Entry<String, Histogram> e) throws JSONException {
+        json.key(e.getKey()).object();
+        json.key("count").value(e.getValue().getCount());
+
+        Snapshot snapshot = e.getValue().getSnapshot();
+        json.key("max").value(snapshot.getMax());
+        json.key("mean").value(snapshot.getMean());
+        json.key("min").value(snapshot.getMin());
+        json.key("p50").value(snapshot.getMedian());
+        json.key("p75").value(snapshot.get75thPercentile());
+        json.key("p95").value(snapshot.get95thPercentile());
+        json.key("p98").value(snapshot.get98thPercentile());
+        json.key("p99").value(snapshot.get99thPercentile());
+        json.key("p999").value(snapshot.get999thPercentile());
+        json.key("stddev").value(snapshot.getStdDev());
+
+        json.endObject();
+    }
+
+    private void printCounter(Map.Entry<String, Counter> e) throws JSONException {
+        json.key(e.getKey()).object();
+        json.key("count").value(e.getValue().getCount());
+        json.endObject();
+    }
+
+    private void printGauge(Map.Entry<String, Gauge> e) throws JSONException {
+        json.key(e.getKey()).object();
+        Object v = e.getValue().getValue();
+        json.key("value").value(jsonSafeValue(v));
+        json.endObject();
+    }
+
+    private static Object jsonSafeValue(Object v){
+        //Json does not allow NaN or infinite doubles. So take care of that
+        if (v instanceof Number){
+            if (v instanceof Double){
+                Double d = (Double) v;
+                if (d.isInfinite() || d.isNaN()){
+                    return d.toString();
+                }
+            }
+        }
+        return v;
+    }
+
+    private static String calculateRateUnit(TimeUnit unit) {
+        final String s = unit.toString().toLowerCase(Locale.US);
+        return s.substring(0, s.length() - 1);
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index f5261c5..c33eb18 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -66,7 +66,7 @@ import org.slf4j.LoggerFactory;
         @Property(name = "felix.webconsole.label", value = "slingmetrics"),
         @Property(name = "felix.webconsole.title", value = "Metrics"),
         @Property(name = "felix.webconsole.category", value = "Sling"),
-        @Property(name = InventoryPrinter.FORMAT, value = {"TEXT" }),
+        @Property(name = InventoryPrinter.FORMAT, value = {"TEXT" , "JSON"}),
         @Property(name = InventoryPrinter.NAME, value = "slingmetrics"),
         @Property(name = InventoryPrinter.TITLE, value = "Sling Metrics"),
         @Property(name = InventoryPrinter.WEBCONSOLE, boolValue = true)
@@ -114,6 +114,13 @@ public class MetricWebConsolePlugin extends HttpServlet implements
                     .build();
             reporter.report();
             reporter.close();
+        } else if (format == Format.JSON) {
+            MetricRegistry registry = getConsolidatedRegistry();
+            JSONReporter reporter = JSONReporter.forRegistry(registry)
+                    .outputTo(new PrintStream(new WriterOutputStream(printWriter)))
+                    .build();
+            reporter.report();
+            reporter.close();
         }
     }
 
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
new file mode 100644
index 0000000..1f13872
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import java.io.PrintStream;
+import java.io.StringWriter;
+
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.JvmAttributeGaugeSet;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.commons.io.output.WriterOutputStream;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class JSONReporterTest {
+
+    @Test
+    public void jsonOutput() throws Exception {
+        MetricRegistry registry = new MetricRegistry();
+        registry.meter("test1").mark(5);
+        registry.timer("test2").time().close();
+        registry.histogram("test3").update(743);
+        registry.counter("test4").inc(9);
+        registry.registerAll(new JvmAttributeGaugeSet());
+
+        JSONObject json = getJSON(registry);
+
+        assertTrue(json.has("meters"));
+        assertTrue(json.has("guages"));
+        assertTrue(json.has("timers"));
+        assertTrue(json.has("counters"));
+        assertTrue(json.has("histograms"));
+        assertTrue(json.has("meters"));
+
+        assertTrue(json.getJSONObject("meters").has("test1"));
+        assertTrue(json.getJSONObject("timers").has("test2"));
+        assertTrue(json.getJSONObject("counters").has("test4"));
+        assertTrue(json.getJSONObject("histograms").has("test3"));
+    }
+
+    @Test
+    public void nan_value() throws Exception{
+        MetricRegistry registry = new MetricRegistry();
+
+        registry.register("test", new Gauge<Double>() {
+            @Override
+            public Double getValue() {
+                return Double.POSITIVE_INFINITY;
+            }
+        });
+
+
+        JSONObject json = getJSON(registry);
+        assertTrue(json.getJSONObject("guages").has("test"));
+    }
+
+    private static JSONObject getJSON(MetricRegistry registry) throws JSONException {
+        StringWriter sw = new StringWriter();
+        JSONReporter reporter = JSONReporter.forRegistry(registry)
+                .outputTo(new PrintStream(new WriterOutputStream(sw)))
+                .build();
+        reporter.report();
+        reporter.close();
+        return new JSONObject(sw.toString());
+    }
+
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 39/44: SLING-7028 - remove assumption that histograms are durations

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 280f1bf811285c5b2410da97fbba9cca8a09a65f
Author: Justin Edelson <ju...@apache.org>
AuthorDate: Mon Aug 7 13:30:02 2017 +0000

    SLING-7028 - remove assumption that histograms are durations
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1804333 13f79535-47bb-0310-9956-ffa450edef68
---
 .../metrics/internal/MetricWebConsolePlugin.java   | 26 +++++++++-------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index 6b8e8c1..ea9bfec 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -314,7 +314,6 @@ public class MetricWebConsolePlugin extends HttpServlet implements
         pw.println("<th class='header'>98%</th>");
         pw.println("<th class='header'>99%</th>");
         pw.println("<th class='header'>999%</th>");
-        pw.println("<th>Duration Unit</th>");
         pw.println("</tr>");
         pw.println("</thead>");
         pw.println("<tbody>");
@@ -325,25 +324,22 @@ public class MetricWebConsolePlugin extends HttpServlet implements
             Snapshot s = h.getSnapshot();
             String name = e.getKey();
 
-            double durationFactor = 1.0 / timeUnit.durationFor(name).toNanos(1);
-            String durationUnit = timeUnit.durationFor(name).toString().toLowerCase(Locale.US);
             pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
 
             pw.printf("<td>%s</td>", name);
             pw.printf("<td>%d</td>", h.getCount());
-            pw.printf("<td>%f</td>", s.getMedian() * durationFactor);
-            pw.printf("<td>%f</td>", s.getMin() * durationFactor);
-            pw.printf("<td>%f</td>", s.getMax() * durationFactor);
-            pw.printf("<td>%f</td>", s.getMean() * durationFactor);
-            pw.printf("<td>%f</td>", s.getStdDev() * durationFactor);
+            pw.printf("<td>%f</td>", s.getMedian());
+            pw.printf("<td>%d</td>", s.getMin());
+            pw.printf("<td>%d</td>", s.getMax());
+            pw.printf("<td>%f</td>", s.getMean());
+            pw.printf("<td>%f</td>", s.getStdDev());
+
+            pw.printf("<td>%f</td>", s.get75thPercentile());
+            pw.printf("<td>%f</td>", s.get95thPercentile());
+            pw.printf("<td>%f</td>", s.get98thPercentile());
+            pw.printf("<td>%f</td>", s.get99thPercentile());
+            pw.printf("<td>%f</td>", s.get999thPercentile());
 
-            pw.printf("<td>%f</td>", s.get75thPercentile() * durationFactor);
-            pw.printf("<td>%f</td>", s.get95thPercentile() * durationFactor);
-            pw.printf("<td>%f</td>", s.get98thPercentile() * durationFactor);
-            pw.printf("<td>%f</td>", s.get99thPercentile() * durationFactor);
-            pw.printf("<td>%f</td>", s.get999thPercentile() * durationFactor);
-
-            pw.printf("<td>%s</td>", durationUnit);
 
             pw.println("</tr>");
             rowClass = "odd".equals(rowClass) ? "even" : "odd";

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 40/44: SLING-7031 - configurable component to write subset of metrics to log file on a recurring basis.

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 52bb7c285194418da30681e30bfd14fa9ec20bca
Author: Justin Edelson <ju...@apache.org>
AuthorDate: Mon Aug 7 13:30:08 2017 +0000

    SLING-7031 - configurable component to write subset of metrics to log file on a recurring basis.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1804334 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |   6 +
 .../commons/metrics/internal/LogReporter.java      | 150 +++++++
 .../commons/metrics/internal/LogReporterTest.java  | 449 +++++++++++++++++++++
 3 files changed, 605 insertions(+)

diff --git a/pom.xml b/pom.xml
index 663e5fe..d7791af 100644
--- a/pom.xml
+++ b/pom.xml
@@ -238,6 +238,12 @@
             <scope>test</scope>
          </dependency>
         <dependency>
+            <groupId>junit-addons</groupId>
+            <artifactId>junit-addons</artifactId>
+            <version>1.4</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.paxexam</artifactId>
             <version>0.0.4</version>
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/LogReporter.java b/src/main/java/org/apache/sling/commons/metrics/internal/LogReporter.java
new file mode 100644
index 0000000..f1f872f
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/LogReporter.java
@@ -0,0 +1,150 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import com.codahale.metrics.Metric;
+import com.codahale.metrics.MetricFilter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Slf4jReporter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
+
+@Component(service = {}, configurationPolicy = ConfigurationPolicy.REQUIRE)
+@Designate(ocd = LogReporter.Config.class, factory = true)
+public class LogReporter implements ServiceTrackerCustomizer<MetricRegistry, Slf4jReporter> {
+
+    private BundleContext context;
+    private ServiceTracker<MetricRegistry, Slf4jReporter> tracker;
+    private Config config;
+
+    @Activate
+    protected void activate(Config config, BundleContext context) {
+        this.config = config;
+        this.context = context;
+        tracker = new ServiceTracker<>(context, MetricRegistry.class, this);
+        tracker.open();
+    }
+
+    @Deactivate
+    protected void deactivate(BundleContext context) {
+        tracker.close();
+    }
+
+    //~---------------------------------------------< ServiceTracker >
+
+    @Override
+    public Slf4jReporter addingService(ServiceReference<MetricRegistry> serviceReference) {
+        MetricRegistry registry = context.getService(serviceReference);
+        String metricRegistryName = (String) serviceReference.getProperty(MetricWebConsolePlugin.METRIC_REGISTRY_NAME);
+
+        if (config.registryName() == null || config.registryName().length() == 0
+                || config.registryName().equals(metricRegistryName)) {
+            Slf4jReporter.Builder builder = Slf4jReporter.forRegistry(registry).
+                    outputTo(LoggerFactory.getLogger(config.loggerName())).
+                    withLoggingLevel(config.level());
+
+            if (config.prefix() != null && config.prefix().length() > 0) {
+                builder.filter(new PrefixFilter(config.prefix()));
+            } else if (config.pattern() != null && config.pattern().length() > 0) {
+                builder.filter(new PatternFilter(config.pattern()));
+            }
+
+            Slf4jReporter reporter = builder.build();
+            reporter.start(config.period(), config.timeUnit());
+            return reporter;
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public void modifiedService(ServiceReference<MetricRegistry> serviceReference, Slf4jReporter reporter) {
+        // NO OP
+    }
+
+    @Override
+    public void removedService(ServiceReference<MetricRegistry> serviceReference, Slf4jReporter reporter) {
+        if (reporter != null) {
+            reporter.close();
+        }
+    }
+
+    private class PrefixFilter implements MetricFilter {
+        private final String prefix;
+
+        private PrefixFilter(String prefix) {
+            this.prefix = prefix;
+        }
+
+        @Override
+        public boolean matches(String s, Metric metric) {
+            return s.startsWith(prefix);
+        }
+    }
+
+    private class PatternFilter implements MetricFilter {
+        private final Pattern pattern;
+
+        private PatternFilter(String pattern) {
+            this.pattern = Pattern.compile(pattern);
+        }
+
+        @Override
+        public boolean matches(String s, Metric metric) {
+            return pattern.matcher(s).matches();
+        }
+    }
+
+    @ObjectClassDefinition(name = "Apache Sling Metrics Log Reporter Configuration")
+    @interface Config {
+
+        @AttributeDefinition(description = "Period at which the metrics data will be logged")
+        long period() default 5;
+
+        @AttributeDefinition(description = "Unit of time for evaluating the period")
+        TimeUnit timeUnit() default TimeUnit.MINUTES;
+
+        @AttributeDefinition(description = "The log level to log at.")
+        Slf4jReporter.LoggingLevel level() default Slf4jReporter.LoggingLevel.INFO;
+
+        @AttributeDefinition(description = "The logger name")
+        String loggerName() default "metrics";
+
+        @AttributeDefinition(description = "If specified, only metrics whose name starts with this value are logged. If both prefix and pattern are set, prefix is used.")
+        String prefix() default "";
+
+        @AttributeDefinition(description = "If specified, only metrics whose name matches this regular expression will be logged. If both prefix and pattern are set, prefix is used.")
+        String pattern() default "";
+
+        @AttributeDefinition(description = "Restrict the metrics logged to a specifically named registry.")
+        String registryName() default "";
+    }
+
+}
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/LogReporterTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/LogReporterTest.java
new file mode 100644
index 0000000..67f1950
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/LogReporterTest.java
@@ -0,0 +1,449 @@
+/*
+ * 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.sling.commons.metrics.internal;
+
+import com.codahale.metrics.MetricFilter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Slf4jReporter;
+import junitx.util.PrivateAccessor;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+
+
+import static org.mockito.Mockito.*;
+import static org.junit.Assert.*;
+
+import java.lang.annotation.Annotation;
+import java.util.concurrent.TimeUnit;
+
+@RunWith(MockitoJUnitRunner.class)
+public class LogReporterTest {
+
+    @Mock
+    private BundleContext bundleContext;
+
+    LogReporter reporterService = new LogReporter();
+
+    @Test
+    public void testSpecificRegistryNameInclude() {
+        MetricRegistry registry = new MetricRegistry();
+        ServiceReference<MetricRegistry> registryServiceReference = mock(ServiceReference.class);
+        when(bundleContext.getService(registryServiceReference)).thenReturn(registry);
+        when(registryServiceReference.getProperty(MetricWebConsolePlugin.METRIC_REGISTRY_NAME)).thenReturn("oak");
+
+        LogReporter.Config config = createConfigWithRegistryName("oak");
+        reporterService.activate(config, bundleContext);
+
+        Slf4jReporter reporter = null;
+        try {
+            reporter = reporterService.addingService(registryServiceReference);
+            assertNotNull(reporter);
+        } finally {
+            if (reporter != null) {
+                reporter.close();
+            }
+            reporterService.deactivate(bundleContext);
+        }
+    }
+
+    @Test
+    public void testSpecificRegistryNameExclude() {
+        MetricRegistry registry = new MetricRegistry();
+        ServiceReference<MetricRegistry> registryServiceReference = mock(ServiceReference.class);
+        when(bundleContext.getService(registryServiceReference)).thenReturn(registry);
+        when(registryServiceReference.getProperty(MetricWebConsolePlugin.METRIC_REGISTRY_NAME)).thenReturn("other");
+
+        LogReporter.Config config = createConfigWithRegistryName("oak");
+        reporterService.activate(config, bundleContext);
+
+        Slf4jReporter reporter = null;
+        try {
+            reporter = reporterService.addingService(registryServiceReference);
+            assertNull(reporter);
+        } finally {
+            if (reporter != null) {
+                reporter.close();
+            }
+            reporterService.deactivate(bundleContext);
+        }
+    }
+
+    @Test
+    public void testSpecificRegistryNameExcludeNullName() {
+        MetricRegistry registry = new MetricRegistry();
+        ServiceReference<MetricRegistry> registryServiceReference = mock(ServiceReference.class);
+        when(bundleContext.getService(registryServiceReference)).thenReturn(registry);
+
+        LogReporter.Config config = createConfigWithRegistryName("oak");
+        reporterService.activate(config, bundleContext);
+
+        Slf4jReporter reporter = null;
+        try {
+            reporter = reporterService.addingService(registryServiceReference);
+            assertNull(reporter);
+        } finally {
+            if (reporter != null) {
+                reporter.close();
+            }
+            reporterService.deactivate(bundleContext);
+        }
+    }
+
+    @Test
+    public void testLoggerName() throws Exception {
+        MetricRegistry registry = new MetricRegistry();
+        ServiceReference<MetricRegistry> registryServiceReference = mock(ServiceReference.class);
+        when(bundleContext.getService(registryServiceReference)).thenReturn(registry);
+
+        LogReporter.Config config = createConfigWithLoggerNameAndLevel("test", Slf4jReporter.LoggingLevel.WARN);
+        reporterService.activate(config, bundleContext);
+
+        Slf4jReporter reporter = null;
+        try {
+            reporter = reporterService.addingService(registryServiceReference);
+            assertNotNull(reporter);
+
+            Object loggerProxy = PrivateAccessor.getField(reporter, "loggerProxy");
+            assertEquals("WarnLoggerProxy", loggerProxy.getClass().getSimpleName());
+
+            Logger logger = (Logger) PrivateAccessor.getField(loggerProxy, "logger");
+            assertEquals("test", logger.getName());
+        } finally {
+            if (reporter != null) {
+                reporter.close();
+            }
+            reporterService.deactivate(bundleContext);
+        }
+    }
+
+    @Test
+    public void testPrefix() throws Exception {
+        MetricRegistry registry = new MetricRegistry();
+        ServiceReference<MetricRegistry> registryServiceReference = mock(ServiceReference.class);
+        when(bundleContext.getService(registryServiceReference)).thenReturn(registry);
+
+        LogReporter.Config config = createConfigWithPrefix("testPrefix");
+        reporterService.activate(config, bundleContext);
+
+        Slf4jReporter reporter = null;
+        try {
+            reporter = reporterService.addingService(registryServiceReference);
+            assertNotNull(reporter);
+
+            MetricFilter filter = (MetricFilter) PrivateAccessor.getField(reporter, "filter");
+            assertEquals("PrefixFilter", filter.getClass().getSimpleName());
+            assertTrue(filter.matches("testPrefixedName", null));
+            assertFalse(filter.matches("testNonPrefixedName", null));
+        } finally {
+            if (reporter != null) {
+                reporter.close();
+            }
+            reporterService.deactivate(bundleContext);
+        }
+    }
+
+    @Test
+    public void testPattern() throws Exception {
+        MetricRegistry registry = new MetricRegistry();
+        ServiceReference<MetricRegistry> registryServiceReference = mock(ServiceReference.class);
+        when(bundleContext.getService(registryServiceReference)).thenReturn(registry);
+
+        LogReporter.Config config = createConfigWithPattern("[0-9]test.*");
+        reporterService.activate(config, bundleContext);
+
+        Slf4jReporter reporter = null;
+        try {
+            reporter = reporterService.addingService(registryServiceReference);
+            assertNotNull(reporter);
+
+            MetricFilter filter = (MetricFilter) PrivateAccessor.getField(reporter, "filter");
+            assertEquals("PatternFilter", filter.getClass().getSimpleName());
+            assertTrue(filter.matches("5testTest", null));
+            assertFalse(filter.matches("ZtestTest", null));
+        } finally {
+            if (reporter != null) {
+                reporter.close();
+            }
+            reporterService.deactivate(bundleContext);
+        }
+    }
+
+    @Test
+    public void testPrefixAndPattern() throws Exception {
+        MetricRegistry registry = new MetricRegistry();
+        ServiceReference<MetricRegistry> registryServiceReference = mock(ServiceReference.class);
+        when(bundleContext.getService(registryServiceReference)).thenReturn(registry);
+
+        LogReporter.Config config = createConfigWithPrefixAndPattern("testPrefix", "[0-9]test.*");
+        reporterService.activate(config, bundleContext);
+
+        Slf4jReporter reporter = null;
+        try {
+            reporter = reporterService.addingService(registryServiceReference);
+            assertNotNull(reporter);
+
+            MetricFilter filter = (MetricFilter) PrivateAccessor.getField(reporter, "filter");
+            assertEquals("PrefixFilter", filter.getClass().getSimpleName());
+            assertTrue(filter.matches("testPrefixedName", null));
+            assertFalse(filter.matches("testNonPrefixedName", null));
+        } finally {
+            if (reporter != null) {
+                reporter.close();
+            }
+            reporterService.deactivate(bundleContext);
+        }
+    }
+
+    @Test
+    public void testRemove() {
+        Slf4jReporter reporter = mock(Slf4jReporter.class);
+        reporterService.removedService(null, reporter);
+        verify(reporter, times(1)).close();
+    }
+
+    @Test
+    public void testNoOpCalls() {
+        // extra no-op calls for coverage
+        reporterService.removedService(null, null);
+        reporterService.modifiedService(null, null);
+    }
+
+    private LogReporter.Config createConfigWithRegistryName(final String registryName) {
+        return new LogReporter.Config() {
+            @Override
+            public long period() {
+                return 5;
+            }
+
+            @Override
+            public TimeUnit timeUnit() {
+                return TimeUnit.MINUTES;
+            }
+
+            @Override
+            public Slf4jReporter.LoggingLevel level() {
+                return Slf4jReporter.LoggingLevel.INFO;
+            }
+
+            @Override
+            public String loggerName() {
+                return "metrics";
+            }
+
+            @Override
+            public String prefix() {
+                return null;
+            }
+
+            @Override
+            public String pattern() {
+                return null;
+            }
+
+            @Override
+            public String registryName() {
+                return registryName;
+            }
+
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return LogReporter.Config.class;
+            }
+        };
+    }
+
+    private LogReporter.Config createConfigWithLoggerNameAndLevel(final String loggerName, final Slf4jReporter.LoggingLevel level) {
+        return new LogReporter.Config() {
+            @Override
+            public long period() {
+                return 5;
+            }
+
+            @Override
+            public TimeUnit timeUnit() {
+                return TimeUnit.MINUTES;
+            }
+
+            @Override
+            public Slf4jReporter.LoggingLevel level() {
+                return level;
+            }
+
+            @Override
+            public String loggerName() {
+                return loggerName;
+            }
+
+            @Override
+            public String prefix() {
+                return null;
+            }
+
+            @Override
+            public String pattern() {
+                return null;
+            }
+
+            @Override
+            public String registryName() {
+                return "";
+            }
+
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return LogReporter.Config.class;
+            }
+        };
+    }
+
+    private LogReporter.Config createConfigWithPrefix(final String prefix) {
+        return new LogReporter.Config() {
+            @Override
+            public long period() {
+                return 5;
+            }
+
+            @Override
+            public TimeUnit timeUnit() {
+                return TimeUnit.MINUTES;
+            }
+
+            @Override
+            public Slf4jReporter.LoggingLevel level() {
+                return Slf4jReporter.LoggingLevel.INFO;
+            }
+
+            @Override
+            public String loggerName() {
+                return "metrics";
+            }
+
+            @Override
+            public String prefix() {
+                return prefix;
+            }
+
+            @Override
+            public String pattern() {
+                return null;
+            }
+
+            @Override
+            public String registryName() {
+                return null;
+            }
+
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return LogReporter.Config.class;
+            }
+        };
+    }
+
+    private LogReporter.Config createConfigWithPattern(final String pattern) {
+        return new LogReporter.Config() {
+            @Override
+            public long period() {
+                return 5;
+            }
+
+            @Override
+            public TimeUnit timeUnit() {
+                return TimeUnit.MINUTES;
+            }
+
+            @Override
+            public Slf4jReporter.LoggingLevel level() {
+                return Slf4jReporter.LoggingLevel.INFO;
+            }
+
+            @Override
+            public String loggerName() {
+                return "metrics";
+            }
+
+            @Override
+            public String prefix() {
+                return null;
+            }
+
+            @Override
+            public String pattern() {
+                return pattern;
+            }
+
+            @Override
+            public String registryName() {
+                return null;
+            }
+
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return LogReporter.Config.class;
+            }
+        };
+    }
+
+    private LogReporter.Config createConfigWithPrefixAndPattern(final String prefix, final String pattern) {
+        return new LogReporter.Config() {
+            @Override
+            public long period() {
+                return 5;
+            }
+
+            @Override
+            public TimeUnit timeUnit() {
+                return TimeUnit.MINUTES;
+            }
+
+            @Override
+            public Slf4jReporter.LoggingLevel level() {
+                return Slf4jReporter.LoggingLevel.INFO;
+            }
+
+            @Override
+            public String loggerName() {
+                return "metrics";
+            }
+
+            @Override
+            public String prefix() {
+                return prefix;
+            }
+
+            @Override
+            public String pattern() {
+                return pattern;
+            }
+
+            @Override
+            public String registryName() {
+                return null;
+            }
+
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return LogReporter.Config.class;
+            }
+        };
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 32/44: SLING-6596 - fix typo introduced by the typo fixing

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit e414f2b4562be13a9f0e88a7bae96a8dcb9c1d60
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Mar 3 14:12:32 2017 +0000

    SLING-6596 - fix typo introduced by the typo fixing
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1785309 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/sling/commons/metrics/internal/JSONReporter.java    | 2 +-
 .../apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java   | 2 +-
 .../org/apache/sling/commons/metrics/internal/JSONReporterTest.java     | 2 +-
 .../sling/commons/metrics/internal/MetricWebConsolePluginTest.java      | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
index c7a439f..d501fb2 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
@@ -13,7 +13,7 @@
  * 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 langauge governing permissions and limitations
+ * specific language governing permissions and limitations
  * under the License.
  */
 
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index 70a7581..6b8e8c1 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -13,7 +13,7 @@
  * 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 langauge governing permissions and limitations
+ * specific language governing permissions and limitations
  * under the License.
  */
 
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
index d05c175..4de6cc8 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
@@ -13,7 +13,7 @@
  * 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 langauge governing permissions and limitations
+ * specific language governing permissions and limitations
  * under the License.
  */
 
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
index 56e44bc..6b73d91 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
@@ -13,7 +13,7 @@
  * 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 langauge governing permissions and limitations
+ * specific language governing permissions and limitations
  * under the License.
  */
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 18/44: SLING-5424 - MBeanServer reference in MetricServiceImpl should be made optional

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 59756f4fe3d9cf84a68cb386dff80c7a85625c53
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Wed Jan 13 04:58:38 2016 +0000

    SLING-5424 - MBeanServer reference in MetricServiceImpl should be made optional
    
    -- Added test to check for MBean registration - Due to missing start call on JMXReporter
        Mbeans were not getting registered
    -- Made reference optional - If not set default PlatformMBeanServer is used
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1724354 13f79535-47bb-0310-9956-ffa450edef68
---
 .../metrics/internal/MetricsServiceImpl.java       | 29 ++++++++++++++-------
 .../metrics/internal/MetricServiceTest.java        | 30 ++++++++++++++++++++--
 2 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
index a0e0520..d2f2728 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
@@ -20,6 +20,7 @@
 package org.apache.sling.commons.metrics.internal;
 
 import java.io.IOException;
+import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
@@ -36,6 +37,7 @@ import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.sling.commons.metrics.Meter;
 import org.apache.sling.commons.metrics.MetricsService;
 import org.apache.sling.commons.metrics.Timer;
@@ -52,21 +54,14 @@ public class MetricsServiceImpl implements MetricsService {
     private final ConcurrentMap<String, Metric> metrics = new ConcurrentHashMap<String, Metric>();
     private final MetricRegistry registry = new MetricRegistry();
 
-    @Reference
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
     private MBeanServer server;
 
     private JmxReporter reporter;
 
     @Activate
     private void activate(BundleContext context, Map<String, Object> config) {
-        //TODO Domain name should be based on calling bundle
-        //For that we can register ServiceFactory and make use of calling
-        //bundle symbolic name to determine the mapping
-
-        reporter = JmxReporter.forRegistry(registry)
-                .inDomain("org.apache.sling")
-                .registerWith(server)
-                .build();
+        enableJMXReporter();
 
         final Dictionary<String, String> svcProps = new Hashtable<String, String>();
         svcProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics Service");
@@ -205,4 +200,20 @@ public class MetricsServiceImpl implements MetricsService {
 
         boolean isInstance(Metric metric);
     }
+
+    private void enableJMXReporter() {
+        //TODO Domain name should be based on calling bundle
+        //For that we can register ServiceFactory and make use of calling
+        //bundle symbolic name to determine the mapping
+
+        if (server == null){
+            server = ManagementFactory.getPlatformMBeanServer();
+        }
+
+        reporter = JmxReporter.forRegistry(registry)
+                .inDomain("org.apache.sling")
+                .registerWith(server)
+                .build();
+        reporter.start();
+    }
 }
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
index a028abf..5885426 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
@@ -21,9 +21,14 @@ package org.apache.sling.commons.metrics.internal;
 
 import java.lang.management.ManagementFactory;
 import java.util.Collections;
+import java.util.Set;
 
 import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.Query;
+import javax.management.QueryExp;
 
+import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.MetricRegistry;
 import org.apache.sling.commons.metrics.Counter;
 import org.apache.sling.commons.metrics.Histogram;
@@ -36,9 +41,13 @@ import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public class MetricServiceTest {
@@ -48,8 +57,8 @@ public class MetricServiceTest {
     private MetricsServiceImpl service = new MetricsServiceImpl();
 
     @After
-    public void registerMBeanServer() {
-        context.registerService(MBeanServer.class, ManagementFactory.getPlatformMBeanServer());
+    public void deactivate(){
+        MockOsgi.deactivate(service);
     }
 
     @Test
@@ -118,6 +127,23 @@ public class MetricServiceTest {
         service.timer("test");
     }
 
+    @Test
+    public void jmxRegistration() throws Exception{
+        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        activate();
+        Meter meter = service.meter("test");
+        assertNotNull(meter);
+        QueryExp q = Query.isInstanceOf(Query.value(JmxReporter.JmxMeterMBean.class.getName()));
+        Set<ObjectName> names = server.queryNames(new ObjectName("org.apache.sling:name=*"), q);
+        assertThat(names, is(not(empty())));
+
+        MockOsgi.deactivate(service);
+
+        names = server.queryNames(new ObjectName("org.apache.sling:name=*"), q);
+        assertThat(names, is(empty()));
+
+    }
+
     private MetricRegistry getRegistry(){
         return context.getService(MetricRegistry.class);
     }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 01/44: SLING-4080 - API to capture/measure application-level metrics Moving to trunk from sandbox

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 510579bc1e277801fa306ed6dca3d253a7279f5d
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 04:20:39 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    Moving to trunk from sandbox
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723456 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 130 ++++++
 .../java/org/apache/sling/metrics/Counter.java     |  49 +++
 .../java/org/apache/sling/metrics/Counting.java    |  32 ++
 .../java/org/apache/sling/metrics/Histogram.java   |  32 ++
 src/main/java/org/apache/sling/metrics/Meter.java  |  37 ++
 src/main/java/org/apache/sling/metrics/Metric.java |  35 ++
 .../org/apache/sling/metrics/MetricsService.java   |  79 ++++
 .../java/org/apache/sling/metrics/NoopMetric.java  |  94 ++++
 src/main/java/org/apache/sling/metrics/Timer.java  |  58 +++
 .../apache/sling/metrics/internal/CounterImpl.java |  65 +++
 .../sling/metrics/internal/HistogramImpl.java      |  50 +++
 .../apache/sling/metrics/internal/MeterImpl.java   |  54 +++
 .../metrics/internal/MetricWebConsolePlugin.java   | 475 +++++++++++++++++++++
 .../sling/metrics/internal/MetricsServiceImpl.java | 199 +++++++++
 .../apache/sling/metrics/internal/TimerImpl.java   |  77 ++++
 .../org/apache/sling/metrics/package-info.java     |  31 ++
 .../sling/metrics/internal/MetricServiceTest.java  | 120 ++++++
 .../sling/metrics/internal/MetricWrapperTest.java  | 132 ++++++
 18 files changed, 1749 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..5d13870
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,130 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.sling</groupId>
+    <artifactId>sling</artifactId>
+    <version>26</version>
+  </parent>
+
+  <artifactId>org.apache.sling.metrics</artifactId>
+  <packaging>bundle</packaging>
+  <version>0.0.1-SNAPSHOT</version>
+
+  <name>Apache Sling Metrics</name>
+  <description>
+    Integrates Metric library http://metrics.dropwizard.io/ with Sling
+
+    Refer to http://sling.apache.org/documentation/bundles/log-tracers.html
+  </description>
+
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/metrics</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/metrics</developerConnection>
+    <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/metrics</url>
+  </scm>
+
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-scr-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>io.dropwizard.metrics</groupId>
+      <artifactId>metrics-core</artifactId>
+      <version>3.1.0</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.commons.osgi</artifactId>
+      <version>2.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>4.3.1</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>4.3.1</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.inventory</artifactId>
+      <version>1.0.2</version>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>2.2</version>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
+      <version>1.3.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>1.10.19</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/metrics/Counter.java b/src/main/java/org/apache/sling/metrics/Counter.java
new file mode 100644
index 0000000..b828aa5
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/Counter.java
@@ -0,0 +1,49 @@
+/*
+ * 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.sling.metrics;
+
+import aQute.bnd.annotation.ProviderType;
+
+@ProviderType
+public interface Counter extends Counting, Metric{
+    /**
+     * Increment the counter by one.
+     */
+    void inc();
+
+    /**
+     * Decrement the counter by one.
+     */
+    void dec();
+
+    /**
+     * Increment the counter by {@code n}.
+     *
+     * @param n the amount by which the counter will be increased
+     */
+    void inc(long n);
+
+    /**
+     * Decrement the counter by {@code n}.
+     *
+     * @param n the amount by which the counter will be decreased
+     */
+    void dec(long n);
+}
diff --git a/src/main/java/org/apache/sling/metrics/Counting.java b/src/main/java/org/apache/sling/metrics/Counting.java
new file mode 100644
index 0000000..309decd
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/Counting.java
@@ -0,0 +1,32 @@
+/*
+ * 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.sling.metrics;
+
+import aQute.bnd.annotation.ProviderType;
+
+@ProviderType
+public interface Counting {
+    /**
+     * Returns the current count.
+     *
+     * @return the current count
+     */
+    long getCount();
+}
diff --git a/src/main/java/org/apache/sling/metrics/Histogram.java b/src/main/java/org/apache/sling/metrics/Histogram.java
new file mode 100644
index 0000000..37938f5
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/Histogram.java
@@ -0,0 +1,32 @@
+/*
+ * 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.sling.metrics;
+
+import aQute.bnd.annotation.ProviderType;
+
+@ProviderType
+public interface Histogram extends Counting, Metric {
+    /**
+     * Adds a recorded value.
+     *
+     * @param value the length of the value
+     */
+    void update(long value);
+}
diff --git a/src/main/java/org/apache/sling/metrics/Meter.java b/src/main/java/org/apache/sling/metrics/Meter.java
new file mode 100644
index 0000000..a4914d7
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/Meter.java
@@ -0,0 +1,37 @@
+/*
+ * 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.sling.metrics;
+
+import aQute.bnd.annotation.ProviderType;
+
+@ProviderType
+public interface Meter extends Counting, Metric{
+    /**
+     * Mark the occurrence of an event.
+     */
+    void mark();
+
+    /**
+     * Mark the occurrence of a given number of events.
+     *
+     * @param n the number of events
+     */
+    void mark(long n);
+}
diff --git a/src/main/java/org/apache/sling/metrics/Metric.java b/src/main/java/org/apache/sling/metrics/Metric.java
new file mode 100644
index 0000000..4952017
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/Metric.java
@@ -0,0 +1,35 @@
+/*
+ * 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.sling.metrics;
+
+import aQute.bnd.annotation.ProviderType;
+
+@ProviderType
+public interface Metric {
+    /**
+     * Adapts the Metric to the specified type.
+     *
+     * @param <A> The type to which this metric is to be adapted.
+     * @param type Class object for the type to which this metric is to be adapted.
+     * @return The object, of the specified type, to which this metric has been adapted
+     * or null if this metric cannot be adapted to the specified type.
+     */
+    <A> A adaptTo(Class<A> type);
+}
diff --git a/src/main/java/org/apache/sling/metrics/MetricsService.java b/src/main/java/org/apache/sling/metrics/MetricsService.java
new file mode 100644
index 0000000..8c51d4b
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/MetricsService.java
@@ -0,0 +1,79 @@
+/*
+ * 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.sling.metrics;
+
+import aQute.bnd.annotation.ProviderType;
+
+@ProviderType
+public interface MetricsService {
+    MetricsService NOOP = new MetricsService() {
+        @Override
+        public Timer timer(String name) {
+            return NoopMetric.INSTANCE;
+        }
+
+        @Override
+        public Histogram histogram(String name) {
+            return NoopMetric.INSTANCE;
+        }
+
+        @Override
+        public Counter counter(String name) {
+            return NoopMetric.INSTANCE;
+        }
+
+        @Override
+        public Meter meter(String name) {
+            return NoopMetric.INSTANCE;
+        }
+    };
+
+    /**
+     * Creates a new {@link Timer} and registers it under the given name.
+     *
+     * @param name the name of the metric
+     * @return a new {@link Timer}
+     */
+    Timer timer(String name);
+
+    /**
+     * Creates a new {@link Histogram} and registers it under the given name.
+     *
+     * @param name the name of the metric
+     * @return a new {@link Histogram}
+     */
+    Histogram histogram(String name);
+
+    /**
+     * Creates a new {@link Counter} and registers it under the given name.
+     *
+     * @param name the name of the metric
+     * @return a new {@link Counter}
+     */
+    Counter counter(String name);
+
+    /**
+     * Creates a new {@link Meter} and registers it under the given name.
+     *
+     * @param name the name of the metric
+     * @return a new {@link Meter}
+     */
+    Meter meter(String name);
+}
diff --git a/src/main/java/org/apache/sling/metrics/NoopMetric.java b/src/main/java/org/apache/sling/metrics/NoopMetric.java
new file mode 100644
index 0000000..210fb3c
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/NoopMetric.java
@@ -0,0 +1,94 @@
+/*
+ * 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.sling.metrics;
+
+import java.util.concurrent.TimeUnit;
+
+final class NoopMetric implements Counter, Histogram, Timer, Meter{
+    public static final NoopMetric INSTANCE = new NoopMetric();
+    @Override
+    public long getCount() {
+        return 0;
+    }
+
+    @Override
+    public void inc() {
+
+    }
+
+    @Override
+    public void dec() {
+
+    }
+
+    @Override
+    public void inc(long n) {
+
+    }
+
+    @Override
+    public void dec(long n) {
+
+    }
+
+    @Override
+    public void mark() {
+
+    }
+
+    @Override
+    public void mark(long n) {
+
+    }
+
+    @Override
+    public void update(long duration, TimeUnit unit) {
+
+    }
+
+    @Override
+    public Context time() {
+        return NoopContext.INSTANCE;
+    }
+
+    @Override
+    public void update(long value) {
+
+    }
+
+    @Override
+    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+        return null;
+    }
+
+    private static final class NoopContext implements Context {
+        public static final NoopContext INSTANCE = new NoopContext();
+
+        @Override
+        public long stop() {
+            return 0;
+        }
+
+        @Override
+        public void close() {
+
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/metrics/Timer.java b/src/main/java/org/apache/sling/metrics/Timer.java
new file mode 100644
index 0000000..602a0cb
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/Timer.java
@@ -0,0 +1,58 @@
+/*
+ * 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.sling.metrics;
+
+import java.io.Closeable;
+import java.util.concurrent.TimeUnit;
+
+import aQute.bnd.annotation.ProviderType;
+
+@ProviderType
+public interface Timer extends Counting, Metric{
+    /**
+     * A timing context.
+     *
+     * @see Timer#time()
+     */
+    interface Context extends Closeable {
+        /**
+         * Updates the timer with the difference between current and start time. Call to this method will
+         * not reset the start time. Multiple calls result in multiple updates.
+         * @return the elapsed time in nanoseconds
+         */
+        long stop();
+    }
+
+    /**
+     * Adds a recorded duration.
+     *
+     * @param duration the length of the duration
+     * @param unit     the scale unit of {@code duration}
+     */
+    void update(long duration, TimeUnit unit);
+
+    /**
+     * Returns a new {@link Context}.
+     *
+     * @return a new {@link Context}
+     * @see Context
+     */
+    Context time();
+}
diff --git a/src/main/java/org/apache/sling/metrics/internal/CounterImpl.java b/src/main/java/org/apache/sling/metrics/internal/CounterImpl.java
new file mode 100644
index 0000000..0137b71
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/internal/CounterImpl.java
@@ -0,0 +1,65 @@
+/*
+ * 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.sling.metrics.internal;
+
+
+import org.apache.sling.metrics.Counter;
+
+final class CounterImpl implements Counter {
+    private final com.codahale.metrics.Counter counter;
+
+    CounterImpl(com.codahale.metrics.Counter counter) {
+        this.counter = counter;
+    }
+
+    @Override
+    public void inc() {
+        counter.inc();
+    }
+
+    @Override
+    public void dec() {
+        counter.dec();
+    }
+
+    @Override
+    public void inc(long n) {
+        counter.inc(n);
+    }
+
+    @Override
+    public void dec(long n) {
+        counter.dec(n);
+    }
+
+    @Override
+    public long getCount() {
+        return counter.getCount();
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <A> A adaptTo(Class<A> type) {
+        if (type == com.codahale.metrics.Counter.class){
+            return (A) counter;
+        }
+        return null;
+    }
+}
diff --git a/src/main/java/org/apache/sling/metrics/internal/HistogramImpl.java b/src/main/java/org/apache/sling/metrics/internal/HistogramImpl.java
new file mode 100644
index 0000000..15117e9
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/internal/HistogramImpl.java
@@ -0,0 +1,50 @@
+/*
+ * 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.sling.metrics.internal;
+
+
+import org.apache.sling.metrics.Histogram;
+
+final class HistogramImpl implements Histogram {
+    private final com.codahale.metrics.Histogram histogram;
+
+    HistogramImpl(com.codahale.metrics.Histogram histogram) {
+        this.histogram = histogram;
+    }
+
+    @Override
+    public void update(long value) {
+        histogram.update(value);
+    }
+
+    @Override
+    public long getCount() {
+        return histogram.getCount();
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <A> A adaptTo(Class<A> type) {
+        if (type == com.codahale.metrics.Histogram.class){
+            return (A) histogram;
+        }
+        return null;
+    }
+}
diff --git a/src/main/java/org/apache/sling/metrics/internal/MeterImpl.java b/src/main/java/org/apache/sling/metrics/internal/MeterImpl.java
new file mode 100644
index 0000000..719d356
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/internal/MeterImpl.java
@@ -0,0 +1,54 @@
+/*
+ * 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.sling.metrics.internal;
+
+import org.apache.sling.metrics.Meter;
+
+final class MeterImpl implements Meter {
+    private final com.codahale.metrics.Meter meter;
+
+    MeterImpl(com.codahale.metrics.Meter meter) {
+        this.meter = meter;
+    }
+
+    @Override
+    public void mark() {
+        meter.mark();
+    }
+
+    @Override
+    public void mark(long n) {
+        meter.mark(n);
+    }
+
+    @Override
+    public long getCount() {
+        return meter.getCount();
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <A> A adaptTo(Class<A> type) {
+        if (type == com.codahale.metrics.Meter.class){
+            return (A)meter;
+        }
+        return null;
+    }
+}
diff --git a/src/main/java/org/apache/sling/metrics/internal/MetricWebConsolePlugin.java b/src/main/java/org/apache/sling/metrics/internal/MetricWebConsolePlugin.java
new file mode 100644
index 0000000..180acca
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/internal/MetricWebConsolePlugin.java
@@ -0,0 +1,475 @@
+/*
+ * 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.sling.metrics.internal;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.util.Collections;
+import java.util.Locale;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.TimeUnit;
+
+import javax.servlet.Servlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.codahale.metrics.ConsoleReporter;
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Gauge;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.Metric;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Snapshot;
+import com.codahale.metrics.Timer;
+import org.apache.commons.io.output.WriterOutputStream;
+import org.apache.felix.inventory.Format;
+import org.apache.felix.inventory.InventoryPrinter;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component
+@Service(value = {InventoryPrinter.class, Servlet.class})
+@Properties({
+        @Property(name = "felix.webconsole.label", value = "slingmetrics"),
+        @Property(name = "felix.webconsole.title", value = "Metrics"),
+        @Property(name = "felix.webconsole.category", value = "Sling"),
+        @Property(name = InventoryPrinter.FORMAT, value = {"TEXT" }),
+        @Property(name = InventoryPrinter.NAME, value = "slingmetrics"),
+        @Property(name = InventoryPrinter.TITLE, value = "Sling Metrics"),
+        @Property(name = InventoryPrinter.WEBCONSOLE, boolValue = true)
+})
+public class MetricWebConsolePlugin extends HttpServlet implements
+        InventoryPrinter, ServiceTrackerCustomizer<MetricRegistry, MetricRegistry>{
+    /**
+     * Service property name which stores the MetricRegistry name as a given OSGi
+     * ServiceRegistry might have multiple instances of MetricRegistry
+     */
+    public static final String METRIC_REGISTRY_NAME = "name";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private BundleContext context;
+    private ServiceTracker<MetricRegistry, MetricRegistry> tracker;
+    private ConcurrentMap<ServiceReference, MetricRegistry> registries
+            = new ConcurrentHashMap<ServiceReference, MetricRegistry>();
+
+    private TimeUnit rateUnit = TimeUnit.SECONDS;
+    private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
+    private Map<String, TimeUnit> specificDurationUnits = Collections.emptyMap();
+    private Map<String, TimeUnit> specificRateUnits = Collections.emptyMap();
+    private MetricTimeUnits timeUnit;
+
+    @Activate
+    private void activate(BundleContext context){
+        this.context = context;
+        this.timeUnit = new MetricTimeUnits(rateUnit, durationUnit, specificRateUnits, specificDurationUnits);
+        tracker = new ServiceTracker<MetricRegistry, MetricRegistry>(context, MetricRegistry.class, this);
+        tracker.open();
+    }
+
+    @Deactivate
+    private void deactivate(BundleContext context){
+        tracker.close();
+    }
+
+    //~--------------------------------------------< InventoryPrinter >
+
+    @Override
+    public void print(PrintWriter printWriter, Format format, boolean isZip) {
+        if (format == Format.TEXT) {
+            MetricRegistry registry = getConsolidatedRegistry();
+            ConsoleReporter reporter = ConsoleReporter.forRegistry(registry)
+                    .outputTo(new PrintStream(new WriterOutputStream(printWriter)))
+                    .build();
+            reporter.report();
+            reporter.close();
+        }
+    }
+
+
+    //~---------------------------------------------< ServiceTracker >
+
+    @Override
+    public MetricRegistry addingService(ServiceReference<MetricRegistry> serviceReference) {
+        MetricRegistry registry = context.getService(serviceReference);
+        registries.put(serviceReference, registry);
+        return registry;
+    }
+
+    @Override
+    public void modifiedService(ServiceReference<MetricRegistry> serviceReference, MetricRegistry registry) {
+        registries.put(serviceReference, registry);
+    }
+
+    @Override
+    public void removedService(ServiceReference<MetricRegistry> serviceReference, MetricRegistry registry) {
+        registries.remove(serviceReference);
+    }
+
+    //~----------------------------------------------< Servlet >
+
+    @Override
+    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
+        final PrintWriter pw = resp.getWriter();
+        MetricRegistry registry = getConsolidatedRegistry();
+
+        appendMetricStatus(pw, registry);
+        addCounterDetails(pw, registry.getCounters());
+        addGaugeDetails(pw, registry.getGauges());
+        addMeterDetails(pw, registry.getMeters());
+        addTimerDetails(pw, registry.getTimers());
+        addHistogramDetails(pw, registry.getHistograms());
+    }
+
+    private static void appendMetricStatus(PrintWriter pw, MetricRegistry registry) {
+        pw.printf(
+                "<p class='statline'>Metrics: %d gauges, %d timers, %d meters, %d counters, %d histograms</p>%n",
+                registry.getGauges().size(),
+                registry.getTimers().size(),
+                registry.getMeters().size(),
+                registry.getCounters().size(),
+                registry.getHistograms().size());
+    }
+
+    private void addMeterDetails(PrintWriter pw, SortedMap<String, Meter> meters) {
+        if (meters.isEmpty()) {
+            return;
+        }
+        pw.println("<br>");
+        pw.println("<div class='table'>");
+        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Meters</div>");
+        pw.println("<table class='nicetable'>");
+        pw.println("<thead>");
+        pw.println("<tr>");
+        pw.println("<th class='header'>Name</th>");
+        pw.println("<th class='header'>Count</th>");
+        pw.println("<th class='header'>Mean Rate</th>");
+        pw.println("<th class='header'>OneMinuteRate</th>");
+        pw.println("<th class='header'>FiveMinuteRate</th>");
+        pw.println("<th class='header'>FifteenMinuteRate</ th>");
+        pw.println("<th>RateUnit</th>");
+        pw.println("</tr>");
+        pw.println("</thead>");
+        pw.println("<tbody>");
+
+        String rowClass = "odd";
+        for (Map.Entry<String, Meter> e : meters.entrySet()) {
+            Meter m = e.getValue();
+            String name = e.getKey();
+
+            double rateFactor = timeUnit.rateFor(name).toSeconds(1);
+            String rateUnit = "events/" + calculateRateUnit(timeUnit.rateFor(name));
+            pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
+
+            pw.printf("<td>%s</td>", name);
+            pw.printf("<td>%d</td>", m.getCount());
+            pw.printf("<td>%f</td>", m.getMeanRate() * rateFactor);
+            pw.printf("<td>%f</td>", m.getOneMinuteRate() * rateFactor);
+            pw.printf("<td>%f</td>", m.getFiveMinuteRate() * rateFactor);
+            pw.printf("<td>%f</td>", m.getFifteenMinuteRate() * rateFactor);
+            pw.printf("<td>%s</td>", rateUnit);
+
+            pw.println("</tr>");
+            rowClass = "odd".equals(rowClass) ? "even" : "odd";
+        }
+
+        pw.println("</tbody>");
+        pw.println("</table>");
+        pw.println("</div>");
+    }
+
+    private void addTimerDetails(PrintWriter pw, SortedMap<String, Timer> timers) {
+        if (timers.isEmpty()) {
+            return;
+        }
+
+        pw.println("<br>");
+        pw.println("<div class='table'>");
+        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Timers</div>");
+        pw.println("<table class='nicetable'>");
+        pw.println("<thead>");
+        pw.println("<tr>");
+        pw.println("<th class='header'>Name</th>");
+        pw.println("<th class='header'>Count</th>");
+        pw.println("<th class='header'>Mean Rate</th>");
+        pw.println("<th class='header'>1 min rate</th>");
+        pw.println("<th class='header'>5 mins rate</th>");
+        pw.println("<th class='header'>15 mins rate</th>");
+        pw.println("<th class='header'>50%</th>");
+        pw.println("<th class='header'>Min</th>");
+        pw.println("<th class='header'>Max</th>");
+        pw.println("<th class='header'>Mean</th>");
+        pw.println("<th class='header'>StdDev</th>");
+        pw.println("<th class='header'>75%</th>");
+        pw.println("<th class='header'>95%</th>");
+        pw.println("<th class='header'>98%</th>");
+        pw.println("<th class='header'>99%</th>");
+        pw.println("<th class='header'>999%</th>");
+        pw.println("<th>Rate Unit</th>");
+        pw.println("<th>Duration Unit</th>");
+        pw.println("</tr>");
+        pw.println("</thead>");
+        pw.println("<tbody>");
+
+        String rowClass = "odd";
+        for (Map.Entry<String, Timer> e : timers.entrySet()) {
+            Timer t = e.getValue();
+            Snapshot s = t.getSnapshot();
+            String name = e.getKey();
+
+            double rateFactor = timeUnit.rateFor(name).toSeconds(1);
+            String rateUnit = "events/" + calculateRateUnit(timeUnit.rateFor(name));
+
+            double durationFactor = 1.0 / timeUnit.durationFor(name).toNanos(1);
+            String durationUnit = timeUnit.durationFor(name).toString().toLowerCase(Locale.US);
+
+            pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
+
+            pw.printf("<td>%s</td>", name);
+            pw.printf("<td>%d</td>", t.getCount());
+            pw.printf("<td>%f</td>", t.getMeanRate() * rateFactor);
+            pw.printf("<td>%f</td>", t.getOneMinuteRate() * rateFactor);
+            pw.printf("<td>%f</td>", t.getFiveMinuteRate() * rateFactor);
+            pw.printf("<td>%f</td>", t.getFifteenMinuteRate() * rateFactor);
+
+            pw.printf("<td>%f</td>", s.getMedian() * durationFactor);
+            pw.printf("<td>%f</td>", s.getMin() * durationFactor);
+            pw.printf("<td>%f</td>", s.getMax() * durationFactor);
+            pw.printf("<td>%f</td>", s.getMean() * durationFactor);
+            pw.printf("<td>%f</td>", s.getStdDev() * durationFactor);
+
+            pw.printf("<td>%f</td>", s.get75thPercentile() * durationFactor);
+            pw.printf("<td>%f</td>", s.get95thPercentile() * durationFactor);
+            pw.printf("<td>%f</td>", s.get98thPercentile() * durationFactor);
+            pw.printf("<td>%f</td>", s.get99thPercentile() * durationFactor);
+            pw.printf("<td>%f</td>", s.get999thPercentile() * durationFactor);
+
+            pw.printf("<td>%s</td>", rateUnit);
+            pw.printf("<td>%s</td>", durationUnit);
+
+            pw.println("</tr>");
+            rowClass = "odd".equals(rowClass) ? "even" : "odd";
+        }
+
+        pw.println("</tbody>");
+        pw.println("</table>");
+        pw.println("</div>");
+    }
+
+    private void addHistogramDetails(PrintWriter pw, SortedMap<String, Histogram> histograms) {
+        if (histograms.isEmpty()) {
+            return;
+        }
+
+        pw.println("<br>");
+        pw.println("<div class='table'>");
+        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Histograms</div>");
+        pw.println("<table class='nicetable'>");
+        pw.println("<thead>");
+        pw.println("<tr>");
+        pw.println("<th class='header'>Name</th>");
+        pw.println("<th class='header'>Count</th>");
+        pw.println("<th class='header'>50%</th>");
+        pw.println("<th class='header'>Min</th>");
+        pw.println("<th class='header'>Max</th>");
+        pw.println("<th class='header'>Mean</th>");
+        pw.println("<th class='header'>StdDev</th>");
+        pw.println("<th class='header'>75%</th>");
+        pw.println("<th class='header'>95%</th>");
+        pw.println("<th class='header'>98%</th>");
+        pw.println("<th class='header'>99%</th>");
+        pw.println("<th class='header'>999%</th>");
+        pw.println("<th>Duration Unit</th>");
+        pw.println("</tr>");
+        pw.println("</thead>");
+        pw.println("<tbody>");
+
+        String rowClass = "odd";
+        for (Map.Entry<String, Histogram> e : histograms.entrySet()) {
+            Histogram h = e.getValue();
+            Snapshot s = h.getSnapshot();
+            String name = e.getKey();
+
+            double durationFactor = 1.0 / timeUnit.durationFor(name).toNanos(1);
+            String durationUnit = timeUnit.durationFor(name).toString().toLowerCase(Locale.US);
+            pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
+
+            pw.printf("<td>%s</td>", name);
+            pw.printf("<td>%d</td>", h.getCount());
+            pw.printf("<td>%f</td>", s.getMedian() * durationFactor);
+            pw.printf("<td>%f</td>", s.getMin() * durationFactor);
+            pw.printf("<td>%f</td>", s.getMax() * durationFactor);
+            pw.printf("<td>%f</td>", s.getMean() * durationFactor);
+            pw.printf("<td>%f</td>", s.getStdDev() * durationFactor);
+
+            pw.printf("<td>%f</td>", s.get75thPercentile() * durationFactor);
+            pw.printf("<td>%f</td>", s.get95thPercentile() * durationFactor);
+            pw.printf("<td>%f</td>", s.get98thPercentile() * durationFactor);
+            pw.printf("<td>%f</td>", s.get99thPercentile() * durationFactor);
+            pw.printf("<td>%f</td>", s.get999thPercentile() * durationFactor);
+
+            pw.printf("<td>%s</td>", durationUnit);
+
+            pw.println("</tr>");
+            rowClass = "odd".equals(rowClass) ? "even" : "odd";
+        }
+
+        pw.println("</tbody>");
+        pw.println("</table>");
+        pw.println("</div>");
+    }
+
+    private void addCounterDetails(PrintWriter pw, SortedMap<String, Counter> counters) {
+        if (counters.isEmpty()) {
+            return;
+        }
+        pw.println("<br>");
+        pw.println("<div class='table'>");
+        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Counters</div>");
+        pw.println("<table class='nicetable'>");
+        pw.println("<thead>");
+        pw.println("<tr>");
+        pw.println("<th class='header'>Name</th>");
+        pw.println("<th class='header'>Count</th>");
+        pw.println("</tr>");
+        pw.println("</thead>");
+        pw.println("<tbody>");
+
+        String rowClass = "odd";
+        for (Map.Entry<String, Counter> e : counters.entrySet()) {
+            Counter c = e.getValue();
+            String name = e.getKey();
+
+            pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
+
+            pw.printf("<td>%s</td>", name);
+            pw.printf("<td>%d</td>", c.getCount());
+
+            pw.println("</tr>");
+            rowClass = "odd".equals(rowClass) ? "even" : "odd";
+        }
+
+        pw.println("</tbody>");
+        pw.println("</table>");
+        pw.println("</div>");
+    }
+
+    private void addGaugeDetails(PrintWriter pw, SortedMap<String, Gauge> gauges) {
+        if (gauges.isEmpty()) {
+            return;
+        }
+
+        pw.println("<br>");
+        pw.println("<div class='table'>");
+        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Guages</div>");
+        pw.println("<table class='nicetable'>");
+        pw.println("<thead>");
+        pw.println("<tr>");
+        pw.println("<th class='header'>Name</th>");
+        pw.println("<th class='header'>Value</th>");
+        pw.println("</tr>");
+        pw.println("</thead>");
+        pw.println("<tbody>");
+
+        String rowClass = "odd";
+        for (Map.Entry<String, Gauge> e : gauges.entrySet()) {
+            Gauge g = e.getValue();
+            String name = e.getKey();
+
+            pw.printf("<tr class='%s ui-state-default'>%n", rowClass);
+
+            pw.printf("<td>%s</td>", name);
+            pw.printf("<td>%s</td>", g.getValue());
+
+            pw.println("</tr>");
+            rowClass = "odd".equals(rowClass) ? "even" : "odd";
+        }
+
+        pw.println("</tbody>");
+        pw.println("</table>");
+        pw.println("</div>");
+    }
+
+
+    //~----------------------------------------------< internal >
+
+    private MetricRegistry getConsolidatedRegistry() {
+        MetricRegistry registry = new MetricRegistry();
+        for (Map.Entry<ServiceReference, MetricRegistry> registryEntry : registries.entrySet()){
+            String metricRegistryName = (String) registryEntry.getKey().getProperty(METRIC_REGISTRY_NAME);
+            for (Map.Entry<String, Metric> metricEntry : registryEntry.getValue().getMetrics().entrySet()){
+                String metricName = metricEntry.getKey();
+                try{
+                    if (metricRegistryName != null){
+                        metricName = metricRegistryName + ":" + metricName;
+                    }
+                    registry.register(metricName, metricEntry.getValue());
+                }catch (IllegalArgumentException ex){
+                    log.warn("Duplicate Metric name found {}", metricName, ex);
+                }
+            }
+        }
+        return registry;
+    }
+
+    private static String calculateRateUnit(TimeUnit unit) {
+        final String s = unit.toString().toLowerCase(Locale.US);
+        return s.substring(0, s.length() - 1);
+    }
+
+    private static class MetricTimeUnits {
+        private final TimeUnit defaultRate;
+        private final TimeUnit defaultDuration;
+        private final Map<String, TimeUnit> rateOverrides;
+        private final Map<String, TimeUnit> durationOverrides;
+
+        MetricTimeUnits(TimeUnit defaultRate,
+                        TimeUnit defaultDuration,
+                        Map<String, TimeUnit> rateOverrides,
+                        Map<String, TimeUnit> durationOverrides) {
+            this.defaultRate = defaultRate;
+            this.defaultDuration = defaultDuration;
+            this.rateOverrides = rateOverrides;
+            this.durationOverrides = durationOverrides;
+        }
+
+        public TimeUnit durationFor(String name) {
+            return durationOverrides.containsKey(name) ? durationOverrides.get(name) : defaultDuration;
+        }
+
+        public TimeUnit rateFor(String name) {
+            return rateOverrides.containsKey(name) ? rateOverrides.get(name) : defaultRate;
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/metrics/internal/MetricsServiceImpl.java b/src/main/java/org/apache/sling/metrics/internal/MetricsServiceImpl.java
new file mode 100644
index 0000000..dea3ea2
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/internal/MetricsServiceImpl.java
@@ -0,0 +1,199 @@
+/*
+ * 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.sling.metrics.internal;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.management.MBeanServer;
+
+import com.codahale.metrics.JmxReporter;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.sling.metrics.Counter;
+import org.apache.sling.metrics.Histogram;
+import org.apache.sling.metrics.Meter;
+import org.apache.sling.metrics.Metric;
+import org.apache.sling.metrics.MetricsService;
+import org.apache.sling.metrics.Timer;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+@Component
+public class MetricsServiceImpl implements MetricsService{
+    private final List<ServiceRegistration> regs = new ArrayList<ServiceRegistration>();
+    private final ConcurrentMap<String, Metric> metrics = new ConcurrentHashMap<String, Metric>();
+    private final MetricRegistry registry = new MetricRegistry();
+
+    @Reference
+    private MBeanServer server;
+
+    private JmxReporter reporter;
+
+    @Activate
+    private void activate(BundleContext context, Map<String, Object> config) {
+        //TODO Domain name should be based on calling bundle
+        //For that we can register ServiceFactory and make use of calling
+        //bundle symbolic name to determine the mapping
+
+        reporter = JmxReporter.forRegistry(registry)
+                .inDomain("org.apache.sling")
+                .registerWith(server)
+                .build();
+
+        final Dictionary<String, String> svcProps = new Hashtable<String, String>();
+        svcProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics Service");
+        svcProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+        regs.add(context.registerService(MetricsService.class.getName(), this, svcProps));
+
+        final Dictionary<String, String> regProps = new Hashtable<String, String>();
+        regProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Metrics Registry");
+        regProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+        regProps.put("name", "sling");
+        regs.add(context.registerService(MetricRegistry.class.getName(), registry, regProps));
+    }
+
+    @Deactivate
+    private void deactivate() throws IOException {
+        for (ServiceRegistration reg : regs) {
+            reg.unregister();
+        }
+        regs.clear();
+
+        metrics.clear();
+
+        if (reporter != null) {
+            reporter.close();
+        }
+    }
+
+    @Override
+    public Timer timer(String name) {
+        return getOrAdd(name, MetricBuilder.TIMERS);
+    }
+
+    @Override
+    public Histogram histogram(String name) {
+        return getOrAdd(name, MetricBuilder.HISTOGRAMS);
+    }
+
+    @Override
+    public Counter counter(String name) {
+        return getOrAdd(name, MetricBuilder.COUNTERS);
+    }
+
+    @Override
+    public Meter meter(String name) {
+        return getOrAdd(name, MetricBuilder.METERS);
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T extends Metric> T getOrAdd(String name, MetricBuilder<T> builder) {
+        final Metric metric = metrics.get(name);
+        if (builder.isInstance(metric)) {
+            return (T) metric;
+        } else if (metric == null) {
+            try {
+                return register(name, builder.newMetric(registry, name));
+            } catch (IllegalArgumentException e) {
+                final Metric added = metrics.get(name);
+                if (builder.isInstance(added)) {
+                    return (T) added;
+                }
+            }
+        }
+        throw new IllegalArgumentException(name + " is already used for a different type of metric");
+    }
+
+    private <T extends Metric> T register(String name, T metric) throws IllegalArgumentException {
+        final Metric existing = metrics.putIfAbsent(name, metric);
+        if (existing != null) {
+            throw new IllegalArgumentException("A metric named " + name + " already exists");
+        }
+        return metric;
+    }
+
+    /**
+     * A quick and easy way of capturing the notion of default metrics.
+     */
+    private interface MetricBuilder<T extends Metric> {
+        MetricBuilder<Counter> COUNTERS = new MetricBuilder<Counter>() {
+            @Override
+            public Counter newMetric(MetricRegistry registry, String name) {
+                return new CounterImpl(registry.counter(name));
+            }
+
+            @Override
+            public boolean isInstance(Metric metric) {
+                return Counter.class.isInstance(metric);
+            }
+        };
+
+        MetricBuilder<Histogram> HISTOGRAMS = new MetricBuilder<Histogram>() {
+            @Override
+            public Histogram newMetric(MetricRegistry registry, String name) {
+                return new HistogramImpl(registry.histogram(name));
+            }
+
+            @Override
+            public boolean isInstance(Metric metric) {
+                return Histogram.class.isInstance(metric);
+            }
+        };
+
+        MetricBuilder<Meter> METERS = new MetricBuilder<Meter>() {
+            @Override
+            public Meter newMetric(MetricRegistry registry, String name) {
+                return new MeterImpl(registry.meter(name));
+            }
+
+            @Override
+            public boolean isInstance(Metric metric) {
+                return Meter.class.isInstance(metric);
+            }
+        };
+
+        MetricBuilder<Timer> TIMERS = new MetricBuilder<Timer>() {
+            @Override
+            public Timer newMetric(MetricRegistry registry, String name) {
+                return new TimerImpl(registry.timer(name));
+            }
+
+            @Override
+            public boolean isInstance(Metric metric) {
+                return Timer.class.isInstance(metric);
+            }
+        };
+
+        T newMetric(MetricRegistry registry, String name);
+
+        boolean isInstance(Metric metric);
+    }
+}
diff --git a/src/main/java/org/apache/sling/metrics/internal/TimerImpl.java b/src/main/java/org/apache/sling/metrics/internal/TimerImpl.java
new file mode 100644
index 0000000..54fd39c
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/internal/TimerImpl.java
@@ -0,0 +1,77 @@
+/*
+ * 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.sling.metrics.internal;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.sling.metrics.Timer;
+
+
+final class TimerImpl implements Timer {
+    private final com.codahale.metrics.Timer timer;
+
+    TimerImpl(com.codahale.metrics.Timer timer) {
+        this.timer = timer;
+    }
+
+    @Override
+    public void update(long duration, TimeUnit unit) {
+        timer.update(duration, unit);
+    }
+
+    @Override
+    public Context time() {
+        return new ContextImpl(timer.time());
+    }
+
+    @Override
+    public long getCount() {
+        return timer.getCount();
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <A> A adaptTo(Class<A> type) {
+        if (type == com.codahale.metrics.Timer.class) {
+            return (A) timer;
+        }
+        return null;
+    }
+
+    private static final class ContextImpl implements Context {
+        private final com.codahale.metrics.Timer.Context context;
+
+        private ContextImpl(com.codahale.metrics.Timer.Context context) {
+            this.context = context;
+        }
+
+        public long stop() {
+            return context.stop();
+        }
+
+        /**
+         * Equivalent to calling {@link #stop()}.
+         */
+        @Override
+        public void close() {
+            stop();
+        }
+    }
+}
diff --git a/src/main/java/org/apache/sling/metrics/package-info.java b/src/main/java/org/apache/sling/metrics/package-info.java
new file mode 100644
index 0000000..9b4ae51
--- /dev/null
+++ b/src/main/java/org/apache/sling/metrics/package-info.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides configuration support for the Logback based logging in Sling
+ *
+ * @version 1.0
+ */
+@Version("1.0")
+@Export(optional = "provide:=true")
+package org.apache.sling.metrics;
+
+import aQute.bnd.annotation.Export;
+import aQute.bnd.annotation.Version;
+
diff --git a/src/test/java/org/apache/sling/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/metrics/internal/MetricServiceTest.java
new file mode 100644
index 0000000..e62daad
--- /dev/null
+++ b/src/test/java/org/apache/sling/metrics/internal/MetricServiceTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.sling.metrics.internal;
+
+import java.lang.management.ManagementFactory;
+import java.util.Collections;
+
+import javax.management.MBeanServer;
+
+import com.codahale.metrics.MetricRegistry;
+import org.apache.sling.metrics.Counter;
+import org.apache.sling.metrics.Histogram;
+import org.apache.sling.metrics.Meter;
+import org.apache.sling.metrics.MetricsService;
+import org.apache.sling.metrics.Timer;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+public class MetricServiceTest {
+    @Rule
+    public final OsgiContext context = new OsgiContext();
+
+    private MetricsServiceImpl service = new MetricsServiceImpl();
+
+    @After
+    public void registerMBeanServer() {
+        context.registerService(MBeanServer.class, ManagementFactory.getPlatformMBeanServer());
+    }
+
+    @Test
+    public void defaultSetup() throws Exception{
+        activate();
+
+        assertNotNull(context.getService(MetricRegistry.class));
+        assertNotNull(context.getService(MetricsService.class));
+
+        MockOsgi.deactivate(service);
+
+        assertNull(context.getService(MetricRegistry.class));
+        assertNull(context.getService(MetricsService.class));
+    }
+
+    @Test
+    public void meter() throws Exception{
+        activate();
+        Meter meter = service.meter("test");
+
+        assertNotNull(meter);
+        assertTrue(getRegistry().getMeters().containsKey("test"));
+
+        assertSame(meter, service.meter("test"));
+    }
+
+    @Test
+    public void counter() throws Exception{
+        activate();
+        Counter counter = service.counter("test");
+
+        assertNotNull(counter);
+        assertTrue(getRegistry().getCounters().containsKey("test"));
+
+        assertSame(counter, service.counter("test"));
+    }
+
+    @Test
+    public void timer() throws Exception{
+        activate();
+        Timer timer = service.timer("test");
+
+        assertNotNull(timer);
+        assertTrue(getRegistry().getTimers().containsKey("test"));
+
+        assertSame(timer, service.timer("test"));
+    }
+
+    @Test
+    public void histogram() throws Exception{
+        activate();
+        Histogram histo = service.histogram("test");
+
+        assertNotNull(histo);
+        assertTrue(getRegistry().getHistograms().containsKey("test"));
+
+        assertSame(histo, service.histogram("test"));
+    }
+
+    private MetricRegistry getRegistry(){
+        return context.getService(MetricRegistry.class);
+    }
+
+    private void activate() {
+        MockOsgi.activate(service, context.bundleContext(), Collections.<String, Object>emptyMap());
+    }
+
+}
diff --git a/src/test/java/org/apache/sling/metrics/internal/MetricWrapperTest.java b/src/test/java/org/apache/sling/metrics/internal/MetricWrapperTest.java
new file mode 100644
index 0000000..898626c
--- /dev/null
+++ b/src/test/java/org/apache/sling/metrics/internal/MetricWrapperTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.sling.metrics.internal;
+
+import java.util.concurrent.TimeUnit;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.ExponentiallyDecayingReservoir;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+public class MetricWrapperTest {
+    private MetricRegistry registry = new MetricRegistry();
+
+    @Test
+    public void counter() throws Exception {
+        Counter counter = registry.counter("test");
+        CounterImpl counterStats = new CounterImpl(counter);
+
+        counterStats.inc();
+        assertEquals(1, counterStats.getCount());
+        assertEquals(1, counter.getCount());
+        assertEquals(1, counterStats.getCount());
+
+        counterStats.inc();
+        counterStats.inc();
+        assertEquals(3, counterStats.getCount());
+
+        counterStats.dec();
+        assertEquals(2, counterStats.getCount());
+        assertEquals(2, counter.getCount());
+
+        counterStats.inc(7);
+        assertEquals(9, counterStats.getCount());
+        assertEquals(9, counter.getCount());
+
+        counterStats.dec(5);
+        assertEquals(4, counterStats.getCount());
+        assertEquals(4, counter.getCount());
+
+        assertSame(counter, counterStats.adaptTo(Counter.class));
+    }
+
+    @Test
+    public void meter() throws Exception {
+        Meter meter = registry.meter("test");
+        MeterImpl meterStats = new MeterImpl(meter);
+
+        meterStats.mark();
+        assertEquals(1, meterStats.getCount());
+        assertEquals(1, meter.getCount());
+
+        meterStats.mark(5);
+        assertEquals(6, meterStats.getCount());
+        assertEquals(6, meter.getCount());
+        assertSame(meter, meterStats.adaptTo(Meter.class));
+    }
+
+    @Test
+    public void timer() throws Exception {
+        Timer time = registry.timer("test");
+        TimerImpl timerStats = new TimerImpl(time);
+
+        timerStats.update(100, TimeUnit.SECONDS);
+        assertEquals(1, time.getCount());
+        assertEquals(TimeUnit.SECONDS.toNanos(100), time.getSnapshot().getMax());
+
+        timerStats.update(100, TimeUnit.SECONDS);
+        assertEquals(2, timerStats.getCount());
+
+        assertSame(time, timerStats.adaptTo(Timer.class));
+    }
+
+    @Test
+    public void histogram() throws Exception {
+        Histogram histo = registry.histogram("test");
+        HistogramImpl histoStats = new HistogramImpl(histo);
+
+        histoStats.update(100);
+        assertEquals(1, histo.getCount());
+        assertEquals(1, histoStats.getCount());
+        assertEquals(100, histo.getSnapshot().getMax());
+
+        assertSame(histo, histoStats.adaptTo(Histogram.class));
+    }
+
+    @Test
+    public void timerContext() throws Exception{
+        VirtualClock clock = new VirtualClock();
+        Timer time = new Timer(new ExponentiallyDecayingReservoir(), clock);
+
+        TimerImpl timerStats = new TimerImpl(time);
+        org.apache.sling.metrics.Timer.Context context = timerStats.time();
+
+        clock.tick = TimeUnit.SECONDS.toNanos(314);
+        context.close();
+
+        assertEquals(1, time.getCount());
+        assertEquals(TimeUnit.SECONDS.toNanos(314), time.getSnapshot().getMax());
+    }
+
+    private static class VirtualClock extends com.codahale.metrics.Clock {
+        long tick;
+        @Override
+        public long getTick() {
+            return tick;
+        }
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 33/44: use Sling Parent 30

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 2e2aeb6534053674c6a89c681b921574f3ab395a
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Mon Mar 6 10:22:30 2017 +0000

    use Sling Parent 30
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1785621 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 7937633..2035102 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>29</version>
+        <version>30</version>
     </parent>
 
     <artifactId>org.apache.sling.commons.metrics</artifactId>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 03/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit bb6b4120404fd63f873578763a92f89b78afaddd
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 04:39:38 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Rename the package to 'org.apache.sling.commons.metrics'
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723459 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/{ => commons}/metrics/Counter.java  |  2 +-
 .../org/apache/sling/{ => commons}/metrics/Counting.java |  2 +-
 .../apache/sling/{ => commons}/metrics/Histogram.java    |  2 +-
 .../org/apache/sling/{ => commons}/metrics/Meter.java    |  2 +-
 .../org/apache/sling/{ => commons}/metrics/Metric.java   |  2 +-
 .../sling/{ => commons}/metrics/MetricsService.java      |  2 +-
 .../apache/sling/{ => commons}/metrics/NoopMetric.java   |  2 +-
 .../org/apache/sling/{ => commons}/metrics/Timer.java    |  2 +-
 .../{ => commons}/metrics/internal/CounterImpl.java      |  4 ++--
 .../{ => commons}/metrics/internal/HistogramImpl.java    |  4 ++--
 .../sling/{ => commons}/metrics/internal/MeterImpl.java  |  4 ++--
 .../metrics/internal/MetricWebConsolePlugin.java         |  2 +-
 .../metrics/internal/MetricsServiceImpl.java             | 16 ++++++++--------
 .../sling/{ => commons}/metrics/internal/TimerImpl.java  |  4 ++--
 .../apache/sling/{ => commons}/metrics/package-info.java |  2 +-
 .../metrics/internal/MetricServiceTest.java              | 12 ++++++------
 .../metrics/internal/MetricWrapperTest.java              |  4 ++--
 17 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/src/main/java/org/apache/sling/metrics/Counter.java b/src/main/java/org/apache/sling/commons/metrics/Counter.java
similarity index 97%
rename from src/main/java/org/apache/sling/metrics/Counter.java
rename to src/main/java/org/apache/sling/commons/metrics/Counter.java
index b828aa5..a4b317a 100644
--- a/src/main/java/org/apache/sling/metrics/Counter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Counter.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics;
+package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
diff --git a/src/main/java/org/apache/sling/metrics/Counting.java b/src/main/java/org/apache/sling/commons/metrics/Counting.java
similarity index 96%
rename from src/main/java/org/apache/sling/metrics/Counting.java
rename to src/main/java/org/apache/sling/commons/metrics/Counting.java
index 309decd..890d650 100644
--- a/src/main/java/org/apache/sling/metrics/Counting.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Counting.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics;
+package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
diff --git a/src/main/java/org/apache/sling/metrics/Histogram.java b/src/main/java/org/apache/sling/commons/metrics/Histogram.java
similarity index 96%
rename from src/main/java/org/apache/sling/metrics/Histogram.java
rename to src/main/java/org/apache/sling/commons/metrics/Histogram.java
index 37938f5..3d1e082 100644
--- a/src/main/java/org/apache/sling/metrics/Histogram.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Histogram.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics;
+package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
diff --git a/src/main/java/org/apache/sling/metrics/Meter.java b/src/main/java/org/apache/sling/commons/metrics/Meter.java
similarity index 96%
rename from src/main/java/org/apache/sling/metrics/Meter.java
rename to src/main/java/org/apache/sling/commons/metrics/Meter.java
index a4914d7..e239c54 100644
--- a/src/main/java/org/apache/sling/metrics/Meter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Meter.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics;
+package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
diff --git a/src/main/java/org/apache/sling/metrics/Metric.java b/src/main/java/org/apache/sling/commons/metrics/Metric.java
similarity index 96%
rename from src/main/java/org/apache/sling/metrics/Metric.java
rename to src/main/java/org/apache/sling/commons/metrics/Metric.java
index 4952017..b8a12bb 100644
--- a/src/main/java/org/apache/sling/metrics/Metric.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Metric.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics;
+package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
diff --git a/src/main/java/org/apache/sling/metrics/MetricsService.java b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
similarity index 98%
rename from src/main/java/org/apache/sling/metrics/MetricsService.java
rename to src/main/java/org/apache/sling/commons/metrics/MetricsService.java
index 8c51d4b..8d2c04f 100644
--- a/src/main/java/org/apache/sling/metrics/MetricsService.java
+++ b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics;
+package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.ProviderType;
 
diff --git a/src/main/java/org/apache/sling/metrics/NoopMetric.java b/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
similarity index 97%
rename from src/main/java/org/apache/sling/metrics/NoopMetric.java
rename to src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
index 210fb3c..f1595ff 100644
--- a/src/main/java/org/apache/sling/metrics/NoopMetric.java
+++ b/src/main/java/org/apache/sling/commons/metrics/NoopMetric.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics;
+package org.apache.sling.commons.metrics;
 
 import java.util.concurrent.TimeUnit;
 
diff --git a/src/main/java/org/apache/sling/metrics/Timer.java b/src/main/java/org/apache/sling/commons/metrics/Timer.java
similarity index 97%
rename from src/main/java/org/apache/sling/metrics/Timer.java
rename to src/main/java/org/apache/sling/commons/metrics/Timer.java
index 602a0cb..a142953 100644
--- a/src/main/java/org/apache/sling/metrics/Timer.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Timer.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics;
+package org.apache.sling.commons.metrics;
 
 import java.io.Closeable;
 import java.util.concurrent.TimeUnit;
diff --git a/src/main/java/org/apache/sling/metrics/internal/CounterImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
similarity index 94%
rename from src/main/java/org/apache/sling/metrics/internal/CounterImpl.java
rename to src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
index 0137b71..f929410 100644
--- a/src/main/java/org/apache/sling/metrics/internal/CounterImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/CounterImpl.java
@@ -17,10 +17,10 @@
  * under the License.
  */
 
-package org.apache.sling.metrics.internal;
+package org.apache.sling.commons.metrics.internal;
 
 
-import org.apache.sling.metrics.Counter;
+import org.apache.sling.commons.metrics.Counter;
 
 final class CounterImpl implements Counter {
     private final com.codahale.metrics.Counter counter;
diff --git a/src/main/java/org/apache/sling/metrics/internal/HistogramImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/HistogramImpl.java
similarity index 93%
rename from src/main/java/org/apache/sling/metrics/internal/HistogramImpl.java
rename to src/main/java/org/apache/sling/commons/metrics/internal/HistogramImpl.java
index 15117e9..3507e3a 100644
--- a/src/main/java/org/apache/sling/metrics/internal/HistogramImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/HistogramImpl.java
@@ -17,10 +17,10 @@
  * under the License.
  */
 
-package org.apache.sling.metrics.internal;
+package org.apache.sling.commons.metrics.internal;
 
 
-import org.apache.sling.metrics.Histogram;
+import org.apache.sling.commons.metrics.Histogram;
 
 final class HistogramImpl implements Histogram {
     private final com.codahale.metrics.Histogram histogram;
diff --git a/src/main/java/org/apache/sling/metrics/internal/MeterImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/MeterImpl.java
similarity index 93%
rename from src/main/java/org/apache/sling/metrics/internal/MeterImpl.java
rename to src/main/java/org/apache/sling/commons/metrics/internal/MeterImpl.java
index 719d356..83d4ff7 100644
--- a/src/main/java/org/apache/sling/metrics/internal/MeterImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MeterImpl.java
@@ -17,9 +17,9 @@
  * under the License.
  */
 
-package org.apache.sling.metrics.internal;
+package org.apache.sling.commons.metrics.internal;
 
-import org.apache.sling.metrics.Meter;
+import org.apache.sling.commons.metrics.Meter;
 
 final class MeterImpl implements Meter {
     private final com.codahale.metrics.Meter meter;
diff --git a/src/main/java/org/apache/sling/metrics/internal/MetricWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
similarity index 99%
rename from src/main/java/org/apache/sling/metrics/internal/MetricWebConsolePlugin.java
rename to src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index 180acca..8796168 100644
--- a/src/main/java/org/apache/sling/metrics/internal/MetricWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics.internal;
+package org.apache.sling.commons.metrics.internal;
 
 import java.io.IOException;
 import java.io.PrintStream;
diff --git a/src/main/java/org/apache/sling/metrics/internal/MetricsServiceImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
similarity index 94%
rename from src/main/java/org/apache/sling/metrics/internal/MetricsServiceImpl.java
rename to src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
index dea3ea2..729d555 100644
--- a/src/main/java/org/apache/sling/metrics/internal/MetricsServiceImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics.internal;
+package org.apache.sling.commons.metrics.internal;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -36,18 +36,18 @@ import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Reference;
-import org.apache.sling.metrics.Counter;
-import org.apache.sling.metrics.Histogram;
-import org.apache.sling.metrics.Meter;
-import org.apache.sling.metrics.Metric;
-import org.apache.sling.metrics.MetricsService;
-import org.apache.sling.metrics.Timer;
+import org.apache.sling.commons.metrics.Meter;
+import org.apache.sling.commons.metrics.MetricsService;
+import org.apache.sling.commons.metrics.Timer;
+import org.apache.sling.commons.metrics.Counter;
+import org.apache.sling.commons.metrics.Histogram;
+import org.apache.sling.commons.metrics.Metric;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
 
 @Component
-public class MetricsServiceImpl implements MetricsService{
+public class MetricsServiceImpl implements MetricsService {
     private final List<ServiceRegistration> regs = new ArrayList<ServiceRegistration>();
     private final ConcurrentMap<String, Metric> metrics = new ConcurrentHashMap<String, Metric>();
     private final MetricRegistry registry = new MetricRegistry();
diff --git a/src/main/java/org/apache/sling/metrics/internal/TimerImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/TimerImpl.java
similarity index 95%
rename from src/main/java/org/apache/sling/metrics/internal/TimerImpl.java
rename to src/main/java/org/apache/sling/commons/metrics/internal/TimerImpl.java
index 54fd39c..cf9d87f 100644
--- a/src/main/java/org/apache/sling/metrics/internal/TimerImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/TimerImpl.java
@@ -17,11 +17,11 @@
  * under the License.
  */
 
-package org.apache.sling.metrics.internal;
+package org.apache.sling.commons.metrics.internal;
 
 import java.util.concurrent.TimeUnit;
 
-import org.apache.sling.metrics.Timer;
+import org.apache.sling.commons.metrics.Timer;
 
 
 final class TimerImpl implements Timer {
diff --git a/src/main/java/org/apache/sling/metrics/package-info.java b/src/main/java/org/apache/sling/commons/metrics/package-info.java
similarity index 96%
rename from src/main/java/org/apache/sling/metrics/package-info.java
rename to src/main/java/org/apache/sling/commons/metrics/package-info.java
index 9b4ae51..1180f06 100644
--- a/src/main/java/org/apache/sling/metrics/package-info.java
+++ b/src/main/java/org/apache/sling/commons/metrics/package-info.java
@@ -24,7 +24,7 @@
  */
 @Version("1.0")
 @Export(optional = "provide:=true")
-package org.apache.sling.metrics;
+package org.apache.sling.commons.metrics;
 
 import aQute.bnd.annotation.Export;
 import aQute.bnd.annotation.Version;
diff --git a/src/test/java/org/apache/sling/metrics/internal/MetricServiceTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
similarity index 91%
rename from src/test/java/org/apache/sling/metrics/internal/MetricServiceTest.java
rename to src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
index e62daad..9dff1e9 100644
--- a/src/test/java/org/apache/sling/metrics/internal/MetricServiceTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricServiceTest.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics.internal;
+package org.apache.sling.commons.metrics.internal;
 
 import java.lang.management.ManagementFactory;
 import java.util.Collections;
@@ -25,11 +25,11 @@ import java.util.Collections;
 import javax.management.MBeanServer;
 
 import com.codahale.metrics.MetricRegistry;
-import org.apache.sling.metrics.Counter;
-import org.apache.sling.metrics.Histogram;
-import org.apache.sling.metrics.Meter;
-import org.apache.sling.metrics.MetricsService;
-import org.apache.sling.metrics.Timer;
+import org.apache.sling.commons.metrics.Counter;
+import org.apache.sling.commons.metrics.Histogram;
+import org.apache.sling.commons.metrics.Meter;
+import org.apache.sling.commons.metrics.MetricsService;
+import org.apache.sling.commons.metrics.Timer;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
 import org.junit.After;
diff --git a/src/test/java/org/apache/sling/metrics/internal/MetricWrapperTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
similarity index 96%
rename from src/test/java/org/apache/sling/metrics/internal/MetricWrapperTest.java
rename to src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
index 898626c..5489b31 100644
--- a/src/test/java/org/apache/sling/metrics/internal/MetricWrapperTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWrapperTest.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.metrics.internal;
+package org.apache.sling.commons.metrics.internal;
 
 import java.util.concurrent.TimeUnit;
 
@@ -113,7 +113,7 @@ public class MetricWrapperTest {
         Timer time = new Timer(new ExponentiallyDecayingReservoir(), clock);
 
         TimerImpl timerStats = new TimerImpl(time);
-        org.apache.sling.metrics.Timer.Context context = timerStats.time();
+        org.apache.sling.commons.metrics.Timer.Context context = timerStats.time();
 
         clock.tick = TimeUnit.SECONDS.toNanos(314);
         context.close();

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 10/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 288c00677897babdd8fd3c3b1d1009492adfa2df
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 10:07:59 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Cleanup pom
    -- Make dependencies for WebConsole plugin optional and have DynamicImport package for them
    -- Removed unused dependencies
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723503 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/pom.xml b/pom.xml
index 641d996..4e6a5f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,19 @@
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
         <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Bundle-DocURL>
+              https://sling.apache.org/documentation/bundles/metrics.html
+            </Bundle-DocURL>
+            <DynamicImport-Package>
+              javax.servlet,
+              javax.servlet.http;version=2.3,
+              org.apache.commons.io.output;version=2.4.0,
+              org.apache.felix.inventory;version=1.0
+            </DynamicImport-Package>
+          </instructions>
+        </configuration>
       </plugin>
       <plugin>
         <groupId>org.apache.felix</groupId>
@@ -73,11 +86,7 @@
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.sling</groupId>
-      <artifactId>org.apache.sling.commons.osgi</artifactId>
-      <version>2.2.0</version>
+      <optional>true</optional>
     </dependency>
     <dependency>
       <groupId>org.osgi</groupId>
@@ -102,12 +111,14 @@
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>2.2</version>
+      <optional>true</optional>
     </dependency>
 
     <dependency>
       <groupId>org.hamcrest</groupId>
       <artifactId>hamcrest-all</artifactId>
       <version>1.3</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>junit</groupId>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 27/44: SLING-6297 - Switch to standard OSGi annotation in Metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit fc929340e3e71ebc3e86688a17e07f39cedbe004
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Nov 17 06:56:52 2016 +0000

    SLING-6297 - Switch to standard OSGi annotation in Metrics
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1770126 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 23 +++++++++-----
 .../org/apache/sling/commons/metrics/Counter.java  |  3 +-
 .../org/apache/sling/commons/metrics/Counting.java |  3 +-
 .../org/apache/sling/commons/metrics/Gauge.java    |  3 +-
 .../apache/sling/commons/metrics/Histogram.java    |  3 +-
 .../org/apache/sling/commons/metrics/Meter.java    |  3 +-
 .../org/apache/sling/commons/metrics/Metric.java   |  3 +-
 .../sling/commons/metrics/MetricsService.java      |  3 +-
 .../org/apache/sling/commons/metrics/Timer.java    |  3 +-
 .../metrics/internal/MetricWebConsolePlugin.java   | 35 ++++++++++------------
 .../metrics/internal/MetricsServiceImpl.java       | 14 ++++-----
 .../apache/sling/commons/metrics/package-info.java |  4 +--
 12 files changed, 55 insertions(+), 45 deletions(-)

diff --git a/pom.xml b/pom.xml
index 3a45b75..31cfea9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,11 +64,21 @@
               org.apache.felix.inventory;version="[1.0.0,2)"
             </DynamicImport-Package>
           </instructions>
+          <!-- Export SCR metadata to classpath to have them available in unit tests -->
+          <exportScr>true</exportScr>
         </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-scr-plugin</artifactId>
+        <executions>
+          <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
+          <execution>
+            <id>scr-metadata</id>
+            <goals>
+              <goal>manifest</goal>
+            </goals>
+            <configuration>
+              <supportIncrementalBuild>true</supportIncrementalBuild>
+            </configuration>
+          </execution>
+        </executions>
       </plugin>
     </plugins>
   </build>
@@ -91,14 +101,10 @@
     <dependency>
       <groupId>org.osgi</groupId>
       <artifactId>osgi.core</artifactId>
-      <version>6.0.0</version>
-      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.osgi</groupId>
       <artifactId>osgi.cmpn</artifactId>
-      <version>6.0.0</version>
-      <scope>provided</scope>
     </dependency>
 
     <dependency>
@@ -141,6 +147,7 @@
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
       <version>1.10.19</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
diff --git a/src/main/java/org/apache/sling/commons/metrics/Counter.java b/src/main/java/org/apache/sling/commons/metrics/Counter.java
index 8269d5b..64730dd 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Counter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Counter.java
@@ -19,7 +19,8 @@
 
 package org.apache.sling.commons.metrics;
 
-import aQute.bnd.annotation.ProviderType;
+
+import org.osgi.annotation.versioning.ProviderType;
 
 /**
  * An incrementing and decrementing counter metric.
diff --git a/src/main/java/org/apache/sling/commons/metrics/Counting.java b/src/main/java/org/apache/sling/commons/metrics/Counting.java
index 890d650..f974ea6 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Counting.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Counting.java
@@ -19,7 +19,8 @@
 
 package org.apache.sling.commons.metrics;
 
-import aQute.bnd.annotation.ProviderType;
+
+import org.osgi.annotation.versioning.ProviderType;
 
 @ProviderType
 public interface Counting {
diff --git a/src/main/java/org/apache/sling/commons/metrics/Gauge.java b/src/main/java/org/apache/sling/commons/metrics/Gauge.java
index ac723a6..9813120 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Gauge.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Gauge.java
@@ -19,7 +19,8 @@
 
 package org.apache.sling.commons.metrics;
 
-import aQute.bnd.annotation.ConsumerType;
+
+import org.osgi.annotation.versioning.ConsumerType;
 
 /**
  * A gauge metric is an instantaneous reading of a particular value. To instrument a queue's depth,
diff --git a/src/main/java/org/apache/sling/commons/metrics/Histogram.java b/src/main/java/org/apache/sling/commons/metrics/Histogram.java
index 7f87cdc..d78f3a8 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Histogram.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Histogram.java
@@ -19,7 +19,8 @@
 
 package org.apache.sling.commons.metrics;
 
-import aQute.bnd.annotation.ProviderType;
+
+import org.osgi.annotation.versioning.ProviderType;
 
 /**
  * A metric which calculates the distribution of a value.
diff --git a/src/main/java/org/apache/sling/commons/metrics/Meter.java b/src/main/java/org/apache/sling/commons/metrics/Meter.java
index 3fef3f8..6674fbf 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Meter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Meter.java
@@ -19,7 +19,8 @@
 
 package org.apache.sling.commons.metrics;
 
-import aQute.bnd.annotation.ProviderType;
+
+import org.osgi.annotation.versioning.ProviderType;
 
 /**
  * A meter metric which measures mean throughput
diff --git a/src/main/java/org/apache/sling/commons/metrics/Metric.java b/src/main/java/org/apache/sling/commons/metrics/Metric.java
index b8a12bb..bf07b69 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Metric.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Metric.java
@@ -19,7 +19,8 @@
 
 package org.apache.sling.commons.metrics;
 
-import aQute.bnd.annotation.ProviderType;
+
+import org.osgi.annotation.versioning.ProviderType;
 
 @ProviderType
 public interface Metric {
diff --git a/src/main/java/org/apache/sling/commons/metrics/MetricsService.java b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
index 56e87e6..5bf4eae 100644
--- a/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
+++ b/src/main/java/org/apache/sling/commons/metrics/MetricsService.java
@@ -19,7 +19,8 @@
 
 package org.apache.sling.commons.metrics;
 
-import aQute.bnd.annotation.ProviderType;
+
+import org.osgi.annotation.versioning.ProviderType;
 
 /**
  * The {@code MetricsService} enables creation of various types of {@code Metric}.
diff --git a/src/main/java/org/apache/sling/commons/metrics/Timer.java b/src/main/java/org/apache/sling/commons/metrics/Timer.java
index 8de1707..f5d79cb 100644
--- a/src/main/java/org/apache/sling/commons/metrics/Timer.java
+++ b/src/main/java/org/apache/sling/commons/metrics/Timer.java
@@ -22,7 +22,8 @@ package org.apache.sling.commons.metrics;
 import java.io.Closeable;
 import java.util.concurrent.TimeUnit;
 
-import aQute.bnd.annotation.ProviderType;
+import org.osgi.annotation.versioning.ProviderType;
+
 
 /**
  * A timer metric which aggregates timing durations and provides duration statistics.
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index d0321ef..0ebc173 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -47,30 +47,27 @@ import com.codahale.metrics.Timer;
 import org.apache.commons.io.output.WriterOutputStream;
 import org.apache.felix.inventory.Format;
 import org.apache.felix.inventory.InventoryPrinter;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@Component
-@Service(value = {InventoryPrinter.class, Servlet.class})
-@Properties({
-        @Property(name = "felix.webconsole.label", value = "slingmetrics"),
-        @Property(name = "felix.webconsole.title", value = "Metrics"),
-        @Property(name = "felix.webconsole.category", value = "Sling"),
-        @Property(name = InventoryPrinter.FORMAT, value = {"TEXT" , "JSON"}),
-        @Property(name = InventoryPrinter.NAME, value = "slingmetrics"),
-        @Property(name = InventoryPrinter.TITLE, value = "Sling Metrics"),
-        @Property(name = InventoryPrinter.WEBCONSOLE, boolValue = true)
-})
+@Component(service = {InventoryPrinter.class, Servlet.class},
+        property = {
+                "felix.webconsole.label=slingmetrics",
+                "felix.webconsole.title=Metrics",
+                "felix.webconsole.category=Sling",
+                InventoryPrinter.FORMAT + "=TEXT",
+                InventoryPrinter.FORMAT + "=JSON",
+                InventoryPrinter.TITLE + "=Sling Metrics",
+                InventoryPrinter.NAME + "=slingmetrics"
+        }
+)
 public class MetricWebConsolePlugin extends HttpServlet implements
         InventoryPrinter, ServiceTrackerCustomizer<MetricRegistry, MetricRegistry>{
     /**
@@ -82,7 +79,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
     private BundleContext context;
     private ServiceTracker<MetricRegistry, MetricRegistry> tracker;
     private ConcurrentMap<ServiceReference, MetricRegistry> registries
-            = new ConcurrentHashMap<ServiceReference, MetricRegistry>();
+            = new ConcurrentHashMap<>();
 
     private TimeUnit rateUnit = TimeUnit.SECONDS;
     private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
@@ -94,7 +91,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
     private void activate(BundleContext context){
         this.context = context;
         this.timeUnit = new MetricTimeUnits(rateUnit, durationUnit, specificRateUnits, specificDurationUnits);
-        tracker = new ServiceTracker<MetricRegistry, MetricRegistry>(context, MetricRegistry.class, this);
+        tracker = new ServiceTracker<>(context, MetricRegistry.class, this);
         tracker.open();
     }
 
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
index 1bc6514..cec64bb 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricsServiceImpl.java
@@ -33,11 +33,6 @@ import javax.management.MBeanServer;
 
 import com.codahale.metrics.JmxReporter;
 import com.codahale.metrics.MetricRegistry;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.sling.commons.metrics.Meter;
 import org.apache.sling.commons.metrics.MetricsService;
 import org.apache.sling.commons.metrics.Timer;
@@ -47,8 +42,13 @@ import org.apache.sling.commons.metrics.Metric;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
 
-@Component
+@Component(service = {}, immediate = true)
 public class MetricsServiceImpl implements MetricsService {
     private final List<ServiceRegistration> regs = new ArrayList<>();
     private final ConcurrentMap<String, Metric> metrics = new ConcurrentHashMap<>();
@@ -56,7 +56,7 @@ public class MetricsServiceImpl implements MetricsService {
     private final BundleMetricsMapper metricsMapper = new BundleMetricsMapper(registry);
     private GaugeManager gaugeManager;
 
-    @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL)
     private MBeanServer server;
 
     private JmxReporter reporter;
diff --git a/src/main/java/org/apache/sling/commons/metrics/package-info.java b/src/main/java/org/apache/sling/commons/metrics/package-info.java
index 5b24541..3d6a101 100644
--- a/src/main/java/org/apache/sling/commons/metrics/package-info.java
+++ b/src/main/java/org/apache/sling/commons/metrics/package-info.java
@@ -23,9 +23,7 @@
  * @version 1.0
  */
 @Version("1.1.0")
-@Export(optional = "provide:=true")
 package org.apache.sling.commons.metrics;
 
-import aQute.bnd.annotation.Export;
-import aQute.bnd.annotation.Version;
 
+import org.osgi.annotation.versioning.Version;
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 38/44: [maven-release-plugin] prepare for next development iteration

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 9e801d6efaab3f2382ec629403080fc7444a2b34
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Fri Jun 2 20:57:20 2017 +0000

    [maven-release-plugin] prepare for next development iteration
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1797445 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4da9663..663e5fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
 
     <artifactId>org.apache.sling.commons.metrics</artifactId>
     <packaging>bundle</packaging>
-    <version>1.2.2</version>
+    <version>1.2.3-SNAPSHOT</version>
 
     <name>Apache Sling Metrics</name>
     <description>
@@ -42,9 +42,9 @@
     </properties>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.2.2</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/tags/org.apache.sling.commons.metrics-1.2.2</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/tags/org.apache.sling.commons.metrics-1.2.2</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/bundles/commons/metrics</url>
     </scm>
 
     <build>

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 20/44: SLING-5899 - "Guages" Typo in Sling metrics console

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 303e3689a420e852cc96e5556a9760c7b0f99166
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Mon Jul 25 14:12:02 2016 +0000

    SLING-5899 - "Guages" Typo in Sling metrics console
    
    Typo fix, thanks to Ana Vinatoru for spotting.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1754008 13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index c33eb18..d0321ef 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -399,7 +399,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
 
         pw.println("<br>");
         pw.println("<div class='table'>");
-        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Guages</div>");
+        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Gauges</div>");
         pw.println("<table class='nicetable' id='data-guages'>");
         pw.println("<thead>");
         pw.println("<tr>");

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 36/44: SLING-6702 - MetricsServiceFactory + tests. Test are a bit slow for now, starting a full Sling Launchpad should not be needed

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit fae352f80589d7fe5edc4858baba8d62d5636617
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Mar 23 15:50:05 2017 +0000

    SLING-6702 - MetricsServiceFactory + tests. Test are a bit slow for now, starting a full Sling Launchpad should not be needed
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1788272 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 85 ++++++++++++++++++-
 .../commons/metrics/MetricsServiceFactory.java     | 62 ++++++++++++++
 .../apache/sling/commons/metrics/package-info.java |  2 +-
 .../metrics/test/MetricsServiceFactoryIT.java      | 96 ++++++++++++++++++++++
 4 files changed, 243 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 2035102..fe07ab1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,6 +36,10 @@
         https://sling.apache.org/documentation/bundles/metrics.html
         for details
     </description>
+    
+    <properties>
+        <org.ops4j.pax.exam.version>4.10.0</org.ops4j.pax.exam.version>
+    </properties>
 
     <scm>
         <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/metrics</connection>
@@ -80,6 +84,38 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
+                    <systemProperties>
+                        <property>
+                            <name>bundle.filename</name>
+                            <value>${basedir}/target/${project.build.finalName}.jar</value>
+                        </property>
+                    </systemProperties>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.servicemix.tooling</groupId>
+                <artifactId>depends-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                          <goal>generate-depends-file</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 
@@ -160,5 +196,52 @@
             <version>2.12</version>
             <scope>test</scope>
         </dependency>
-    </dependencies>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam</artifactId>
+            <version>${org.ops4j.pax.exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-cm</artifactId>
+            <version>${org.ops4j.pax.exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-forked</artifactId>
+            <version>${org.ops4j.pax.exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-junit4</artifactId>
+            <version>${org.ops4j.pax.exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-link-mvn</artifactId>
+            <version>${org.ops4j.pax.exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>5.6.2</version>
+            <scope>test</scope>
+         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.paxexam</artifactId>
+            <version>0.0.4</version>
+            <scope>provided</scope>
+        </dependency>
+     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/commons/metrics/MetricsServiceFactory.java b/src/main/java/org/apache/sling/commons/metrics/MetricsServiceFactory.java
new file mode 100644
index 0000000..cd1c23f
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/metrics/MetricsServiceFactory.java
@@ -0,0 +1,62 @@
+/*
+ * 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.sling.commons.metrics;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+/** Utility that provides a MetricsService to any class that
+ *  has been loaded from an OSGi bundle.
+ *  This is meant to make it as easy to access the MetricsService
+ *  as it is to get a Logger, for example.
+ */
+public class MetricsServiceFactory {
+    
+    /** Provide a MetricsService mapped to the Bundle that loaded class c 
+     *  @param c a Class loaded by an OSGi bundle
+     *  @return a MetricsService
+     */
+    public static MetricsService getMetricsService(Class<?> c) {
+        if(c == null) {
+            throw new IllegalArgumentException("Class parameter is required");
+        }
+        
+        final Bundle b = FrameworkUtil.getBundle(c);
+        if(b == null) {
+            throw new IllegalArgumentException("No BundleContext, Class was not loaded from a Bundle?: " 
+                    + c.getClass().getName());
+        }
+        
+        final BundleContext ctx = b.getBundleContext();
+
+        // In theory we should unget this reference, but the OSGi framework
+        // ungets all references held by a bundle when it stops and we cannot
+        // do much better than that anyway.
+        final ServiceReference ref = ctx.getServiceReference(MetricsService.class.getName());
+        if(ref == null) {
+            throw new IllegalStateException("MetricsService not found for Bundle "
+                    + b.getSymbolicName());
+        }
+        
+        return (MetricsService)ctx.getService(ref);
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/commons/metrics/package-info.java b/src/main/java/org/apache/sling/commons/metrics/package-info.java
index 3d6a101..0fa4a33 100644
--- a/src/main/java/org/apache/sling/commons/metrics/package-info.java
+++ b/src/main/java/org/apache/sling/commons/metrics/package-info.java
@@ -22,7 +22,7 @@
  *
  * @version 1.0
  */
-@Version("1.1.0")
+@Version("1.2.0")
 package org.apache.sling.commons.metrics;
 
 
diff --git a/src/test/java/org/apache/sling/commons/metrics/test/MetricsServiceFactoryIT.java b/src/test/java/org/apache/sling/commons/metrics/test/MetricsServiceFactoryIT.java
new file mode 100644
index 0000000..1e7cd83
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/metrics/test/MetricsServiceFactoryIT.java
@@ -0,0 +1,96 @@
+/*
+ * 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.sling.commons.metrics.test;
+
+import javax.inject.Inject;
+import org.apache.sling.commons.metrics.MetricsService;
+import org.apache.sling.commons.metrics.MetricsServiceFactory;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingLaunchpadOakTar;
+import org.apache.sling.testing.paxexam.TestSupport;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.framework.BundleContext;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class MetricsServiceFactoryIT extends TestSupport {
+
+    @Inject
+    private BundleContext bundleContext;
+    
+    @Configuration
+    public Option[] configuration() {
+        return new Option[]{
+            baseConfiguration()
+        };
+    }
+
+    @Override
+    protected Option baseConfiguration() {
+        return composite(
+            super.baseConfiguration(),
+            launchpad(),
+            testBundle("bundle.filename"),
+            mavenBundle().groupId("io.dropwizard.metrics").artifactId("metrics-core").versionAsInProject(),
+            mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.testing.paxexam").versionAsInProject(),
+            mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.junit.core").version("1.0.23")
+        );
+    }
+    
+   protected Option launchpad() {
+        final int httpPort = findFreePort();
+        final String workingDirectory = workingDirectory();
+        return slingLaunchpadOakTar(workingDirectory, httpPort);
+    }
+   
+    @Test
+    public void nullClass() {
+        try {
+            MetricsServiceFactory.getMetricsService(null);
+            fail("Expecting an Exception");
+        } catch(IllegalArgumentException asExpected) {
+        }
+        
+    }
+    
+    @Test
+    public void classNotLoadedFromOsgiBundle() {
+        try {
+            MetricsServiceFactory.getMetricsService(String.class);
+            fail("Expecting an Exception");
+        } catch(IllegalArgumentException asExpected) {
+        }
+    }
+    
+    @Test
+    public void classFromBundle() {
+        final MetricsService m = MetricsServiceFactory.getMetricsService(getClass());
+        assertNotNull("Expecting a MetricsService", m);
+    }
+    
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 31/44: SLING-6596 - typo: guage -> gauge

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 31cc54d19db301533a6f878bb655bdd4385d2285
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Mar 3 08:45:17 2017 +0000

    SLING-6596 - typo: guage -> gauge
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1785238 13f79535-47bb-0310-9956-ffa450edef68
---
 .../org/apache/sling/commons/metrics/internal/JSONReporter.java   | 4 ++--
 .../sling/commons/metrics/internal/MetricWebConsolePlugin.java    | 4 ++--
 .../apache/sling/commons/metrics/internal/JSONReporterTest.java   | 8 ++++----
 .../commons/metrics/internal/MetricWebConsolePluginTest.java      | 4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
index 8e630d0..c7a439f 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java
@@ -13,7 +13,7 @@
  * 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
+ * specific langauge governing permissions and limitations
  * under the License.
  */
 
@@ -163,7 +163,7 @@ class JSONReporter implements Reporter, Closeable {
                         SortedMap<String, Timer> timers) throws IOException {
         json.object();
         if (!gauges.isEmpty()) {
-            json.key("guages").object();
+            json.key("gauges").object();
             for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
                 printGauge(entry);
             }
diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
index 0ebc173..70a7581 100644
--- a/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePlugin.java
@@ -13,7 +13,7 @@
  * 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
+ * specific langauge governing permissions and limitations
  * under the License.
  */
 
@@ -397,7 +397,7 @@ public class MetricWebConsolePlugin extends HttpServlet implements
         pw.println("<br>");
         pw.println("<div class='table'>");
         pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Gauges</div>");
-        pw.println("<table class='nicetable' id='data-guages'>");
+        pw.println("<table class='nicetable' id='data-gauges'>");
         pw.println("<thead>");
         pw.println("<tr>");
         pw.println("<th class='header'>Name</th>");
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
index 49a6b46..d05c175 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/JSONReporterTest.java
@@ -13,7 +13,7 @@
  * 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
+ * specific langauge governing permissions and limitations
  * under the License.
  */
 
@@ -49,7 +49,7 @@ public class JSONReporterTest {
         Map<String, Object> json = getJSON(registry);
 
         assertTrue(json.containsKey("meters"));
-        assertTrue(json.containsKey("guages"));
+        assertTrue(json.containsKey("gauges"));
         assertTrue(json.containsKey("timers"));
         assertTrue(json.containsKey("counters"));
         assertTrue(json.containsKey("histograms"));
@@ -75,7 +75,7 @@ public class JSONReporterTest {
 
 
         Map<String, Object> json = getJSON(registry);
-        assertTrue(((Map<String, Object>)json.get("guages")).containsKey("test"));
+        assertTrue(((Map<String, Object>)json.get("gauges")).containsKey("test"));
     }
 
     private static Map<String, Object> getJSON(MetricRegistry registry) throws IOException {
@@ -88,4 +88,4 @@ public class JSONReporterTest {
         return new JSONParser(sw.toString()).getParsed();
     }
 
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
index 296c9e6..56e44bc 100644
--- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
+++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java
@@ -13,7 +13,7 @@
  * 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
+ * specific langauge governing permissions and limitations
  * under the License.
  */
 
@@ -145,7 +145,7 @@ public class MetricWebConsolePluginTest {
         assertTable("data-counters", page);
         assertTable("data-timers", page);
         assertTable("data-histograms", page);
-        assertTable("data-guages", page);
+        assertTable("data-gauges", page);
     }
 
     private void assertTable(String name, HtmlPage page) {

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.

[sling-org-apache-sling-commons-metrics] 02/44: SLING-4080 - API to capture/measure application-level metrics

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git

commit 988cec0ca1229666463e312bb321ed0f184b89f8
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Jan 7 04:30:22 2016 +0000

    SLING-4080 - API to capture/measure application-level metrics
    
    Rename the bundle name to include 'commons' in the name
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1723457 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 5d13870..2d18405 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
     <version>26</version>
   </parent>
 
-  <artifactId>org.apache.sling.metrics</artifactId>
+  <artifactId>org.apache.sling.commons.metrics</artifactId>
   <packaging>bundle</packaging>
   <version>0.0.1-SNAPSHOT</version>
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.