You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by bo...@apache.org on 2017/09/07 19:14:57 UTC

[16/18] storm git commit: Added in precision for csv, and tsv too

Added in precision for csv, and tsv too


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/113413cd
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/113413cd
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/113413cd

Branch: refs/heads/master
Commit: 113413cddefce23f920ec12733321284d31ce9d7
Parents: 19508b9
Author: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Authored: Fri Sep 1 10:44:34 2017 -0500
Committer: Robert (Bobby) Evans <ev...@yahoo-inc.com>
Committed: Fri Sep 1 10:44:34 2017 -0500

----------------------------------------------------------------------
 examples/storm-loadgen/README.md                |  2 +-
 .../apache/storm/loadgen/LoadMetricsServer.java | 33 ++++++++++++++++----
 2 files changed, 28 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/113413cd/examples/storm-loadgen/README.md
----------------------------------------------------------------------
diff --git a/examples/storm-loadgen/README.md b/examples/storm-loadgen/README.md
index 1858ea4..b24b8ed 100644
--- a/examples/storm-loadgen/README.md
+++ b/examples/storm-loadgen/README.md
@@ -89,8 +89,8 @@ Not all options are supported by all reporters.
 |columns | A comma separated list of columns to output (see below for the metrics supported).  A `*` is replaced by all metrics. Defaults to "start_time", "end_time", "rate", "mean", "99%ile", "99.9%ile", "cores", "mem", "failed", "ids", "congested" | csv, tsv, fixed |
 |extraColumns | Like columns but ones that should be added to the defaults instead of replacing them. A `*` is replaced by all metrics. | csv, tsv, fixed |
 |meta | An arbitrary string that will appear as a "meta" column at the end.  This helps when appending to files to keep different runs separated | csv, tsv, fixed|
+|precision | The number of places after the decimal point to print out.  The default for fixed is 3, all others it is unlimited. | csv, tsv, fixed|
 |columnWidth | The width of each field | fixed|
-|precision | The number of places after the decimal point to print out | fixed|
 
 There are a lot of different metrics supported
 

http://git-wip-us.apache.org/repos/asf/storm/blob/113413cd/examples/storm-loadgen/src/main/java/org/apache/storm/loadgen/LoadMetricsServer.java
----------------------------------------------------------------------
diff --git a/examples/storm-loadgen/src/main/java/org/apache/storm/loadgen/LoadMetricsServer.java b/examples/storm-loadgen/src/main/java/org/apache/storm/loadgen/LoadMetricsServer.java
index a44ab45..546b3ca 100644
--- a/examples/storm-loadgen/src/main/java/org/apache/storm/loadgen/LoadMetricsServer.java
+++ b/examples/storm-loadgen/src/main/java/org/apache/storm/loadgen/LoadMetricsServer.java
@@ -476,9 +476,16 @@ public class LoadMetricsServer extends HttpForwardingMetricsServer {
         protected final TimeUnit targetUnit;
         protected final List<String> extractors;
         protected final String meta;
+        protected final int precision;
+        protected String doubleFormat;
 
         public ColumnsFileReporter(String path, Map<String, String> query, Map<String, MetricExtractor> extractorsMap)
             throws FileNotFoundException {
+            this(path, query, extractorsMap, null);
+        }
+
+        public ColumnsFileReporter(String path, Map<String, String> query, Map<String, MetricExtractor> extractorsMap,
+                                   String defaultPreceision) throws FileNotFoundException {
             super(path, query, extractorsMap);
             targetUnit = UNIT_MAP.get(query.getOrDefault("time", "MILLISECONDS").toUpperCase());
             if (targetUnit == null) {
@@ -511,7 +518,14 @@ public class LoadMetricsServer extends HttpForwardingMetricsServer {
                     }
                 }
             }
-
+            String strPrecision = query.getOrDefault("precision", defaultPreceision);
+            if (strPrecision == null) {
+                precision = -1;
+                doubleFormat = "%f";
+            } else {
+                precision = Integer.parseInt(strPrecision);
+                doubleFormat = "%." + precision + "f";
+            }
             meta = query.get("meta");
         }
 
@@ -536,19 +550,25 @@ public class LoadMetricsServer extends HttpForwardingMetricsServer {
             }
             return ret;
         }
+
+        protected String format(Object o) {
+            if (o instanceof Double || o instanceof Float) {
+                return String.format(doubleFormat, o);
+            } else {
+                return o == null ? "" : o.toString();
+            }
+        }
     }
 
 
     static class FixedWidthReporter extends  ColumnsFileReporter {
-        public final String doubleFormat;
         public final String longFormat;
         public final String stringFormat;
 
         public FixedWidthReporter(String path, Map<String, String> query, Map<String, MetricExtractor> extractorsMap)
             throws FileNotFoundException {
-            super(path, query, extractorsMap);
+            super(path, query, extractorsMap, "3");
             int columnWidth = Integer.parseInt(query.getOrDefault("columnWidth", "15")) - 1;//Always have a space in between
-            int precision = Integer.parseInt(query.getOrDefault("precision", "3"));
             doubleFormat = "%," + columnWidth + "." + precision + "f";
             longFormat = "%," + columnWidth + "d";
             stringFormat = "%" + columnWidth + "s";
@@ -558,7 +578,8 @@ public class LoadMetricsServer extends HttpForwardingMetricsServer {
             this(null, Collections.emptyMap(), allExtractors);
         }
 
-        private String format(Object o) {
+        @Override
+        protected String format(Object o) {
             if (o instanceof Double || o instanceof Float) {
                 return String.format(doubleFormat, o);
             } else if (o instanceof Integer || o instanceof Long) {
@@ -638,7 +659,7 @@ public class LoadMetricsServer extends HttpForwardingMetricsServer {
                 }
                 first = false;
                 Object value = allExtractors.get(name).get(m, targetUnit);
-                String svalue = value == null ? "" : value.toString();
+                String svalue = format(value);
                 out.print(escape(svalue));
             }
             if (meta != null) {