Repository: incubator-eagle
Updated Branches:
  refs/heads/master cfd4d38fd -> 02abe02c3


[EAGLE-832] Support to define granularity for MetricDefinition to avoid metric 
duplicate

Support to define granularity for MetricDefinition to avoid metric duplicate

Author: Hao Chen <h...@apache.org>

Closes #724 from haoch/SupportGranularity.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/02abe02c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/02abe02c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/02abe02c

Branch: refs/heads/master
Commit: 02abe02c37cd4351ea456ccf42fe24fb9544682d
Parents: cfd4d38
Author: Hao Chen <h...@apache.org>
Authored: Thu Dec 8 22:44:29 2016 +0800
Committer: Hao Chen <h...@apache.org>
Committed: Thu Dec 8 22:44:29 2016 +0800

----------------------------------------------------------------------
 .../environment/builder/MetricDefinition.java   | 21 ++++++++++++++++++++
 .../app/messaging/MetricStreamPersist.java      |  3 ++-
 .../eagle/metric/HadoopMetricMonitorApp.java    |  3 +++
 3 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/02abe02c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MetricDefinition.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MetricDefinition.java
 
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MetricDefinition.java
index 62a81b0..d45ad2b 100644
--- 
a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MetricDefinition.java
+++ 
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MetricDefinition.java
@@ -19,6 +19,7 @@ package org.apache.eagle.app.environment.builder;
 
 import java.io.Serializable;
 import java.util.Arrays;
+import java.util.Calendar;
 import java.util.List;
 import java.util.Map;
 
@@ -40,6 +41,11 @@ public class MetricDefinition implements Serializable {
     private List<String> dimensionFields;
 
     /**
+     * Metric granularity.
+     */
+    private int granularity = Calendar.MINUTE;
+
+    /**
      * Metric value field name.
      */
     private String valueField = "value";
@@ -76,6 +82,13 @@ public class MetricDefinition implements Serializable {
         this.timestampSelector = timestampSelector;
     }
 
+    public int getGranularity() {
+        return granularity;
+    }
+
+    public void setGranularity(int granularity) {
+        this.granularity = granularity;
+    }
 
     @FunctionalInterface
     public interface NameSelector extends Serializable {
@@ -93,6 +106,14 @@ public class MetricDefinition implements Serializable {
         return metricDefinition;
     }
 
+    /**
+     * @see java.util.Calendar
+     */
+    public MetricDefinition granularity(int granularity) {
+        this.setGranularity(granularity);
+        return this;
+    }
+
     public static MetricDefinition namedByField(String nameField) {
         MetricDefinition metricDefinition = new MetricDefinition();
         metricDefinition.setNameSelector(new FieldNameSelector(nameField));

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/02abe02c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/MetricStreamPersist.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/MetricStreamPersist.java
 
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/MetricStreamPersist.java
index 32b168b..2a1d8a8 100644
--- 
a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/MetricStreamPersist.java
+++ 
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/MetricStreamPersist.java
@@ -26,6 +26,7 @@ import com.google.common.base.Preconditions;
 import com.typesafe.config.Config;
 import org.apache.eagle.app.environment.builder.MetricDefinition;
 import org.apache.eagle.app.utils.StreamConvertHelper;
+import org.apache.eagle.common.DateTimeUtil;
 import org.apache.eagle.log.entity.GenericMetricEntity;
 import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
 import org.apache.eagle.service.client.IEagleServiceClient;
@@ -143,7 +144,7 @@ public class MetricStreamPersist extends BaseRichBolt  {
 
             GenericMetricEntity entity = new GenericMetricEntity();
             entity.setPrefix(metricName);
-            entity.setTimestamp(timestamp);
+            
entity.setTimestamp(DateTimeUtil.roundDown(metricDefinition.getGranularity(), 
timestamp));
             entity.setTags(tags);
             entity.setValue(values);
             return entity;

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/02abe02c/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorApp.java
----------------------------------------------------------------------
diff --git 
a/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorApp.java
 
b/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorApp.java
index 7f5e21b..323e5fe 100644
--- 
a/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorApp.java
+++ 
b/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorApp.java
@@ -23,6 +23,8 @@ import org.apache.eagle.app.environment.builder.CEPFunction;
 import org.apache.eagle.app.environment.impl.StormEnvironment;
 import org.apache.eagle.app.environment.builder.MetricDefinition;
 
+import java.util.Calendar;
+
 public class HadoopMetricMonitorApp extends StormApplication {
     @Override
     public StormTopology execute(Config config, StormEnvironment environment) {
@@ -32,6 +34,7 @@ public class HadoopMetricMonitorApp extends StormApplication {
                 .namedByField("metric")
                 .eventTimeByField("timestamp")
                 .dimensionFields("host","component","site")
+                .granularity(Calendar.MINUTE)
                 .valueField("value"))
             .toTopology();
     }

Reply via email to