Search in sources :

Example 91 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hadoop by apache.

the class TestMetricsSystemImpl method testQSize.

@Test
public void testQSize() throws Exception {
    new ConfigBuilder().add("*.period", 8).add("*.queue.capacity", 2).add("test.sink.test.class", TestSink.class.getName()).save(TestMetricsConfig.getTestFilename("hadoop-metrics2-test"));
    MetricsSystemImpl ms = new MetricsSystemImpl("Test");
    final CountDownLatch proceedSignal = new CountDownLatch(1);
    final CountDownLatch reachedPutMetricSignal = new CountDownLatch(1);
    ms.start();
    try {
        MetricsSink slowSink = mock(MetricsSink.class);
        MetricsSink dataSink = mock(MetricsSink.class);
        ms.registerSink("slowSink", "The sink that will wait on putMetric", slowSink);
        ms.registerSink("dataSink", "The sink I'll use to get info about slowSink", dataSink);
        doAnswer(new Answer() {

            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                reachedPutMetricSignal.countDown();
                proceedSignal.await();
                return null;
            }
        }).when(slowSink).putMetrics(any(MetricsRecord.class));
        // trigger metric collection first time
        ms.onTimerEvent();
        assertTrue(reachedPutMetricSignal.await(1, TimeUnit.SECONDS));
        // Now that the slow sink is still processing the first metric,
        // its queue length should be 1 for the second collection.
        ms.onTimerEvent();
        verify(dataSink, timeout(500).times(2)).putMetrics(r1.capture());
        List<MetricsRecord> mr = r1.getAllValues();
        Number qSize = Iterables.find(mr.get(1).metrics(), new Predicate<AbstractMetric>() {

            @Override
            public boolean apply(@Nullable AbstractMetric input) {
                assert input != null;
                return input.name().equals("Sink_slowSinkQsize");
            }
        }).value();
        assertEquals(1, qSize);
    } finally {
        proceedSignal.countDown();
        ms.stop();
    }
}
Also used : MetricsRecord(org.apache.hadoop.metrics2.MetricsRecord) AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) Predicate(com.google.common.base.Predicate) Answer(org.mockito.stubbing.Answer) MetricsSink(org.apache.hadoop.metrics2.MetricsSink) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Example 92 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hadoop by apache.

the class TestMetricsVisitor method testCommon.

/**
   * Test the common use cases
   */
@Test
public void testCommon() {
    MetricsVisitor visitor = mock(MetricsVisitor.class);
    MetricsRegistry registry = new MetricsRegistry("test");
    List<AbstractMetric> metrics = MetricsLists.builder("test").addCounter(info("c1", "int counter"), 1).addCounter(info("c2", "long counter"), 2L).addGauge(info("g1", "int gauge"), 5).addGauge(info("g2", "long gauge"), 6L).addGauge(info("g3", "float gauge"), 7f).addGauge(info("g4", "double gauge"), 8d).metrics();
    for (AbstractMetric metric : metrics) {
        metric.visit(visitor);
    }
    verify(visitor).counter(c1.capture(), eq(1));
    assertEquals("c1 name", "c1", c1.getValue().name());
    assertEquals("c1 description", "int counter", c1.getValue().description());
    verify(visitor).counter(c2.capture(), eq(2L));
    assertEquals("c2 name", "c2", c2.getValue().name());
    assertEquals("c2 description", "long counter", c2.getValue().description());
    verify(visitor).gauge(g1.capture(), eq(5));
    assertEquals("g1 name", "g1", g1.getValue().name());
    assertEquals("g1 description", "int gauge", g1.getValue().description());
    verify(visitor).gauge(g2.capture(), eq(6L));
    assertEquals("g2 name", "g2", g2.getValue().name());
    assertEquals("g2 description", "long gauge", g2.getValue().description());
    verify(visitor).gauge(g3.capture(), eq(7f));
    assertEquals("g3 name", "g3", g3.getValue().name());
    assertEquals("g3 description", "float gauge", g3.getValue().description());
    verify(visitor).gauge(g4.capture(), eq(8d));
    assertEquals("g4 name", "g4", g4.getValue().name());
    assertEquals("g4 description", "double gauge", g4.getValue().description());
}
Also used : MetricsRegistry(org.apache.hadoop.metrics2.lib.MetricsRegistry) AbstractMetric(org.apache.hadoop.metrics2.AbstractMetric) MetricsVisitor(org.apache.hadoop.metrics2.MetricsVisitor) Test(org.junit.Test)

Example 93 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hadoop by apache.

the class TestMetricsAnnotations method testMethods.

@Test
public void testMethods() {
    MyMetrics2 metrics = new MyMetrics2();
    MetricsSource source = MetricsAnnotations.makeSource(metrics);
    MetricsRecordBuilder rb = getMetrics(source);
    verify(rb).addGauge(info("G1", "G1"), 1);
    verify(rb).addGauge(info("G2", "G2"), 2L);
    verify(rb).addGauge(info("G3", "G3"), 3.0f);
    verify(rb).addGauge(info("G4", "G4"), 4.0);
    verify(rb).addCounter(info("C1", "C1"), 1);
    verify(rb).addCounter(info("C2", "C2"), 2L);
    verify(rb).tag(info("T1", "T1"), "t1");
}
Also used : MetricsSource(org.apache.hadoop.metrics2.MetricsSource) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 94 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hadoop by apache.

the class TestMetricsAnnotations method testClasses.

@Test
public void testClasses() {
    MetricsRecordBuilder rb = getMetrics(MetricsAnnotations.makeSource(new MyMetrics3()));
    MetricsCollector collector = rb.parent();
    verify(collector).addRecord(info("MyMetrics3", "My metrics"));
    verify(rb).add(tag(MsInfo.Context, "foo"));
}
Also used : MetricsCollector(org.apache.hadoop.metrics2.MetricsCollector) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Example 95 with Metrics

use of org.apache.hadoop.metrics2.annotation.Metrics in project hadoop by apache.

the class TestUserGroupInformation method verifyLoginMetrics.

public static void verifyLoginMetrics(long success, int failure) throws IOException {
    // Ensure metrics related to kerberos login is updated.
    MetricsRecordBuilder rb = getMetrics("UgiMetrics");
    if (success > 0) {
        assertCounter("LoginSuccessNumOps", success, rb);
        assertGaugeGt("LoginSuccessAvgTime", 0, rb);
    }
    if (failure > 0) {
        assertCounter("LoginFailureNumPos", failure, rb);
        assertGaugeGt("LoginFailureAvgTime", 0, rb);
    }
}
Also used : MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Aggregations

Test (org.junit.Test)67 MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)30 MetricsRecord (org.apache.hadoop.metrics2.MetricsRecord)20 AbstractMetric (org.apache.hadoop.metrics2.AbstractMetric)19 MetricsSystem (org.apache.hadoop.metrics2.MetricsSystem)19 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)18 MetricsSource (org.apache.hadoop.metrics2.MetricsSource)16 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 HashSet (java.util.HashSet)8 Path (org.apache.hadoop.fs.Path)8 MetricsException (org.apache.hadoop.metrics2.MetricsException)8 MetricsCollectorImpl (org.apache.hadoop.metrics2.impl.MetricsCollectorImpl)7 DefaultMetricsSystem (org.apache.hadoop.metrics2.lib.DefaultMetricsSystem)7 Configuration (org.apache.hadoop.conf.Configuration)5 Map (java.util.Map)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 MetricsSink (org.apache.hadoop.metrics2.MetricsSink)4 MetricsSystemImpl (org.apache.hadoop.metrics2.impl.MetricsSystemImpl)4 GraphiteSink (org.apache.hadoop.metrics2.sink.GraphiteSink)4