Search in sources :

Example 1 with MutableStat

use of org.apache.hadoop.metrics2.lib.MutableStat in project hadoop by apache.

the class TestEntityGroupFSTimelineStore method testPluginRead.

@Test
public void testPluginRead() throws Exception {
    // Verify precondition
    assertEquals(EntityGroupPlugInForTest.class.getName(), store.getConfig().get(YarnConfiguration.TIMELINE_SERVICE_ENTITY_GROUP_PLUGIN_CLASSES));
    List<TimelineEntityGroupPlugin> currPlugins = store.getPlugins();
    for (TimelineEntityGroupPlugin plugin : currPlugins) {
        ClassLoader pluginClassLoader = plugin.getClass().getClassLoader();
        assertTrue("Should set up ApplicationClassLoader", pluginClassLoader instanceof ApplicationClassLoader);
        URL[] paths = ((URLClassLoader) pluginClassLoader).getURLs();
        boolean foundJAR = false;
        for (URL path : paths) {
            if (path.toString().contains(testJar.getAbsolutePath())) {
                foundJAR = true;
            }
        }
        assertTrue("Not found path " + testJar.getAbsolutePath() + " for plugin " + plugin.getClass().getName(), foundJAR);
    }
    // Load data and cache item, prepare timeline store by making a cache item
    EntityGroupFSTimelineStore.AppLogs appLogs = store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED);
    EntityCacheItem cacheItem = new EntityCacheItem(EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId), config);
    cacheItem.setAppLogs(appLogs);
    store.setCachedLogs(EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId), cacheItem);
    MutableCounterLong detailLogEntityRead = store.metrics.getGetEntityToDetailOps();
    MutableStat cacheRefresh = store.metrics.getCacheRefresh();
    long numEntityReadBefore = detailLogEntityRead.value();
    long cacheRefreshBefore = cacheRefresh.lastStat().numSamples();
    // Generate TDM
    TimelineDataManager tdm = PluginStoreTestUtils.getTdmWithStore(config, store);
    // Verify single entity read
    TimelineEntity entity3 = tdm.getEntity("type_3", mainTestAppId.toString(), EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser());
    assertNotNull(entity3);
    assertEquals(entityNew.getStartTime(), entity3.getStartTime());
    // Verify multiple entities read
    NameValuePair primaryFilter = new NameValuePair(EntityGroupPlugInForTest.APP_ID_FILTER_NAME, mainTestAppId.toString());
    TimelineEntities entities = tdm.getEntities("type_3", primaryFilter, null, null, null, null, null, null, EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser());
    assertEquals(1, entities.getEntities().size());
    for (TimelineEntity entity : entities.getEntities()) {
        assertEquals(entityNew.getStartTime(), entity.getStartTime());
    }
    // Verify metrics
    assertEquals(numEntityReadBefore + 2L, detailLogEntityRead.value());
    assertEquals(cacheRefreshBefore + 1L, cacheRefresh.lastStat().numSamples());
}
Also used : MutableCounterLong(org.apache.hadoop.metrics2.lib.MutableCounterLong) MutableStat(org.apache.hadoop.metrics2.lib.MutableStat) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) ApplicationClassLoader(org.apache.hadoop.util.ApplicationClassLoader) URL(java.net.URL) TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) URLClassLoader(java.net.URLClassLoader) ApplicationClassLoader(org.apache.hadoop.util.ApplicationClassLoader) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Example 2 with MutableStat

use of org.apache.hadoop.metrics2.lib.MutableStat in project hadoop by apache.

the class TestMutableMetrics method testSnapshot.

/**
   * Test the snapshot method
   */
@Test
public void testSnapshot() {
    MetricsRecordBuilder mb = mockMetricsRecordBuilder();
    MetricsRegistry registry = new MetricsRegistry("test");
    registry.newCounter("c1", "int counter", 1);
    registry.newCounter("c2", "long counter", 2L);
    registry.newGauge("g1", "int gauge", 3);
    registry.newGauge("g2", "long gauge", 4L);
    registry.newStat("s1", "stat", "Ops", "Time", true).add(0);
    registry.newRate("s2", "stat", false).add(0);
    registry.snapshot(mb, true);
    MutableStat s2 = (MutableStat) registry.get("s2");
    // should get the same back.
    s2.snapshot(mb, true);
    s2.add(1);
    // should get new interval values back
    s2.snapshot(mb, true);
    verify(mb).addCounter(info("c1", "int counter"), 1);
    verify(mb).addCounter(info("c2", "long counter"), 2L);
    verify(mb).addGauge(info("g1", "int gauge"), 3);
    verify(mb).addGauge(info("g2", "long gauge"), 4L);
    verify(mb).addCounter(info("S1NumOps", "Number of ops for stat"), 1L);
    verify(mb).addGauge(eq(info("S1AvgTime", "Average time for stat")), eq(0.0, EPSILON));
    verify(mb).addGauge(eq(info("S1StdevTime", "Standard deviation of time for stat")), eq(0.0, EPSILON));
    verify(mb).addGauge(eq(info("S1IMinTime", "Interval min time for stat")), eq(0.0, EPSILON));
    verify(mb).addGauge(eq(info("S1IMaxTime", "Interval max time for stat")), eq(0.0, EPSILON));
    verify(mb).addGauge(eq(info("S1MinTime", "Min time for stat")), eq(0.0, EPSILON));
    verify(mb).addGauge(eq(info("S1MaxTime", "Max time for stat")), eq(0.0, EPSILON));
    verify(mb).addGauge(eq(info("S1INumOps", "Interval number of ops for stat")), eq(1L));
    verify(mb, times(2)).addCounter(info("S2NumOps", "Number of ops for stat"), 1L);
    verify(mb, times(2)).addGauge(eq(info("S2AvgTime", "Average time for stat")), eq(0.0, EPSILON));
    verify(mb).addCounter(info("S2NumOps", "Number of ops for stat"), 2L);
    verify(mb).addGauge(eq(info("S2AvgTime", "Average time for stat")), eq(1.0, EPSILON));
    // Add one more sample to s1 and verify that total number of ops
    // has increased to 2, but interval number is 1 for both intervals.
    MutableStat s1 = (MutableStat) registry.get("s1");
    s1.add(0);
    registry.snapshot(mb, true);
    verify(mb).addCounter(info("S1NumOps", "Number of ops for stat"), 2L);
    verify(mb, times(2)).addGauge(eq(info("S1INumOps", "Interval number of ops for stat")), eq(1L));
}
Also used : MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 3 with MutableStat

use of org.apache.hadoop.metrics2.lib.MutableStat in project hadoop by apache.

the class TestMutableMetrics method testMutableStatWithBulkAdd.

/**
   * Tests that when using {@link MutableStat#add(long, long)}, even with a high
   * sample count, the mean does not lose accuracy.
   */
@Test
public void testMutableStatWithBulkAdd() {
    MetricsRecordBuilder rb = mockMetricsRecordBuilder();
    MetricsRegistry registry = new MetricsRegistry("test");
    MutableStat stat = registry.newStat("Test", "Test", "Ops", "Val", false);
    stat.add(1000, 1000);
    stat.add(1000, 2000);
    registry.snapshot(rb, false);
    assertCounter("TestNumOps", 2000L, rb);
    assertGauge("TestAvgVal", 1.5, rb);
}
Also used : MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)2 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 MutableCounterLong (org.apache.hadoop.metrics2.lib.MutableCounterLong)1 MutableStat (org.apache.hadoop.metrics2.lib.MutableStat)1 ApplicationClassLoader (org.apache.hadoop.util.ApplicationClassLoader)1 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)1 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)1