Search in sources :

Example 51 with MetricsSystem

use of org.apache.hadoop.metrics2.MetricsSystem in project hadoop by apache.

the class TestRollingFileSystemSinkWithHdfs method testFailedWrite.

/**
   * Test that writing to HDFS fails when HDFS is unavailable.
   *
   * @throws IOException thrown when reading or writing log files
   */
@Test
public void testFailedWrite() throws IOException {
    final String path = "hdfs://" + cluster.getNameNode().getHostAndPort() + "/tmp";
    MetricsSystem ms = initMetricsSystem(path, false, false);
    new MyMetrics1().registerWith(ms);
    shutdownHdfs();
    MockSink.errored = false;
    // publish the metrics
    ms.publishMetricsNow();
    assertTrue("No exception was generated while writing metrics " + "even though HDFS was unavailable", MockSink.errored);
    try {
        ms.stop();
    } finally {
        ms.shutdown();
    }
}
Also used : MyMetrics1(org.apache.hadoop.metrics2.sink.RollingFileSystemSinkTestBase.MyMetrics1) MetricsSystem(org.apache.hadoop.metrics2.MetricsSystem) Test(org.junit.Test)

Example 52 with MetricsSystem

use of org.apache.hadoop.metrics2.MetricsSystem in project hadoop by apache.

the class TestRollingFileSystemSinkWithSecureHdfs method testWithSecureHDFS.

/**
   * Do a basic write test against an HDFS cluster with Kerberos enabled. We
   * assume that if a basic write succeeds, more complex operations will also
   * succeed.
   *
   * @throws Exception thrown if things break
   */
@Test
public void testWithSecureHDFS() throws Exception {
    final String path = "hdfs://" + cluster.getNameNode().getHostAndPort() + "/tmp/test";
    final MetricsSystem ms = initMetricsSystem(path, true, false, true);
    assertMetricsContents(sink.doAs(new PrivilegedExceptionAction<String>() {

        @Override
        public String run() throws Exception {
            return doWriteTest(ms, path, 1);
        }
    }));
}
Also used : MetricsSystem(org.apache.hadoop.metrics2.MetricsSystem) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Test(org.junit.Test)

Example 53 with MetricsSystem

use of org.apache.hadoop.metrics2.MetricsSystem in project hadoop by apache.

the class RollingFileSystemSinkTestBase method initMetricsSystem.

/**
   * Set up the metrics system, start it, and return it.
   * @param path the base path for the sink
   * @param ignoreErrors whether the sink should ignore errors
   * @param allowAppend whether the sink is allowed to append to existing files
   * @param useSecureParams whether to set the principal and keytab properties
   * @return the org.apache.hadoop.metrics2.MetricsSystem
   */
protected MetricsSystem initMetricsSystem(String path, boolean ignoreErrors, boolean allowAppend, boolean useSecureParams) {
    // If the prefix is not lower case, the metrics system won't be able to
    // read any of the properties.
    String prefix = methodName.getMethodName().toLowerCase();
    ConfigBuilder builder = new ConfigBuilder().add("*.period", 10000).add(prefix + ".sink.mysink0.class", MockSink.class.getName()).add(prefix + ".sink.mysink0.basepath", path).add(prefix + ".sink.mysink0.source", "testsrc").add(prefix + ".sink.mysink0.context", "test1").add(prefix + ".sink.mysink0.ignore-error", ignoreErrors).add(prefix + ".sink.mysink0.allow-append", allowAppend).add(prefix + ".sink.mysink0.roll-offset-interval-millis", 0).add(prefix + ".sink.mysink0.roll-interval", "1h");
    if (useSecureParams) {
        builder.add(prefix + ".sink.mysink0.keytab-key", SINK_KEYTAB_FILE_KEY).add(prefix + ".sink.mysink0.principal-key", SINK_PRINCIPAL_KEY);
    }
    builder.save(TestMetricsConfig.getTestFilename("hadoop-metrics2-" + prefix));
    MetricsSystemImpl ms = new MetricsSystemImpl(prefix);
    ms.start();
    return ms;
}
Also used : ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) MetricsSystemImpl(org.apache.hadoop.metrics2.impl.MetricsSystemImpl)

Example 54 with MetricsSystem

use of org.apache.hadoop.metrics2.MetricsSystem in project hadoop by apache.

the class TestRollingFileSystemSinkWithLocal method testWrite.

/**
   * Test writing logs to the local file system.
   * @throws Exception when things break
   */
@Test
public void testWrite() throws Exception {
    String path = methodDir.getAbsolutePath();
    MetricsSystem ms = initMetricsSystem(path, false, false);
    assertMetricsContents(doWriteTest(ms, path, 1));
}
Also used : MetricsSystem(org.apache.hadoop.metrics2.MetricsSystem) Test(org.junit.Test)

Example 55 with MetricsSystem

use of org.apache.hadoop.metrics2.MetricsSystem in project hadoop by apache.

the class TestRollingFileSystemSinkWithLocal method testSilentFailedWrite.

/**
   * Test that writing fails silently when the directory is not writable.
   */
@Test
public void testSilentFailedWrite() {
    String path = methodDir.getAbsolutePath();
    MetricsSystem ms = initMetricsSystem(path, true, false);
    new MyMetrics1().registerWith(ms);
    methodDir.setWritable(false);
    MockSink.errored = false;
    try {
        // publish the metrics
        ms.publishMetricsNow();
        assertFalse("An exception was generated while writing metrics " + "when the target directory was not writable, even though the " + "sink is set to ignore errors", MockSink.errored);
        ms.stop();
        ms.shutdown();
    } finally {
        // Make sure the dir is writable again so we can delete it at the end
        methodDir.setWritable(true);
    }
}
Also used : MetricsSystem(org.apache.hadoop.metrics2.MetricsSystem) Test(org.junit.Test)

Aggregations

MetricsSystem (org.apache.hadoop.metrics2.MetricsSystem)80 DefaultMetricsSystem (org.apache.hadoop.metrics2.lib.DefaultMetricsSystem)58 Test (org.junit.Test)23 MetricsSource (org.apache.hadoop.metrics2.MetricsSource)6 MetricsSystemImpl (org.apache.hadoop.metrics2.impl.MetricsSystemImpl)5 MyMetrics1 (org.apache.hadoop.metrics2.sink.RollingFileSystemSinkTestBase.MyMetrics1)5 JvmMetrics (org.apache.hadoop.hive.common.JvmMetrics)3 JvmMetrics (org.apache.hadoop.metrics2.source.JvmMetrics)3 After (org.junit.After)3 Path (org.apache.hadoop.fs.Path)2 LlapMetricsSystem (org.apache.hadoop.hive.llap.metrics.LlapMetricsSystem)2 MetricsCollectorImpl (org.apache.hadoop.metrics2.impl.MetricsCollectorImpl)2 MetricsRegistry (org.apache.hadoop.metrics2.lib.MetricsRegistry)2 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)2 QueueMetrics (org.apache.hadoop.yarn.server.resourcemanager.scheduler.QueueMetrics)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ConsoleReporter (com.codahale.metrics.ConsoleReporter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ChannelFuture (io.netty.channel.ChannelFuture)1 URI (java.net.URI)1