HttpPostEmitterMonitor: don't emit maxTime and minTime if no times were recorded (#6418)

* HttpPostEmitterMonitor: don't emit maxTime and minTime if no times were recorded

* Don't emit sum and count if none

* Remove outdated comments
This commit is contained in:
Roman Leventov 2018-10-08 17:11:42 -03:00 committed by GitHub
parent 2b76d57347
commit af9efdbedf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 10 deletions

View File

@ -21,6 +21,7 @@ package org.apache.druid.java.util.emitter.core;
import com.google.common.primitives.UnsignedInts;
import javax.annotation.Nullable;
import java.util.concurrent.atomic.AtomicLong;
/**
@ -70,18 +71,34 @@ public class ConcurrentTimeCounter
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)

View File

@ -75,10 +75,20 @@ public class HttpPostEmitterMonitor extends FeedDefiningMonitor
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