Search in sources :

Example 6 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class TestPatternFilter method includeShouldOverrideExclude.

/**
   * Include patterns should take precedence over exclude patterns
   */
@Test
public void includeShouldOverrideExclude() {
    SubsetConfiguration c = new ConfigBuilder().add("p.include", "foo").add("p.include.tags", "foo:f").add("p.exclude", "foo").add("p.exclude.tags", "foo:f").subset("p");
    shouldAccept(c, "foo");
    shouldAccept(c, Arrays.asList(tag("foo", "", "f")));
    shouldAccept(c, mockMetricsRecord("foo", Arrays.asList(tag("foo", "", "f"))));
}
Also used : ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 7 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class TestPatternFilter method shouldAcceptUnmatchedWhenBothAreConfigured.

/**
   * Filters should accepts unmatched item when both include and
   * exclude patterns are present.
   */
@Test
public void shouldAcceptUnmatchedWhenBothAreConfigured() {
    SubsetConfiguration c = new ConfigBuilder().add("p.include", "foo").add("p.include.tags", "foo:f").add("p.exclude", "bar").add("p.exclude.tags", "bar:b").subset("p");
    shouldAccept(c, "foo");
    shouldAccept(c, Arrays.asList(tag("foo", "", "f")));
    shouldAccept(c, mockMetricsRecord("foo", Arrays.asList(tag("foo", "", "f"))));
    shouldReject(c, "bar");
    shouldReject(c, Arrays.asList(tag("bar", "", "b")));
    shouldReject(c, mockMetricsRecord("bar", Arrays.asList(tag("foo", "", "f"))));
    shouldReject(c, mockMetricsRecord("foo", Arrays.asList(tag("bar", "", "b"))));
    shouldAccept(c, "foobar");
    shouldAccept(c, Arrays.asList(tag("foobar", "", "")));
    shouldAccept(c, mockMetricsRecord("foobar", Arrays.asList(tag("foobar", "", ""))));
}
Also used : ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 8 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class TestPatternFilter method includeOnlyShouldOnlyIncludeMatched.

/**
   * Filters should handle white-listing correctly
   */
@Test
public void includeOnlyShouldOnlyIncludeMatched() {
    SubsetConfiguration wl = new ConfigBuilder().add("p.include", "foo").add("p.include.tags", "foo:f").subset("p");
    shouldAccept(wl, "foo");
    shouldAccept(wl, Arrays.asList(tag("bar", "", ""), tag("foo", "", "f")), new boolean[] { false, true });
    shouldAccept(wl, mockMetricsRecord("foo", Arrays.asList(tag("bar", "", ""), tag("foo", "", "f"))));
    shouldReject(wl, "bar");
    shouldReject(wl, Arrays.asList(tag("bar", "", "")));
    shouldReject(wl, Arrays.asList(tag("foo", "", "boo")));
    shouldReject(wl, mockMetricsRecord("bar", Arrays.asList(tag("foo", "", "f"))));
    shouldReject(wl, mockMetricsRecord("foo", Arrays.asList(tag("bar", "", ""))));
}
Also used : ConfigBuilder(org.apache.hadoop.metrics2.impl.ConfigBuilder) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 9 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class TestMetricsCollectorImpl method recordBuilderShouldNoOpIfFiltered.

@Test
public void recordBuilderShouldNoOpIfFiltered() {
    SubsetConfiguration fc = new ConfigBuilder().add("p.exclude", "foo").subset("p");
    MetricsCollectorImpl mb = new MetricsCollectorImpl();
    mb.setRecordFilter(newGlobFilter(fc));
    MetricsRecordBuilderImpl rb = mb.addRecord("foo");
    rb.tag(info("foo", ""), "value").addGauge(info("g0", ""), 1);
    assertEquals("no tags", 0, rb.tags().size());
    assertEquals("no metrics", 0, rb.metrics().size());
    assertNull("null record", rb.getRecord());
    assertEquals("no records", 0, mb.getRecords().size());
}
Also used : SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Example 10 with SubsetConfiguration

use of org.apache.commons.configuration2.SubsetConfiguration in project hadoop by apache.

the class TestMetricsCollectorImpl method testPerMetricFiltering.

@Test
public void testPerMetricFiltering() {
    SubsetConfiguration fc = new ConfigBuilder().add("p.exclude", "foo").subset("p");
    MetricsCollectorImpl mb = new MetricsCollectorImpl();
    mb.setMetricFilter(newGlobFilter(fc));
    MetricsRecordBuilderImpl rb = mb.addRecord("foo");
    rb.tag(info("foo", ""), "").addCounter(info("c0", ""), 0).addGauge(info("foo", ""), 1);
    assertEquals("1 tag", 1, rb.tags().size());
    assertEquals("1 metric", 1, rb.metrics().size());
    assertEquals("expect foo tag", "foo", rb.tags().get(0).name());
    assertEquals("expect c0", "c0", rb.metrics().get(0).name());
}
Also used : SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Test(org.junit.Test)

Aggregations

SubsetConfiguration (org.apache.commons.configuration2.SubsetConfiguration)14 Test (org.junit.Test)14 ConfigBuilder (org.apache.hadoop.metrics2.impl.ConfigBuilder)11 DatagramSocket (java.net.DatagramSocket)4 MulticastSocket (java.net.MulticastSocket)4 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)1 Path (org.apache.hadoop.fs.Path)1 AbstractMetric (org.apache.hadoop.metrics2.AbstractMetric)1 MetricsException (org.apache.hadoop.metrics2.MetricsException)1 MetricsRecord (org.apache.hadoop.metrics2.MetricsRecord)1 MetricsTag (org.apache.hadoop.metrics2.MetricsTag)1 MetricsVisitor (org.apache.hadoop.metrics2.MetricsVisitor)1 KafkaSink (org.apache.hadoop.metrics2.sink.KafkaSink)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)1