Skip to content

Commit 68bd711

Browse files
author
Ravindra Dingankar
committed
allow decimals in percentile in description
1 parent 3b06c5b commit 68bd711

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableInverseQuantiles.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.hadoop.metrics2.util.Quantile;
2525
import org.apache.hadoop.metrics2.util.SampleQuantiles;
2626
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
27+
import java.text.DecimalFormat;
2728
import java.util.concurrent.Executors;
2829
import java.util.concurrent.ScheduledExecutorService;
2930
import java.util.concurrent.ScheduledFuture;
@@ -83,13 +84,14 @@ public MutableInverseQuantiles(String name, String description, String sampleNam
8384
"Number of %s for %s with %ds interval", lsName, desc, intervalSecs)));
8485
// Construct the MetricsInfos for the inverse quantiles, converting to inverse percentiles
8586
setQuantileInfos(INVERSE_QUANTILES.length);
86-
String nameTemplate = ucName + "%dthInversePercentile" + uvName;
87-
String descTemplate = "%d inverse percentile " + lvName + " with " + intervalSecs
87+
DecimalFormat df = new DecimalFormat("###.####");
88+
String nameTemplate = "thInversePercentile" + uvName;
89+
String descTemplate = " inverse percentile " + lvName + " with " + intervalSecs
8890
+ " second interval for " + desc;
8991
for (int i = 0; i < INVERSE_QUANTILES.length; i++) {
9092
double inversePercentile = 100 * (1 - INVERSE_QUANTILES[i].quantile);
91-
addQuantileInfo(i, info(String.format(nameTemplate, inversePercentile),
92-
String.format(descTemplate, inversePercentile)));
93+
addQuantileInfo(i, info(ucName + df.format(inversePercentile) + nameTemplate,
94+
df.format(inversePercentile) + descTemplate));
9395
}
9496

9597
setEstimator(new SampleQuantiles(INVERSE_QUANTILES));

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableQuantiles.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import static org.apache.hadoop.metrics2.lib.Interns.info;
2222

23+
import java.text.DecimalFormat;
2324
import java.util.Map;
2425
import java.util.concurrent.Executors;
2526
import java.util.concurrent.ScheduledExecutorService;
@@ -90,18 +91,19 @@ public MutableQuantiles(String name, String description, String sampleName,
9091
String desc = StringUtils.uncapitalize(description);
9192
String lsName = StringUtils.uncapitalize(sampleName);
9293
String lvName = StringUtils.uncapitalize(valueName);
94+
DecimalFormat df = new DecimalFormat("###.####");
9395

9496
setNumInfo(info(ucName + "Num" + usName, String.format(
9597
"Number of %s for %s with %ds interval", lsName, desc, interval)));
9698
// Construct the MetricsInfos for the quantiles, converting to percentiles
9799
setQuantileInfos(quantiles.length);
98-
String nameTemplate = ucName + "%dthPercentile" + uvName;
99-
String descTemplate = "%d percentile " + lvName + " with " + interval
100+
String nameTemplate = "thPercentile" + uvName;
101+
String descTemplate = " percentile " + lvName + " with " + interval
100102
+ " second interval for " + desc;
101103
for (int i = 0; i < quantiles.length; i++) {
102104
double percentile = 100 * quantiles[i].quantile;
103-
addQuantileInfo(i, info(String.format(nameTemplate, percentile),
104-
String.format(descTemplate, percentile)));
105+
addQuantileInfo(i, info(ucName + df.format(percentile) + nameTemplate,
106+
df.format(percentile) + descTemplate));
105107
}
106108

107109
setEstimator(new SampleQuantiles(quantiles));
@@ -166,7 +168,7 @@ public synchronized void addQuantileInfo(int i, MetricsInfo info) {
166168
/**
167169
* Set the rollover interval (in seconds) of the estimator.
168170
*
169-
* @param pIntervalSecs (in seconds) of the estimator.
171+
* @param pIntervalSecs of the estimator.
170172
*/
171173
public synchronized void setInterval(int pIntervalSecs) {
172174
this.intervalSecs = pIntervalSecs;
@@ -175,7 +177,7 @@ public synchronized void setInterval(int pIntervalSecs) {
175177
/**
176178
* Get the rollover interval (in seconds) of the estimator.
177179
*
178-
* @return intervalSecs (in seconds) of the estimator.
180+
* @return intervalSecs of the estimator.
179181
*/
180182
public synchronized int getInterval() {
181183
return intervalSecs;

0 commit comments

Comments
 (0)