Search in sources :

Example 16 with MetricRegistryImpl

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

the class MetricGroupTest method testLogicalScopeShouldIgnoreValueGroupName.

/**
 * Verifies that calling {@link AbstractMetricGroup#getLogicalScope(CharacterFilter, char, int)}
 * on {@link GenericValueMetricGroup} should ignore value as well.
 */
@Test
public void testLogicalScopeShouldIgnoreValueGroupName() throws Exception {
    Configuration config = new Configuration();
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.class.getName());
    MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.fromConfiguration(config));
    try {
        GenericMetricGroup root = new GenericMetricGroup(registry, new DummyAbstractMetricGroup(registry), "root");
        String key = "key";
        String value = "value";
        MetricGroup group = root.addGroup(key, value);
        String logicalScope = ((AbstractMetricGroup) group).getLogicalScope(new DummyCharacterFilter(), registry.getDelimiter(), 0);
        assertThat("Key is missing from logical scope.", logicalScope, containsString(key));
        assertThat("Value is present in logical scope.", logicalScope, not(containsString(value)));
    } finally {
        registry.shutdown().get();
    }
}
Also used : MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) TestReporter(org.apache.flink.runtime.metrics.util.TestReporter) MetricGroup(org.apache.flink.metrics.MetricGroup) DummyCharacterFilter(org.apache.flink.runtime.metrics.util.DummyCharacterFilter) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 17 with MetricRegistryImpl

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

the class PrometheusReporterTaskScopeTest method setupReporter.

@BeforeEach
void setupReporter() {
    registry = new MetricRegistryImpl(MetricRegistryTestUtils.defaultMetricRegistryConfiguration(), Collections.singletonList(createReporterSetup("test1", "9400-9500")));
    reporter = (PrometheusReporter) registry.getReporters().get(0);
    TaskManagerMetricGroup tmMetricGroup = TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, TASK_MANAGER_HOST, new ResourceID(TASK_MANAGER_ID));
    taskMetricGroup1 = tmMetricGroup.addJob(jobId, JOB_NAME).addTask(taskId1, taskAttemptId1, TASK_NAME, SUBTASK_INDEX_1, ATTEMPT_NUMBER);
    taskMetricGroup2 = tmMetricGroup.addJob(jobId, JOB_NAME).addTask(taskId2, taskAttemptId2, TASK_NAME, SUBTASK_INDEX_2, ATTEMPT_NUMBER);
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with MetricRegistryImpl

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

the class PrometheusReporterTest method setupReporter.

@BeforeEach
void setupReporter() {
    registry = new MetricRegistryImpl(MetricRegistryTestUtils.defaultMetricRegistryConfiguration(), Collections.singletonList(createReporterSetup("test1", portRangeProvider.next())));
    metricGroup = new FrontMetricGroup<>(createReporterScopedSettings(), TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, HOST_NAME, new ResourceID(TASK_MANAGER)));
    reporter = (PrometheusReporter) registry.getReporters().get(0);
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with MetricRegistryImpl

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

the class AbstractMetricGroupTest method testGetAllVariables.

/**
 * Verifies that no {@link NullPointerException} is thrown when {@link
 * AbstractMetricGroup#getAllVariables()} is called and the parent is null.
 */
@Test
public void testGetAllVariables() throws Exception {
    MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.defaultMetricRegistryConfiguration());
    AbstractMetricGroup group = new AbstractMetricGroup<AbstractMetricGroup<?>>(registry, new String[0], null) {

        @Override
        protected QueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter) {
            return null;
        }

        @Override
        protected String getGroupName(CharacterFilter filter) {
            return "";
        }
    };
    assertTrue(group.getAllVariables().isEmpty());
    registry.shutdown().get();
}
Also used : CharacterFilter(org.apache.flink.metrics.CharacterFilter) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) Test(org.junit.Test)

Example 20 with MetricRegistryImpl

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

the class AbstractMetricGroupTest method testScopeCachingForMultipleReporters.

@Test
public void testScopeCachingForMultipleReporters() throws Exception {
    String counterName = "1";
    Configuration config = new Configuration();
    config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D");
    MetricConfig metricConfig1 = new MetricConfig();
    metricConfig1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
    MetricConfig metricConfig2 = new MetricConfig();
    metricConfig2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, CollectingMetricsReporter.class.getName());
    config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");
    CollectingMetricsReporter reporter1 = new CollectingMetricsReporter(FILTER_B);
    CollectingMetricsReporter reporter2 = new CollectingMetricsReporter(FILTER_C);
    MetricRegistryImpl testRegistry = new MetricRegistryImpl(MetricRegistryTestUtils.fromConfiguration(config), Arrays.asList(ReporterSetup.forReporter("test1", metricConfig1, reporter1), ReporterSetup.forReporter("test2", metricConfig2, reporter2)));
    try {
        MetricGroup tmGroup = TaskManagerMetricGroup.createTaskManagerMetricGroup(testRegistry, "host", new ResourceID("id"));
        tmGroup.counter(counterName);
        assertEquals("Reporters were not properly instantiated", 2, testRegistry.getReporters().size());
        {
            // verify reporter1
            MetricGroupAndName nameAndGroup = reporter1.getAddedMetrics().stream().filter(nag -> nag.name.equals(counterName)).findAny().get();
            String metricName = nameAndGroup.name;
            MetricGroup group = nameAndGroup.group;
            // the first call determines which filter is applied to all future
            // calls; in
            // this case
            // no filter is used at all
            assertEquals("A-B-C-D-1", group.getMetricIdentifier(metricName));
            // from now on the scope string is cached and should not be reliant
            // on the
            // given filter
            assertEquals("A-B-C-D-1", group.getMetricIdentifier(metricName, FILTER_C));
            assertEquals("A-B-C-D-1", group.getMetricIdentifier(metricName, reporter1));
            // the metric name however is still affected by the filter as it is
            // not
            // cached
            assertEquals("A-B-C-D-4", group.getMetricIdentifier(metricName, input -> input.replace("B", "X").replace(counterName, "4")));
        }
        {
            // verify reporter2
            MetricGroupAndName nameAndGroup = reporter2.getAddedMetrics().stream().filter(nag -> nag.name.equals(counterName)).findAny().get();
            String metricName = nameAndGroup.name;
            MetricGroup group = nameAndGroup.group;
            // the first call determines which filter is applied to all future calls
            assertEquals("A!B!X!D!1", group.getMetricIdentifier(metricName, reporter2));
            // from now on the scope string is cached and should not be reliant on the given
            // filter
            assertEquals("A!B!X!D!1", group.getMetricIdentifier(metricName));
            assertEquals("A!B!X!D!1", group.getMetricIdentifier(metricName, FILTER_C));
            // the metric name however is still affected by the filter as it is not cached
            assertEquals("A!B!X!D!3", group.getMetricIdentifier(metricName, input -> input.replace("A", "X").replace(counterName, "3")));
        }
    } finally {
        testRegistry.shutdown().get();
    }
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) Arrays(java.util.Arrays) MetricConfig(org.apache.flink.metrics.MetricConfig) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) CharacterFilter(org.apache.flink.metrics.CharacterFilter) AtomicReference(java.util.concurrent.atomic.AtomicReference) ReporterSetup(org.apache.flink.runtime.metrics.ReporterSetup) BlockerSync(org.apache.flink.core.testutils.BlockerSync) TestingMetricRegistry(org.apache.flink.runtime.metrics.util.TestingMetricRegistry) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) ScopeFormat(org.apache.flink.runtime.metrics.scope.ScopeFormat) Map(java.util.Map) ConfigConstants(org.apache.flink.configuration.ConfigConstants) TestLogger(org.apache.flink.util.TestLogger) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) QueryScopeInfo(org.apache.flink.runtime.metrics.dump.QueryScopeInfo) IsNot.not(org.hamcrest.core.IsNot.not) CollectingMetricsReporter(org.apache.flink.runtime.metrics.CollectingMetricsReporter) MetricRegistryTestUtils(org.apache.flink.runtime.metrics.MetricRegistryTestUtils) MetricGroupAndName(org.apache.flink.runtime.metrics.CollectingMetricsReporter.MetricGroupAndName) Configuration(org.apache.flink.configuration.Configuration) NoOpMetricRegistry(org.apache.flink.runtime.metrics.NoOpMetricRegistry) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MetricOptions(org.apache.flink.configuration.MetricOptions) IsMapContaining(org.hamcrest.collection.IsMapContaining) MetricGroup(org.apache.flink.metrics.MetricGroup) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Configuration(org.apache.flink.configuration.Configuration) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) MetricGroupAndName(org.apache.flink.runtime.metrics.CollectingMetricsReporter.MetricGroupAndName) MetricGroup(org.apache.flink.metrics.MetricGroup) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) CollectingMetricsReporter(org.apache.flink.runtime.metrics.CollectingMetricsReporter) 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