HBASE-11301 [optionally] update jmx cache to drop old metrics (Maysam Yabandeh via stack)
This commit is contained in:
parent
31b4d2daa1
commit
fb41615887
|
@ -404,6 +404,9 @@ Release 2.7.0 - UNRELEASED
|
||||||
|
|
||||||
HADOOP-11341. KMS support for whitelist key ACLs. (Arun Suresh via wang)
|
HADOOP-11341. KMS support for whitelist key ACLs. (Arun Suresh via wang)
|
||||||
|
|
||||||
|
HADOOP-11301. [optionally] update jmx cache to drop old metrics
|
||||||
|
(Maysam Yabandeh via stack)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-11323. WritableComparator#compare keeps reference to byte array.
|
HADOOP-11323. WritableComparator#compare keeps reference to byte array.
|
||||||
|
|
|
@ -173,9 +173,8 @@ class MetricsSourceAdapter implements DynamicMBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
int oldCacheSize = attrCache.size();
|
updateAttrCache();
|
||||||
int newCacheSize = updateAttrCache();
|
if (getAllMetrics) {
|
||||||
if (oldCacheSize < newCacheSize) {
|
|
||||||
updateInfoCache();
|
updateInfoCache();
|
||||||
}
|
}
|
||||||
jmxCacheTS = Time.now();
|
jmxCacheTS = Time.now();
|
||||||
|
|
|
@ -23,6 +23,8 @@ import static org.junit.Assert.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.hadoop.metrics2.MetricsCollector;
|
||||||
|
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
|
||||||
import org.apache.hadoop.metrics2.MetricsSource;
|
import org.apache.hadoop.metrics2.MetricsSource;
|
||||||
import org.apache.hadoop.metrics2.MetricsTag;
|
import org.apache.hadoop.metrics2.MetricsTag;
|
||||||
import org.apache.hadoop.metrics2.annotation.Metric;
|
import org.apache.hadoop.metrics2.annotation.Metric;
|
||||||
|
@ -31,10 +33,59 @@ import org.apache.hadoop.metrics2.lib.MetricsAnnotations;
|
||||||
import org.apache.hadoop.metrics2.lib.MetricsRegistry;
|
import org.apache.hadoop.metrics2.lib.MetricsRegistry;
|
||||||
import org.apache.hadoop.metrics2.lib.MetricsSourceBuilder;
|
import org.apache.hadoop.metrics2.lib.MetricsSourceBuilder;
|
||||||
import org.apache.hadoop.metrics2.lib.MutableCounterLong;
|
import org.apache.hadoop.metrics2.lib.MutableCounterLong;
|
||||||
|
import static org.apache.hadoop.metrics2.lib.Interns.info;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.management.MBeanAttributeInfo;
|
||||||
|
import javax.management.MBeanInfo;
|
||||||
|
|
||||||
public class TestMetricsSourceAdapter {
|
public class TestMetricsSourceAdapter {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPurgeOldMetrics() throws Exception {
|
||||||
|
// create test source with a single metric counter of value 1
|
||||||
|
PurgableSource source = new PurgableSource();
|
||||||
|
MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source);
|
||||||
|
final MetricsSource s = sb.build();
|
||||||
|
|
||||||
|
List<MetricsTag> injectedTags = new ArrayList<MetricsTag>();
|
||||||
|
MetricsSourceAdapter sa = new MetricsSourceAdapter(
|
||||||
|
"tst", "tst", "testdesc", s, injectedTags, null, null, 1, false);
|
||||||
|
|
||||||
|
MBeanInfo info = sa.getMBeanInfo();
|
||||||
|
boolean sawIt = false;
|
||||||
|
for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) {
|
||||||
|
sawIt |= mBeanAttributeInfo.getName().equals(source.lastKeyName);
|
||||||
|
};
|
||||||
|
assertTrue("The last generated metric is not exported to jmx", sawIt);
|
||||||
|
|
||||||
|
Thread.sleep(1000); // skip JMX cache TTL
|
||||||
|
|
||||||
|
info = sa.getMBeanInfo();
|
||||||
|
sawIt = false;
|
||||||
|
for (MBeanAttributeInfo mBeanAttributeInfo : info.getAttributes()) {
|
||||||
|
sawIt |= mBeanAttributeInfo.getName().equals(source.lastKeyName);
|
||||||
|
};
|
||||||
|
assertTrue("The last generated metric is not exported to jmx", sawIt);
|
||||||
|
}
|
||||||
|
|
||||||
|
//generate a new key per each call
|
||||||
|
class PurgableSource implements MetricsSource {
|
||||||
|
int nextKey = 0;
|
||||||
|
String lastKeyName = null;
|
||||||
|
@Override
|
||||||
|
public void getMetrics(MetricsCollector collector, boolean all) {
|
||||||
|
MetricsRecordBuilder rb =
|
||||||
|
collector.addRecord("purgablesource")
|
||||||
|
.setContext("test");
|
||||||
|
lastKeyName = "key" + nextKey++;
|
||||||
|
rb.addGauge(info(lastKeyName, "desc"), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetMetricsAndJmx() throws Exception {
|
public void testGetMetricsAndJmx() throws Exception {
|
||||||
// create test source with a single metric counter of value 0
|
// create test source with a single metric counter of value 0
|
||||||
|
|
Loading…
Reference in New Issue