leventov closed pull request #6418: HttpPostEmitterMonitor: don't emit maxTime 
and minTime if no times were recorded
URL: https://github.com/apache/incubator-druid/pull/6418
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/java-util/src/main/java/org/apache/druid/java/util/emitter/core/ConcurrentTimeCounter.java
 
b/java-util/src/main/java/org/apache/druid/java/util/emitter/core/ConcurrentTimeCounter.java
index d4c5435236d..a71b2fc4ed6 100644
--- 
a/java-util/src/main/java/org/apache/druid/java/util/emitter/core/ConcurrentTimeCounter.java
+++ 
b/java-util/src/main/java/org/apache/druid/java/util/emitter/core/ConcurrentTimeCounter.java
@@ -21,6 +21,7 @@
 
 import com.google.common.primitives.UnsignedInts;
 
+import javax.annotation.Nullable;
 import java.util.concurrent.atomic.AtomicLong;
 
 /**
@@ -70,18 +71,34 @@ public long getTimeSumAndCountAndReset()
     return timeSumAndCount.getAndSet(0L);
   }
 
-  public int getAndResetMaxTime()
+  /**
+   * Returns the max time {@link #add}ed since the previous call to this 
method or since the creation of this object,
+   * or null if no times were added.
+   */
+  @Nullable
+  public Integer getAndResetMaxTime()
   {
     long max = this.max.getAndSet(-1);
-    // If max < 0, means no times added yet, then return 0
-    return max >= 0 ? (int) max : 0;
+    if (max >= 0) {
+      return (int) max;
+    } else {
+      return null;
+    }
   }
 
-  public int getAndResetMinTime()
+  /**
+   * Returns the min time {@link #add}ed since the previous call to this 
method or since the creation of this object,
+   * or null if no times were added.
+   */
+  @Nullable
+  public Integer getAndResetMinTime()
   {
     long min = this.min.getAndSet(-1);
-    // If min < 0, means no times added yet, then return 0
-    return min >= 0 ? (int) min : 0;
+    if (min >= 0) {
+      return (int) min;
+    } else {
+      return null;
+    }
   }
 
   public static int timeSum(long timeSumAndCount)
diff --git 
a/java-util/src/main/java/org/apache/druid/java/util/metrics/HttpPostEmitterMonitor.java
 
b/java-util/src/main/java/org/apache/druid/java/util/metrics/HttpPostEmitterMonitor.java
index de40f0ec652..a8fd802194d 100644
--- 
a/java-util/src/main/java/org/apache/druid/java/util/metrics/HttpPostEmitterMonitor.java
+++ 
b/java-util/src/main/java/org/apache/druid/java/util/metrics/HttpPostEmitterMonitor.java
@@ -75,10 +75,20 @@ public boolean doMonitor(ServiceEmitter emitter)
   private void emitTimeCounterMetrics(ServiceEmitter emitter, 
ConcurrentTimeCounter timeCounter, String metricNameBase)
   {
     long timeSumAndCount = timeCounter.getTimeSumAndCountAndReset();
-    emitter.emit(builder.build(metricNameBase + "timeMsSum", 
ConcurrentTimeCounter.timeSum(timeSumAndCount)));
-    emitter.emit(builder.build(metricNameBase + "count", 
ConcurrentTimeCounter.count(timeSumAndCount)));
-    emitter.emit(builder.build(metricNameBase + "maxTimeMs", 
timeCounter.getAndResetMaxTime()));
-    emitter.emit(builder.build(metricNameBase + "minTimeMs", 
timeCounter.getAndResetMinTime()));
+    int timeSum = ConcurrentTimeCounter.timeSum(timeSumAndCount);
+    int count = ConcurrentTimeCounter.count(timeSumAndCount);
+    if (count != 0) {
+      emitter.emit(builder.build(metricNameBase + "timeMsSum", timeSum));
+      emitter.emit(builder.build(metricNameBase + "count", count));
+    }
+    Integer maxTime = timeCounter.getAndResetMaxTime();
+    if (maxTime != null) {
+      emitter.emit(builder.build(metricNameBase + "maxTimeMs", maxTime));
+    }
+    Integer minTime = timeCounter.getAndResetMinTime();
+    if (minTime != null) {
+      emitter.emit(builder.build(metricNameBase + "minTimeMs", minTime));
+    }
   }
 
   @Override


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to