HBASE-20571 JMXJsonServlet generates invalid JSON if it has NaN in metrics

- CacheStats won't generate NaN metrics.
- JSONBean class will serialize special floating point values as
  "NaN", "Infinity" or "-Infinity"

Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
Balazs Meszaros 2018-05-11 16:30:38 +02:00 committed by Andrew Purtell
parent 61f2b5f071
commit 39ea1efa88
2 changed files with 40 additions and 6 deletions

View File

@ -310,7 +310,11 @@ public class JSONBean {
jg.writeEndArray();
} else if(value instanceof Number) {
Number n = (Number)value;
jg.writeNumber(n.toString());
if (Double.isFinite(n.doubleValue())) {
jg.writeNumber(n.toString());
} else {
jg.writeString(n.toString());
}
} else if(value instanceof Boolean) {
Boolean b = (Boolean)value;
jg.writeBoolean(b);

View File

@ -388,23 +388,53 @@ public class CacheStats {
}
public double getHitRatio() {
return ((double) getHitCount() / (double) getRequestCount());
double requestCount = getRequestCount();
if (requestCount == 0) {
return 0;
}
return getHitCount() / requestCount;
}
public double getHitCachingRatio() {
return ((double) getHitCachingCount() / (double) getRequestCachingCount());
double requestCachingCount = getRequestCachingCount();
if (requestCachingCount == 0) {
return 0;
}
return getHitCachingCount() / requestCachingCount;
}
public double getMissRatio() {
return ((double) getMissCount() / (double) getRequestCount());
double requestCount = getRequestCount();
if (requestCount == 0) {
return 0;
}
return getMissCount() / requestCount;
}
public double getMissCachingRatio() {
return ((double) getMissCachingCount() / (double) getRequestCachingCount());
double requestCachingCount = getRequestCachingCount();
if (requestCachingCount == 0) {
return 0;
}
return getMissCachingCount() / requestCachingCount;
}
public double evictedPerEviction() {
return ((double) getEvictedCount() / (double) getEvictionCount());
double evictionCount = getEvictionCount();
if (evictionCount == 0) {
return 0;
}
return getEvictedCount() / evictionCount;
}
public long getFailedInserts() {