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

eolivelli pushed a commit to branch maven-metrics
in repository https://gitbox.apache.org/repos/asf/maven-studies.git


The following commit(s) were added to refs/heads/maven-metrics by this push:
     new 8762bbc  Add metrics description
8762bbc is described below

commit 8762bbcc4064df2bae0822a6d1c470e65604d3b4
Author: Enrico Olivelli <eolive...@apache.org>
AuthorDate: Mon Apr 13 15:26:36 2020 +0200

    Add metrics description
---
 .../maven/lifecycle/internal/LifecycleStarter.java |  4 +-
 .../main/java/org/apache/maven/metrics/Metric.java | 47 ++++++++++++++++++++++
 .../org/apache/maven/metrics/MetricsContext.java   |  8 ++--
 .../maven/metrics/impl/NullMetricsProvider.java    |  8 ++--
 4 files changed, 58 insertions(+), 9 deletions(-)

diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleStarter.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleStarter.java
index e2a53ad..711639c 100644
--- 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleStarter.java
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleStarter.java
@@ -135,7 +135,9 @@ public class LifecycleStarter
             }
             long startBuild = System.currentTimeMillis();
             builder.build( session, reactorContext, projectBuilds, 
taskSegments, reactorBuildStatus );
-            metricsSystem.getMetricsContext().getSummary( "buildTime" ).add( 
System.currentTimeMillis() - startBuild );
+            metricsSystem.getMetricsContext()
+                    .getSummary( "buildTime", "Effective build time (in ms)" )
+                    .add( System.currentTimeMillis() - startBuild );
         }
         catch ( Exception e )
         {
diff --git a/maven-metrics/src/main/java/org/apache/maven/metrics/Metric.java 
b/maven-metrics/src/main/java/org/apache/maven/metrics/Metric.java
new file mode 100644
index 0000000..f77c850
--- /dev/null
+++ b/maven-metrics/src/main/java/org/apache/maven/metrics/Metric.java
@@ -0,0 +1,47 @@
+package org.apache.maven.metrics;
+
+/*
+ * 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.
+ */
+
+/**
+ * Interface common to every metrics.
+ * It allows the user to define common metadata about the metric.
+ */
+public interface Metric
+{
+    /**
+     * Define a textual label for the metric
+     * @param label the label (plain text)
+     * @return the metric handle itself
+     */
+    default <T extends Metric> T setLabel( String label )
+    {
+        return (T) this;
+    }
+
+    /**
+     * Define a textual help for the metric
+     * @param help the help (plain text)
+     * @return the metric handle itself
+     */
+    default <T extends Metric> T setHelp( String help )
+    {
+        return (T) this;
+    }
+}
diff --git 
a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsContext.java 
b/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsContext.java
index a42b5bb..cb85793 100644
--- a/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsContext.java
+++ b/maven-metrics/src/main/java/org/apache/maven/metrics/MetricsContext.java
@@ -50,7 +50,7 @@ public interface MetricsContext
      * @param name
      * @return the counter identified by name in this context.
      */
-    Counter getCounter( String name );
+    Counter getCounter( String name, String description );
 
     /**
      * Registers an user provided {@link Gauge} which will be called by the
@@ -63,7 +63,7 @@ public interface MetricsContext
      * @param gauge the implementation of the Gauge
      *
      */
-    void registerGauge( String name, Gauge gauge );
+    void registerGauge( String name, String description, Gauge gauge );
 
     /**
      * Unregisters the user provided {@link Gauge} bound to the given name.
@@ -79,7 +79,7 @@ public interface MetricsContext
      * @param name
      * @return the summary identified by name in this context.
      */
-    Summary getSummary( String name );
+    Summary getSummary( String name, String description );
 
     /**
      * Returns a set of summaries.
@@ -87,6 +87,6 @@ public interface MetricsContext
      * @param name
      * @return the summary identified by name in this context.
      */
-    SummarySet getSummarySet( String name );
+    SummarySet getSummarySet( String name, String description );
 
 }
diff --git 
a/maven-metrics/src/main/java/org/apache/maven/metrics/impl/NullMetricsProvider.java
 
b/maven-metrics/src/main/java/org/apache/maven/metrics/impl/NullMetricsProvider.java
index 12aeb87..a94c3b2 100644
--- 
a/maven-metrics/src/main/java/org/apache/maven/metrics/impl/NullMetricsProvider.java
+++ 
b/maven-metrics/src/main/java/org/apache/maven/metrics/impl/NullMetricsProvider.java
@@ -58,13 +58,13 @@ public class NullMetricsProvider implements MetricsProvider
         }
 
         @Override
-        public Counter getCounter( String name )
+        public Counter getCounter( String name, String description )
         {
             return NullCounter.INSTANCE;
         }
 
         @Override
-        public void registerGauge( String name, Gauge gauge )
+        public void registerGauge( String name, String description, Gauge 
gauge )
         {
         }
 
@@ -74,13 +74,13 @@ public class NullMetricsProvider implements MetricsProvider
         }
 
         @Override
-        public Summary getSummary( String name )
+        public Summary getSummary( String name, String description )
         {
             return NullSummary.INSTANCE;
         }
 
         @Override
-        public SummarySet getSummarySet( String name )
+        public SummarySet getSummarySet( String name, String description )
         {
             return NullSummarySet.INSTANCE;
         }

Reply via email to