Search in sources :

Example 26 with MetricRegistryImpl

use of org.apache.flink.runtime.metrics.MetricRegistryImpl in project flink by apache.

the class MetricGroupRegistrationTest method testMetricInstantiation.

/**
 * Verifies that group methods instantiate the correct metric with the given name.
 */
@Test
public void testMetricInstantiation() throws Exception {
    MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.defaultMetricRegistryConfiguration(), Collections.singletonList(ReporterSetup.forReporter("test", new TestReporter1())));
    MetricGroup root = TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, "host", new ResourceID("id"));
    Counter counter = root.counter("counter");
    assertEquals(counter, TestReporter1.lastPassedMetric);
    assertEquals("counter", TestReporter1.lastPassedName);
    Gauge<Object> gauge = root.gauge("gauge", new Gauge<Object>() {

        @Override
        public Object getValue() {
            return null;
        }
    });
    Assert.assertEquals(gauge, TestReporter1.lastPassedMetric);
    assertEquals("gauge", TestReporter1.lastPassedName);
    Histogram histogram = root.histogram("histogram", new Histogram() {

        @Override
        public void update(long value) {
        }

        @Override
        public long getCount() {
            return 0;
        }

        @Override
        public HistogramStatistics getStatistics() {
            return null;
        }
    });
    Assert.assertEquals(histogram, TestReporter1.lastPassedMetric);
    assertEquals("histogram", TestReporter1.lastPassedName);
    registry.shutdown().get();
}
Also used : Histogram(org.apache.flink.metrics.Histogram) Counter(org.apache.flink.metrics.Counter) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) MetricGroup(org.apache.flink.metrics.MetricGroup) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) HistogramStatistics(org.apache.flink.metrics.HistogramStatistics) Test(org.junit.Test)

Example 27 with MetricRegistryImpl

use of org.apache.flink.runtime.metrics.MetricRegistryImpl in project flink by apache.

the class MetricGroupTest method testCreateQueryServiceMetricInfo.

@Test
public void testCreateQueryServiceMetricInfo() {
    JobID jid = new JobID();
    JobVertexID vid = new JobVertexID();
    ExecutionAttemptID eid = new ExecutionAttemptID();
    MetricRegistryImpl registry = new MetricRegistryImpl(defaultMetricRegistryConfiguration);
    TaskManagerMetricGroup tm = TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, "host", new ResourceID("id"));
    TaskMetricGroup task = tm.addJob(jid, "jobname").addTask(vid, eid, "taskName", 4, 5);
    GenericMetricGroup userGroup1 = new GenericMetricGroup(registry, task, "hello");
    GenericMetricGroup userGroup2 = new GenericMetricGroup(registry, userGroup1, "world");
    QueryScopeInfo.TaskQueryScopeInfo info1 = (QueryScopeInfo.TaskQueryScopeInfo) userGroup1.createQueryServiceMetricInfo(new DummyCharacterFilter());
    assertEquals("hello", info1.scope);
    assertEquals(jid.toString(), info1.jobID);
    assertEquals(vid.toString(), info1.vertexID);
    assertEquals(4, info1.subtaskIndex);
    QueryScopeInfo.TaskQueryScopeInfo info2 = (QueryScopeInfo.TaskQueryScopeInfo) userGroup2.createQueryServiceMetricInfo(new DummyCharacterFilter());
    assertEquals("hello.world", info2.scope);
    assertEquals(jid.toString(), info2.jobID);
    assertEquals(vid.toString(), info2.vertexID);
    assertEquals(4, info2.subtaskIndex);
}
Also used : ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) QueryScopeInfo(org.apache.flink.runtime.metrics.dump.QueryScopeInfo) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) DummyCharacterFilter(org.apache.flink.runtime.metrics.util.DummyCharacterFilter) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 28 with MetricRegistryImpl

use of org.apache.flink.runtime.metrics.MetricRegistryImpl in project flink by apache.

the class TaskManagerGroupTest method testGenerateScopeCustom.

@Test
public void testGenerateScopeCustom() throws Exception {
    Configuration cfg = new Configuration();
    cfg.setString(MetricOptions.SCOPE_NAMING_TM, "constant.<host>.foo.<host>");
    MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.fromConfiguration(cfg));
    TaskManagerMetricGroup group = TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, "host", new ResourceID("id"));
    assertArrayEquals(new String[] { "constant", "host", "foo", "host" }, group.getScopeComponents());
    assertEquals("constant.host.foo.host.name", group.getMetricIdentifier("name"));
    registry.shutdown().get();
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) Test(org.junit.Test)

Aggregations

MetricRegistryImpl (org.apache.flink.runtime.metrics.MetricRegistryImpl)28 Test (org.junit.Test)24 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)17 Configuration (org.apache.flink.configuration.Configuration)15 JobID (org.apache.flink.api.common.JobID)13 MetricGroup (org.apache.flink.metrics.MetricGroup)6 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)5 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)5 QueryScopeInfo (org.apache.flink.runtime.metrics.dump.QueryScopeInfo)4 DummyCharacterFilter (org.apache.flink.runtime.metrics.util.DummyCharacterFilter)4 CharacterFilter (org.apache.flink.metrics.CharacterFilter)2 MetricRegistryConfiguration (org.apache.flink.runtime.metrics.MetricRegistryConfiguration)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 InetAddress (java.net.InetAddress)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1